Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: element 0 of variables does not require grad and does not have a grad_fn #12

Open
taeheej opened this issue Dec 14, 2021 · 2 comments

Comments

@taeheej
Copy link

taeheej commented Dec 14, 2021

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?

@petrgeiger-incieve
Copy link

petrgeiger-incieve commented May 31, 2022

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)

@alvaro-budria
Copy link

I can confirm that the workaround suggested by @petrgeiger-incieve seems to be working on my end. I am using PyTorch 1.12 btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants