Hi,

You can use autograd.grad() to get the value of the gradient as a list and not modify the .grad fields of the parameters.
You will need to update the .grad fields before calling the optimizer.step() function I’m afraid.

Also I am fairly confused by this line: param.grad = nn.Parameter(torch.from_numpy(newGrad.detach().numpy()).float()) why do you wrap the grad in a Parameter? And why do you send it to numpy?