nn.MSELoss expects the output and target to have the same shape (or will broadcast it with a warning).
However, you are currently breaking the computation graph by transforming some outputs to LongTensors, which won’t get gradients.
If you remove these .long() calls, your code will work.
What’s your use case to use LongTensors and how should the gradients be calculated in this case?