Skip to content

remove LogDensityProblemsAD #2490

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

Merged
merged 10 commits into from
Feb 25, 2025
Merged

remove LogDensityProblemsAD #2490

merged 10 commits into from
Feb 25, 2025

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Feb 20, 2025

this PR removes LogDensityProblemsAD in favour of using the new interface in TuringLang/DynamicPPL.jl#806

Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 4.91803% with 58 lines in your changes missing coverage. Please review.

Project coverage is 29.77%. Comparing base (52b2105) to head (7c32e3e).
Report is 1 commits behind head on mhauru/dppl-0.35.

Files with missing lines Patch % Lines
src/optimisation/Optimisation.jl 0.00% 28 Missing ⚠️
ext/TuringOptimExt.jl 0.00% 15 Missing ⚠️
src/mcmc/hmc.jl 0.00% 9 Missing ⚠️
src/mcmc/abstractmcmc.jl 60.00% 2 Missing ⚠️
src/mcmc/sghmc.jl 0.00% 2 Missing ⚠️
ext/TuringDynamicHMCExt.jl 0.00% 1 Missing ⚠️
src/mcmc/gibbs.jl 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##           mhauru/dppl-0.35    #2490      +/-   ##
====================================================
+ Coverage             26.93%   29.77%   +2.83%     
====================================================
  Files                    21       21              
  Lines                  1407     1387      -20     
====================================================
+ Hits                    379      413      +34     
+ Misses                 1028      974      -54     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member Author

@penelopeysm penelopeysm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the entire test/ad.jl file, my reasoning is explained below

Comment on lines -54 to -56
@test l ≈ logp
@test sort(∇E) ≈ grad_FWAD atol = 1e-9
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this checks that the gradient obtained with LogDensityProblemsAD is equal to the gradient obtained directly with ForwardDiff - this isn't Turing's job to test hence removed

Comment on lines -105 to -107
@test zygoteℓ.ℓ === ℓ
∇E2 = LogDensityProblems.logdensity_and_gradient(zygoteℓ, x)[2]
@test sort(∇E2) ≈ grad_FWAD atol = 1e-9
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is checking that Zygote gives the same gradient as ForwardDiff does.

Firstly Zygote isn't formally supported so I don't think we need to test its correctness on this one particular model, and secondly if we did want to support it we should add this to the DPPL test suite

@test sort(∇E2) ≈ grad_FWAD atol = 1e-9
end

@testset "general AD tests" begin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole testset is just testing AD correctness on various models, and should all be moved into DynamicPPL, if it's not already there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's there already, in test/compat/ad.jl.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay what that's so weird. Doubly happy to delete it then


test_model_ad(wishart_ad(), logp3, [:v])
end
@testset "Simplex Zygote and ReverseDiff (with and without caching) AD" begin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with this one, it's not even testing correctness, it's just testing that AD can run

sample(invwishart(), HMC(0.01, 1; adtype=AutoReverseDiff(; compile=false)), 1000)
sample(invwishart(), HMC(0.01, 1; adtype=AutoZygote()), 1000)
end
@testset "Hessian test" begin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with this one, it's testing correctness of Hessians against an analytic value, it's not really our job imo

@test H_f == H_r
end

@testset "memoization: issue #1393" begin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think this testset is relevant anymore because the memoisation code has been long removed #1414

end
end

@testset "ReverseDiff compiled without linking" begin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this testset is fully contained in DynamicPPL already

@penelopeysm penelopeysm requested a review from mhauru February 20, 2025 15:12
@penelopeysm penelopeysm changed the title remove LogDensityProblemsAD part 1 remove LogDensityProblemsAD Feb 20, 2025
@penelopeysm penelopeysm marked this pull request as ready for review February 21, 2025 18:55
Copy link
Member

@mhauru mhauru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One question mostly out of curiosity.

@@ -202,7 +202,7 @@ end
All the ADTypes on which we want to run the tests.
"""
adbackends = [
Turing.AutoForwardDiff(; chunksize=0),
Turing.AutoForwardDiff(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the significance of not setting chunksize?

Copy link
Member Author

@penelopeysm penelopeysm Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if chunksize isn't set it will default to nothing, and both 0 and nothing will get 'optimised' into the same thing by this function in DynamicPPLForwardDiffExt https://github.com/TuringLang/DynamicPPL.jl/blob/90c7b26c852b7d0ae87dee0a5a0010b097a0c1d3/ext/DynamicPPLForwardDiffExt.jl#L10-L40

but also technically chunksize=0 is 'wrong' and not supported in DifferentiationInterface, the fact that it works in Turing is solely because of that extension, which I'd honestly like to get rid of but have mainly kept around for compatibility - see TuringLang/DynamicPPL.jl#806 (comment)

if the extension isn't present, then chunksize=0 actually errors, and I believe it was the source of this error #2369 (it's because ForwardDiff tries to count the number of chunks by dividing by the chunksize). I suspect that that error appeared because Optimisation.jl started using DifferentiationInterface under the hood

@penelopeysm penelopeysm merged commit ee2b148 into mhauru/dppl-0.35 Feb 25, 2025
18 of 52 checks passed
@penelopeysm penelopeysm deleted the py/no-ldp-ad branch February 25, 2025 14:39
mhauru added a commit that referenced this pull request Mar 13, 2025
* Progress towards compat with DPPL v0.35

* More fixing of DPPL v0.35 stuff

* Fix LogDensityFunction argument order

* More minor bugfixes

* [TEMP] Commit Manifest pointing to DynamicPPL#release-0.35

* remove LogDensityProblemsAD (#2490)

* Remove LogDensityProblemsAD, part 1

* update Optimisation code to not use LogDensityProblemsAD

* Fix field name change

* Don't put chunksize=0

* Remove LogDensityProblemsAD dep

* Improve OptimLogDensity docstring

* Remove unneeded model argument to _optimize

* Fix more tests

* Remove essential/ad from the list of CI groups

* Fix HMC function

* more test fixes (#2491)

* Remove LogDensityProblemsAD, part 1

* update Optimisation code to not use LogDensityProblemsAD

* Fix field name change

* Don't put chunksize=0

* Remove LogDensityProblemsAD dep

* Improve OptimLogDensity docstring

* Remove unneeded model argument to _optimize

* Fix more tests

* Remove essential/ad from the list of CI groups

* Fix HMC function

* More test fixes

* Remove Manifest

* More fixes for DynamicPPL 0.35 (#2494)

* Remove test/dynamicppl/compiler.jl

* Remove old regression tests

* Remove vdemo2

* Fix last test

* Add HISTORY.md entry about DPPL 0.35

* Allow ESS to sample variables with different symbols

* Update a TODO note

---------

Co-authored-by: Penelope Yong <[email protected]>
mhauru added a commit that referenced this pull request Mar 19, 2025
* Bump minor version to v0.37

* Remove selector/space stuff (#2458)

* Remove selector stuff from ESS

* Remove selector stuff from MH

* Remove selector stuff from HMC

* Remove selector stuff from Emcee

* Remove selector stuff from IS

* Add missing getspace methods

* Remove selector stuff for particle methods

* Fix an HMC selector bug

* Code style

* Fix Emcee selector bug

* Fix typo in ESS tests

* Fix some constructor overwrites

* Remove unnecessary tests

* Remove selector stuff from SGHMC

* Remove drop_space and other non-longer-necessary deprecation measures

* Bump minor version 0.37. Add a HISTORY.md entry

* Apply suggestions from code review

Co-authored-by: Penelope Yong <[email protected]>

* Remove unnecessary type parameters

Co-authored-by: Penelope Yong <[email protected]>

* Simplify constructors in particle_mcmc.jl

* Remove calls to setgid and updategid

---------

Co-authored-by: Penelope Yong <[email protected]>

* Bump Mooncake compat to 0.4.95

* Support for DynamicPPL v0.35 (#2488)

* Progress towards compat with DPPL v0.35

* More fixing of DPPL v0.35 stuff

* Fix LogDensityFunction argument order

* More minor bugfixes

* [TEMP] Commit Manifest pointing to DynamicPPL#release-0.35

* remove LogDensityProblemsAD (#2490)

* Remove LogDensityProblemsAD, part 1

* update Optimisation code to not use LogDensityProblemsAD

* Fix field name change

* Don't put chunksize=0

* Remove LogDensityProblemsAD dep

* Improve OptimLogDensity docstring

* Remove unneeded model argument to _optimize

* Fix more tests

* Remove essential/ad from the list of CI groups

* Fix HMC function

* more test fixes (#2491)

* Remove LogDensityProblemsAD, part 1

* update Optimisation code to not use LogDensityProblemsAD

* Fix field name change

* Don't put chunksize=0

* Remove LogDensityProblemsAD dep

* Improve OptimLogDensity docstring

* Remove unneeded model argument to _optimize

* Fix more tests

* Remove essential/ad from the list of CI groups

* Fix HMC function

* More test fixes

* Remove Manifest

* More fixes for DynamicPPL 0.35 (#2494)

* Remove test/dynamicppl/compiler.jl

* Remove old regression tests

* Remove vdemo2

* Fix last test

* Add HISTORY.md entry about DPPL 0.35

* Allow ESS to sample variables with different symbols

* Update a TODO note

---------

Co-authored-by: Penelope Yong <[email protected]>

* Fix call to DynamicPPL.initialize_parameters!!

* Remove `Zygote` (#2505)

* Remove `Zygote`; fix #2504

* Update test/test_utils/ad_utils.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Add HISTORY.md entry about removing support for Zygote

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Markus Hauru <[email protected]>
Co-authored-by: Penelope Yong <[email protected]>
Co-authored-by: Markus Hauru <[email protected]>

* Fix a Gibbs test

* Clean up exports (#2474)

* Regroup exports by package

* Export DynamicPPL.returned and DynamicPPL.prefix

* Stop exporting  @logprob_str and @prob_str

* Remove DynamicPPL module export

* Remove DynamicPPL.LogDensityFunction re-export

* Remove BernoulliLogit, drop support for Distributions < 0.25.77

* Stop blanket re-exporting Libtask and Bijectors

* Manually specify AbstractMCMC exports

* Format

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Remove Bijectors.ordered export

* Re-export LinearAlgebra.I

* Replace Turing.Model -> DynamicPPL.Model

* Format

* Keep exporting LogDensityFunction

* Add note in docs

* Align Turing exports with docs API page

* Fix things like `predict` on docs API page

* Fix a Gibbs test

* Format

* Fix missing Bijectors import

* Update docs/src/api.md

Co-authored-by: Markus Hauru <[email protected]>

* Update docs/src/api.md

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Clean up broken docs links, remove unneeded deps

* Format

* Add changelog entry for exports

* Clean up exports in essential/Essential

* Apply suggestions from code review

Co-authored-by: Markus Hauru <[email protected]>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Markus Hauru <[email protected]>
Co-authored-by: Markus Hauru <[email protected]>

---------

Co-authored-by: Penelope Yong <[email protected]>
Co-authored-by: Hong Ge <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants