just to give a consistent link for those lines, you can press ‘y’ in github and get the link.
here is the updated link:

  
      github.com
  
  
    pytorch/pytorch/blob/892940b45a20d94450661a3108f4723a0f4815b1/test/test_nn.py#L1914-L1923 111

def test_pack_padded_sequence(self):
    def pad(tensor, length):
        return torch.cat([tensor, tensor.new(length - tensor.size(0), *tensor.size()[1:]).zero_()])
    lengths = [10, 8, 4, 2, 2, 2, 1]
    max_length = lengths[0]
    batch_sizes = [sum(map(bool, filter(lambda x: x >= i, lengths))) for i in range(1, max_length + 1)]
    offset = 0
    padded = torch.cat([pad(i * 100 + torch.arange(1, 5 * l + 1).view(l, 1, 5), max_length)
                        for i, l in enumerate(lengths, 1)], 1)
    padded = Variable(padded, requires_grad=True)