Solved by ptrblck in post #2 
              
              
                In the second use case you are ignoring the warning: 
UserWarning: Using a target size (torch.Size([4])) that is different to the input size (torch.Size([4, 1])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.

which explains that broadcasting …