To my understanding input_grad = torch.autograd.grad(L, input) calculates the grads wrt input, and d_loss.backward(), optimizer_d.step() are updating weights with their grads. But there is a counter counting how many times you have derived from the network, and it’s not allowed in Pytorch?
In my case, if I don’t want to update the trained network and just want to get the grads wrt input, I can used torch.autograd.grad without problem above?