Closed jbrea closed 3 months ago
Enzyme is trying to automatically determine the activity of the return argument. Since you are returning a Float64 the return is set to Active, and an automatic 1.0
is used as the differential return.
You can set the activity of the return to Const
instead.
Thanks. Yes,
autodiff(Reverse, f1!, Const, Duplicated([0.], [1.]), Duplicated(x, dx1))
gives the expected result. Wouldn't it be better if
autodiff(Reverse, f1!, Duplicated([0.], [1.]), Duplicated(x, dx1))
wouldn't exist, such that the user always has to specify, if the return is active or not?
This is a design decision. The automatic activity deduction makes it easier for folks to use autodiff (e.g. just using on sin), which already gets complaints about it being more difficult than other utilities so I'm hesitant to do so.
cc @gdalle for design thoughts
Yeah it's a tough one. Ultimately it's about understanding which adjoints get propagated where. I have wanted to add something like https://discourse.julialang.org/t/do-i-understand-enzyme-properly/97760 to the docs for a while, maybe it would help?
Yeah I think more docs are definitely needed/helpful
In any case closing as nothing inside enzyme was erring
dx2
is the correct result. Is there a way to warn the user. if the function doesn't returnnothing
?This is with Enzyme v0.11.19 and julia 1.10.2.