-
-
Notifications
You must be signed in to change notification settings - Fork 398
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
[docs] update autodiff tutorial #3836
Conversation
I had a question about the use of DI. For many backends, performance is greatly improved by the preparation mechanism, which allows you to record a tape / preallocate a cache / etc. But to apply it, you need an example input that has the same type and size as the ones you'll encounter during optimization. Is there any way we can use this mechanism in JuMP? |
You could just use the first call to build the tape, and then error if there are calls from different inputs. JuMP doesn't provide anything special. You can do everything in user-land. |
# [DifferentiationInterface.jl](https://github.com/gdalle/DifferentiationInterface.jl) | ||
# is a package that provides an abstraction layer across multiple underlying | ||
# autodiff libaries. | ||
|
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.
Perhaps add a disclaimer:
While DI makes it easier to experiment with different autodiff tools, this comes at a cost. In particular, DI may produce slower derivatives than using an AD tool directly, and sometimes fail to work at all. For example, in this code passing AutoEnzyme to DI fails to differentiate the code which is supported when directly calling Enzyme, like above.
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.
By the way do you have any idea why it fails here? As usual it's a segfault so not particularly user friendly
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.
No idea, I haven’t even tried to run it or seen what the error message, just took your word that it failed xD.
open an issue with the mwe and error and can take a look
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.
and sometimes fail to work at all
I don't want to mention something in our documentation if this is the case.
What is the failure mode? Will we gracefully report errors? Segfaults are not good.
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.
Oh agreed in that segfaults are bad, in that case @gdalle just drop DI docs then?
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 realized my changes mean we never actually mention Enzyme in the context of DI, so perhaps that's okay.
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.
The fact that it is a segfault is not due to DI per se, it's Enzyme not catching the error gracefully. Sure, DI might be using Enzyme wrong in this particular case (perhaps because of a function returning two closures), but I too would very much prefer a clean error message from Enzyme to a segfault. Will try to reproduce tomorrow.
Again haven't seen the error message so not clear what's up, but I'm unaware of any segfaults caused by Enzyme atm. Most the time people saw segfaults in the past were actually bugs in the Julia compiler itself (e.g. JuliaLang/julia#55306 ).
That said unfortunately even if you're not the underlying cause of an error, the top level package you use is going to be the one people blame for issues (especially if code works otherwise without it). Analogously, there's a ton of code in Enzyme working around bugs in the Julia and LLVM compiler errors =/. Perhaps something similar would be good in DI?
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.
It is not DI's job to work around LLVM errors, it's Enzyme's or Julia's. DI is a fancy argument-passer
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.
And here's the MWE: EnzymeAD/Enzyme.jl#1942
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.
For the record, pure Enzyme also fails on this one when one uses splat(f)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3836 +/- ##
=======================================
Coverage 97.90% 97.90%
=======================================
Files 44 44
Lines 6019 6019
=======================================
Hits 5893 5893
Misses 126 126 ☔ View full report in Codecov by Sentry. |
Looks like the warning got dropped before merging
Two modifications to the tutorial on autodiff of user-defined operators:
autodiff_deferred
anymore). I didn't necessarily go for the most efficient solutions, you may want to ask @wsmoses for that, I just performed the minimal changes to gain compatibility with the breaking release.AutoEnzyme()
but it's a start.Related issues: