This is necessitated by the open Issue: pytorch/pytorch#1591
First, the usual pack_padded_sequence
and pad_packed_sequence
for handling variable length sequences;
seq_len, bsz, n_dims = feats.size()
packed_input = pack_padded_sequence(feats, lengths, batch_first=False)
packed_output, self.hidden = self.lstm(packed_input, self.hidden)
# lstm_out --> seqlen X bsz X hidden_dim
lstm_out, output_lengths = pad_packed_sequence(packed_output, batch_first = False)