If your batch looks like this:
a b c d
e f 0 0
g 0 0 0

then passing it to pack_padded_sequence along with the lengths [4, 2, 1] will give you a PackedSequence object containing a e g b f c d and batch sizes [3, 2, 1, 1]. This is the format that cuDNN expects. What you’re probably looking for is (something like) the code in the AutogradRNN class (https://github.com/pytorch/pytorch/tree/master/torch/nn/_functions/rnn.py 215), which implements an LSTM that takes a PackedSequence but uses LSTMCell rather than calling cuDNN.