Slightly off-topic: For everything except machine translation, that is, for classifiers, autoencoder, sequence tagger, I always use custom batch sampler that organizes the dataset into batches with sequences of equal length. This avoids the hassle with PackedSequence as well as padding in general.
Here’s the code. 5 And that’s what the usage looks like:
from pytorch.utils.data.text.dataset import BucketBatchSampler, BucketDataset

bucket_batch_sampler = BucketBatchSampler(X_train, batch_size)
bucket_dataset = BucketDataset(X_train, None) # None because example is for an autoencoder (otherwise, e.g., y_train for classifier)

X_train_iter = DataLoader(bucket_dataset, batch_sampler=bucket_batch_sampler, num_workers=4)

Maybe useful for you.