The error, at least from



 mMagmer:

import torch
import torch.nn as nn

total = 256 * 56 * 4 
x = torch.arange(0, total).view(256,56 , 4).float()
x.requires_grad = True
o= nn.utils.rnn.pack_padded_sequence(x, torch.tensor(256*[57]), batch_first=True)
o[0].mean().backward()



is pretty clear. pack_padded_sequence takes two args: input , lengths . first is BxTxH (because you are doing batch_first=True), the second is [length]*B, i.e., a B dim vector. If you are asking it to use batchsize 57 when the real batchsize is 56.