-
Notifications
You must be signed in to change notification settings - Fork 15
Integrate DifferentiationInterface.jl for gradient computation #397
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
Conversation
|
JuliaBUGS.jl documentation for PR #397 is available at: |
Pull Request Test Coverage Report for Build 19888070954Details
💛 - Coveralls |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #397 +/- ##
==========================================
- Coverage 83.86% 83.48% -0.39%
==========================================
Files 31 31
Lines 3936 3978 +42
==========================================
+ Hits 3301 3321 +20
- Misses 635 657 +22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
511c6a6 to
f0135a8
Compare
|
One high-level suggestion is to review DynamicPPL.LogDensityFunction and explore whether it can be shared with JuliaBUGS models. This could help reduce code redundancy. cc @penelopeysm |
JuliaBUGS/Project.toml
Outdated
| name = "JuliaBUGS" | ||
| uuid = "ba9fb4c0-828e-4473-b6a1-cd2560fee5bf" | ||
| version = "0.10.3" | ||
| version = "0.10.4" |
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.
Is it really non-breaking to make such a big change?
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 adtype parameter is optional (defaults to nothing), all existing code works unchanged, so this is backward compatible.
However, if you prefer 0.11.0, I can change it.
|
I like this a lot, thanks! (The code really look fantastic and comprehensive.) I had a similar PR locally, but didn't push through because I feels like we should first test against the AD backends so that when we say we support, we actually support. Another thing to consider is whether we want to drop the support for LogDensityProblemsAD (I think the current PR will, so as it is, it should be breaking). @shravanngoswamii what do you think? |
Let's drop it unless there is a good reason. |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
Anything missing here? |
Yes, We haven't tested against all mentioned AD Backends, somehow I was getting few errors, will have to look into it properly.
Agree to you, we should test it before merging this!
@sunxd3 I think we should drop the support for this, but it's still used in many parts of codebase. I don't have any strong opinions, still haven't explored JuliaBUGS in depth! |
Julia 1.12 makes some changes to how world age is handled. JuliaBUGS use `eval` to generate node functions and this is problematic under 1.12. If a user uses JuliaBUGS `compile` in REPL, there is no problem, like before. This issue is particularly pronounced when using JuliaBUGS with a pattern like `compile -> LogDensityProblems.logdensity` within the same script. It can be pretty involved fixing the problem fundamentally. For now, this PR patches some of the tests to use `invokelatest` so they run. Other than it's nontrivial to fix the problem, we are likely seeing a change to the AD interface for JuliaBUGS following #397.
|
It's okay test ForwardDiff, and Mooncake only. Turing.jl will move towards Mooncake in the longer term. |
Resolved conflicts: - Project.toml: Use main's version (0.11.1) - benchmark/benchmark.jl: Added comparison table functions from main - benchmark/run_benchmarks.jl: Use main's new benchmark output format - src/JuliaBUGS.jl: Merged main's evaluation mode docs with HEAD's adtype feature - test/ext/JuliaBUGS*Ext.jl: Keep HEAD's adtype compile API
BREAKING: Use compile(...; adtype=...) or BUGSModelWithGradient(model, adtype) instead of ADgradient()
|
@shravanngoswamii I updated some code, can you give this a final review? |
Benchmark ResultsJulia 1.11.7 on AMD EPYC 7763 64-Core Processor (Linux) Ratio = JuliaBUGS/Stan (lower is better for JuliaBUGS)
Note: Stan benchmarks use hand-optimized Stan models, not direct BUGS translations. Comparison is illustrative only. |
@sunxd3 Thanks for taking this over. Everything looks good to me. Feel free to merge! |
|
Thanks! |
Replace
LogDensityProblemsADwithDifferentiationInterface.jlfor automatic differentiation.Changes:
adtypeparameter to compile() for specifying AD backends:ReverseDiff,:ForwardDiff,:Zygote,:EnzymeBUGSModelWithGradientwrapper withlogdensity_and_gradientmethodadtypecontinues to workUsage:
Closes #380