-
Notifications
You must be signed in to change notification settings - Fork 18
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
Use Zygote.jacobian
etc.
#128
Conversation
1be197f
to
202c86f
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #128 +/- ##
==========================================
+ Coverage 82.32% 82.54% +0.22%
==========================================
Files 8 8
Lines 413 424 +11
==========================================
+ Hits 340 350 +10
- Misses 73 74 +1 ☔ View full report in Codecov by Sentry. |
IIRC, one fundamental difference is that Zygote.jacobian preallocates the Jacobian matrix. This is not good for higher order derivatives with reverse mode because it is mutating. |
My feeling is that this is a problem that should be addressed in Zygote (possibly they should use the default implementation in AbstractDifferentiation based on |
I agree with this take, and I push it further here: #129 |
|
My view is the same there as well: If |
Bump 🙂 For other AD backends such as ForwardDiff, ReverseDiff, and Tracker actually we already use jacobian, hessian, etc. in downstream packages when applicable. |
return res.val, res.grad | ||
end | ||
|
||
AD.jacobian(::AD.ZygoteBackend, f, args...) = Zygote.jacobian(f, args...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we provide a way to opt out of this, perhaps a type parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't provide any opt-outs for any other backend, so my feeling is that we should not add one here. I think it would also unnecessarily complicate the backend (and if there's a problem with Zygote.jacobian
I still think it should be fixed in Zygote). If a user really wants to use a different implementation of AD.jacobian
I think it should be reasonably easy to define a custom MyZygoteBackend
that forwards everything but AD.jacobian
to a ZygoteBackend
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be the minority vote here in which case I will take the extra inconvenience of defining my own backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with David on this one
Zygote already has an interface for pullbacks, jacobians, etc., hence IMO we should use it in
AD.jacobian
etc. as I guess users (arguably correctly) expect thatAD.jacobian
performs the same computations and is as efficient asZygote.jacobian
. That is, I think AbstractDifferentiation should not treat Zygote as "just" an example of ChainRules AD backend but rather as a separate entity as - I think - we should not redefine jacobian etc. for Zygote based on the ChainRules pullback withZygote.ZygoteRuleConfig
.Fixes #54.