-
Notifications
You must be signed in to change notification settings - Fork 57
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
Incorrect gradients when using views #979
Comments
Yeah this is a known sharp edge. The primal and shadow must be structurally equivalent -- which in this case means having the same offset. We should probably issue a warning on construction with views so folks are more aware. |
Indeed, a warning (or even an error, if at all feasible) would be great, this is not at all clear from the documentation. For context, what I was trying to do here is integrate a Hamiltonian system and use autodifferentiation to build the derivative (i.e. the forces) for use with and with autodiff for the right-hand side. In an attempt to avoid superfluous allocations, I used the views in the manner shown in the MWE. Then, the offset problem occurs quite naturally due to the Hamiltonian structure. Thus, I'd argue that this is not a super-obscure use case. |
For reference, a better solution to my problem seems to be to use |
The following code shows an example of incorrect gradients when using views (see output and comments for details). It would be great if you could have a look; thanks!
EDIT: This is
Enzyme#main
onEDIT#2: De-cluttered MWE.
MWE
Output
The two 2d arrays printed on top should be the same; but as can be seen in the array displayed at the end, the gradient is stored to indices
7:12
instead of the correct1:6
The text was updated successfully, but these errors were encountered: