For an text autoencoder network I ended up writing my own data loader that not only sorts but also buckets sequences according to their length – contrast to the BucketIterator of torchtext which only buckets sequences of similar lengths.
This has a couple of advantages:

No need for padding and the potential loss efficiency
No need for PackedSequence

In the decoder I can generate the words in loop for the whole batch since they have all the same length. Existing examples for Seq2Seq models 3 assume batch sizes of 1. That’s way too slow 


For this autoencoder use case, bucketing sequences is the most pain-free solution. It’s a just one-time step during data preparation. While some batches might not be full – e.g., when the batch size is 64 but there are exactly 100 sequences of length 30, resulting in 2 batches of sizes 64 and 36 – if the dataset is large enough, >99% of batches are full. So no performance loss here.