Solved by tom in post #2 
              
              
                I think you are looking for torch.nn.utils.rnn.pad_sequence. 
If you want to do this manually: 

One greatly underappreciated (to my mind) feature of PyTorch is that you can allocate a tensor of zeros (of the right type) and then copy to slices without breaking the autograd link. This is what pad_se…