PyHessian
PyHessian copied to clipboard
RuntimeError: element 0 of variables does not require grad and does not have a grad_fn
In hessian.py When I tried to run the following code, Hv = hessian_vector_product(gradsH, params, v)
The error comes out. Is there any idea how to resolve this issue?
Instead of loss.backward(create_graph=True)
, which is called before hessian_vector_product
use torch.autograd.grad(...)
. I am using Pytorch 1.10.0 and it works. (Also dont forget to filter out unused parameters-grads)
I can confirm that the workaround suggested by @petrgeiger-incieve seems to be working on my end. I am using PyTorch
1.12
btw.