I am seeing that the problem starts at
`_, predicted = torch.max(outputs.data, 1) `

I read that torch.max or torch.argmax are non differentiable functions. Until this line, outputs.grad_fn has backward and requires_grad is True, but predicted is  an object torch.return_types.max, so it doesn’t have grad_fn and it can no more propagate gradients backward.