You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
From what I understand, the generated function Enzyme.gradient puts a Ref there to treat every argument as (Mixed)Duplicated. This means that all gradient results are stored in the passed arguments:
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 inside DI.gradient and recover allocation-free behavior.
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.
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: