-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add rrule_from_frule macro #2
base: main
Are you sure you want to change the base?
Conversation
Nice. If we resolved JuliaDiff/ChainRulesTestUtils.jl#221 It might be nice to add a short explination of why this works into the docstring. My notes from slack are
|
Thanks @oxinabox! I now added a short docstring. I also have left two more TODO's in the code:
|
Related to this, I think Zygote (and probably Diffractor) will AFAIK also generate code for the pullback of that discarded primal i think. |
This draft PR implements a proposal for a new rrule definition helper macro
@rrule_from_frule
. It generates an rrule from an already defined frule by calling-back into (reverse-mode) AD.This is also inspired by JAX's approach to decomposing reverse-mode into (forward-mode) linearization + transposition (where transposition only needs rules for linear primitives).
This minimum working example illustrates the idea from a ChainRules.jl perspective:
This PR aims to provide this approach as a macro that can be used like
@rrule_from_frule f(x::AbstractArray{<:Real})
to minimize boiler-plate code.