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

shape of gradient does not match the parameter shape in vector field while using adjoint method #206

Open
ljxw88 opened this issue Nov 15, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@ljxw88
Copy link

ljxw88 commented Nov 15, 2023

In torchdyn -> numerics -> sensitivity.py

function _gather_odefunc_adjoint(), line 71:

dμ = torch.cat([el.flatten() if el is not None else torch.zeros(1) for el in dμ], dim=-1)

should be fixed by

param_shapes = [p.shape for p in vf.parameters()]
dμ = torch.cat([el.flatten() if el is not None else torch.zeros(param_shapes[i]).to(t.device).flatten() for i, el in enumerate(dμ)], dim=-1)

otherwise, the shape of gradient (torch.zeros(1)) does not match the parameter shape in vector field.

@ljxw88 ljxw88 added the bug Something isn't working label Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant