Which line of code is throwing this error?
Could you print the shapes of all tensors before calling this particular op?
Also, loss = loss(output, target) would mask the “loss function” called loss with its result, so I would recommend to use other names, e.g. loss = criterion(output, target).