-
Notifications
You must be signed in to change notification settings - Fork 65
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
Enzyme.gradient
allocates on SVector
#1968
Comments
sure, PR welcome! |
Sure! I'll try to handle this case correctly in DI first, because it still errors at the moment. Once I have a handle on the single-argument solution, I'll try to tamper with the generated function to do the same for multiple arguments. |
bump @gdalle |
gentle ping @gdalle |
Essentially this comes down to adding the option for Lines 1714 to 1720 in 42ecd12
The variable interpolated as Lines 1686 to 1692 in 42ecd12
|
Hi!
As you know, @ExpandingMan and I are looking to optimize performance for StaticArrays. Forward mode works splendidly, but reverse mode still makes one allocation during the
gradient
call:I found it surprising because Enzyme guesses the right activity for
SVector
:The allocation happens on the following line:
Enzyme.jl/src/Enzyme.jl
Line 1708 in 42ecd12
From what I understand, the generated function
Enzyme.gradient
puts aRef
there to treat every argument as(Mixed)Duplicated
. This means that all gradient results are stored in the passed arguments:Enzyme.jl/src/Enzyme.jl
Line 1741 in 42ecd12
Otherwise, you would have to recover some gradients from the result and others from the arguments, which is understandably tricky.
Do you think there is an easy fix in Enzyme? Otherwise, since DI only has one differentiated argument, I assume it will be rather straightfoward to call
Enzyme.autodiff
directly insideDI.gradient
and recover allocation-free behavior.Related:
The text was updated successfully, but these errors were encountered: