Print the shapes of tensors ‘output’ and ‘prediction’ right before that line, and then keep inserting print statements in the preceding code until you see where one of them gets the incorrect shape.
print(output.size(), prediction.size())