    def forward(self, x, lengths):
        """
        Args:
            x (torch.Tensor): (B, F, T)
        """

        for conv in self.convolutions:
            x = F.dropout(F.tanh(conv(x)), 0.5, self.training)

        x = x.transpose(1, 2)  # (B, T, D)

        # x may not be sorted by length. Sort->process->unsort
        max_len = x.size(1)
        assert max_len == torch.max(lengths).item()

        lengths, perm_idx = lengths.sort(0, descending=True)
        x = x[perm_idx]
        x = nn.utils.rnn.pack_padded_sequence(x, lengths, batch_first=True)

        self.lstm.flatten_parameters()
        outputs, _ = self.lstm(x)
        outputs, _ = nn.utils.rnn.pad_packed_sequence(outputs, batch_first=True)

        _, unperm_idx = perm_idx.sort(0)
        outputs = outputs[unperm_idx]  # (B, T, D)
        lengths = lengths[unperm_idx]  # (B, T, D)

        outputs = self.pool(outputs, lengths)  # (B, D)

        mu = self.mu_proj(outputs)
        logvar = self.logvar_proj(outputs)
        z = distr.Normal(mu, logvar).rsample()
        return z, mu, logvar
Args:
x (torch.Tensor): (B, F, T)
examples/textless_nlp/gslm/unit2speech/tacotron2/model.py