Do I need to zero_grad when I use torch.autograd.grad()?

Do I need to use optimiser.zero_grad(), before using orch.autograd.grad? or it is just used when we use backward() function?

Just when you use the .backward() function. The goal of zero_grad is to reset the buffers used by .backward().

1 Like