Solved by ptrblck in post #2 
              
              
                No, this would only be needed, if you really want to calculate gradients in the input (e.g. for adversarial attacks). 

This is also not needed and I don’t know right now a valid use case where the targets need gradients. 
Could you explain how this return value is treated? 
return torch.mean(torch…