Sorry, I mixed argmax with max. @JohnCwok is right,  the index returned by argmax does not have gradients. In this case, if ur output is onehot, u don’t have to use the argmax, just feed it into the MSELoss.