Here is the code example where I tried to encode a sequence using nn.LSTM:
import torch
from torch import nn

src = torch.tensor([[1, 2, 3, 0, 0], [2, 3, 4, 5, 1], [1, 3, 6, 4, 0]])
src_len = torch.tensor([3, 5, 4])

embed = nn.Embedding(7, 4, 0)
lstm = nn.LSTM(4, 4)

src_embedded = embed(src)

# without PackedSequence
output, hidden = lstm(src_embedded)

# with PackedSequence
src_embedded_packed = nn.utils.rnn.pack_padded_sequence(
    src_embedded, src_len, True, False)
output_packed, hidden = lstm(src_embedded_packed)
output_unpacked, unpacked_len = nn.utils.rnn.pad_packed_sequence(
    output_packed, True)

assert output.equal(output_unpacked)

I got AssertionError when trying to compare the output computed with PackedSequence or without. Is this normal behavior? Thanks!