Skip to content

Support DPPL 0.37 #2550

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 52 commits into from
Aug 12, 2025
Merged

Support DPPL 0.37 #2550

merged 52 commits into from
Aug 12, 2025

Conversation

mhauru
Copy link
Member

@mhauru mhauru commented May 15, 2025

Currently in a very unfinished state.

@yebai
Copy link
Member

yebai commented May 18, 2025

Lots of interface code changes here are unnecessary and are planned to be removed in #2413

Perhaps we should address #2413 first.

@mhauru
Copy link
Member Author

mhauru commented May 20, 2025

That is tempting, to not waste time fixing code that's on its way out. I worry though that removing the samplers will take a while still, and in the meanwhile all the accumulator stuff, and other DPPL changes that build on it, would be held back from Turing.jl. For instance, introducing ValuesAsInModelAccumulator would cut our inference time in #2542 by half.

@penelopeysm
Copy link
Member

penelopeysm commented Jul 17, 2025

IMO, it goes both ways. Reducing sampler complexity would make this PR easier. On the other hand, merging this PR would also make it easier to remove the duplicate samplers. (To be precise, DPPL 0.37 would make it easier.)

I think DPPL 0.37 has taken a long time and we should prioritise this, rather than trying to squeeze in the changes to samplers.

I'm going to fix the merge conflicts and add a [sources] bit to Project.toml to point to the unreleased DPPL branch, so that CI can at least run on 1.11. (See https://pkgdocs.julialang.org/v1/toml-files/#The-%5Bsources%5D-section)

Note that 1.10 CI will always fail as [sources] isn't understood on 1.10.

test/mcmc/hmc.jl Outdated
Comment on lines 174 to 175
# TODO(mhauru) Do we give up being able to sample from only prior/likelihood like this,
# or do we implement some way to pass `whichlogprob=:LogPrior` through `sample`?
Copy link
Member

Choose a reason for hiding this comment

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

sample(::LogDensityFunction) would solve that, since we could set getlogprior in the LDF, but I guess that'll be the next release.

Comment on lines -196 to -201
# TODO(penelopeysm): Can we just use leafcontext(model.context)? Do we
# need to pass in the sampler? (In fact LogDensityFunction defaults to
# using leafcontext(model.context) so could we just remove the argument
# entirely?)
DynamicPPL.SamplingContext(rng, spl, DynamicPPL.leafcontext(model.context));
adtype=spl.alg.adtype,
Copy link
Member

Choose a reason for hiding this comment

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

As established in (e.g.) TuringLang/DynamicPPL.jl#955 (comment) SamplingContext for Hamiltonians was never overloaded so it is equivalent to just use DefaultContext in the LDF.

@penelopeysm
Copy link
Member

Because Turing re-exports some things that were changed in DPPL 0.37 (for example, LogDensityFunction), this has to go into breaking. (It probably philosophically should anyway, since I think this might be the biggest makeover that DPPL has had in a while.)

@penelopeysm penelopeysm changed the base branch from main to breaking July 19, 2025 14:46
Copy link
Contributor

Turing.jl documentation for PR #2550 is available at:
https://TuringLang.github.io/Turing.jl/previews/PR2550/

* Use new `getlogjoint` for optimisation

* Change getlogjoint -> getlogjoint_internal where needed

* Enforce re-evaluation when constructing `Transition`

* fix tests

* Remove extra evaluations from SGLD and SGHMC

* Remove dead `transitions_from_chain` method (used to be part of `predict`)

* metadata -> getstats_with_lp

* Clean up some stray getlogp
@mhauru mhauru mentioned this pull request Aug 1, 2025
22 tasks
Comment on lines +606 to +619
# TODO(DPPL0.37/penelopeysm): decide what to do with these tests
@testset "Coalescing multiple observations into one" begin
# Instead of observing x[1] and x[2] separately, we lump them into a
# single distribution.
@model function dynamic_bernoulli()
b ~ Bernoulli()
if b
dists = [Normal(1.0)]
else
dists = [Normal(1.0), Normal(2.0)]
end
return x ~ product_distribution(dists)
end
model = dynamic_bernoulli()
Copy link
Member

Choose a reason for hiding this comment

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

To be discussed @ 4 Aug meeting

* Allow Prior to skip model re-evaluation

* remove unneeded `default_chain_type` method

* add a test

* add a likelihood term too

* why not test correctness while we're at it
@penelopeysm penelopeysm force-pushed the mhauru/dppl-0.37 branch 2 times, most recently from 8af36e1 to 806c82d Compare August 7, 2025 10:43
@penelopeysm
Copy link
Member

penelopeysm commented Aug 7, 2025

Apologies for force push, I did it on the wrong branch. I undid it (force pushed back to the old commit) so it shouldn't affect any local git history. CI is now failing because DynamicPPL's breaking branch doesn't exist... hmmmm

@penelopeysm
Copy link
Member

I'd be happy to merge TuringLang/DynamicPPL.jl#1005, release DPPL, then remove the [sources] thing here and maybe merge this into breaking (I don't think there are any other breaking changes that this will hold up).

@mhauru
Copy link
Member Author

mhauru commented Aug 7, 2025

I agree on that plan.

penelopeysm and others added 3 commits August 11, 2025 14:30
* Remove calls to resetlogp!!

* Add a changelog for 0.40

* Update HISTORY.md

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

---------

Co-authored-by: Markus Hauru <[email protected]>
* Unify `Transition` methods

* Add tests

* Add same test for SGLD/SGHMC

* Refactor so that it's nice and organised

* Fix failing test on 1.10

* just increase the atol

* Make addlogprob test more robust

* Remove stray `@show`

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

---------

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

@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'm very pleased with where we are on this, would be happy to merge into breaking and then main. Was there anything else you wanted to add to 0.40?

@mhauru mhauru marked this pull request as ready for review August 12, 2025 13:59
@mhauru
Copy link
Member Author

mhauru commented Aug 12, 2025

Thanks, very happy with that. I'm good to merge and release once tests pass. You wanna do it?

@penelopeysm
Copy link
Member

Okay 😄

@penelopeysm
Copy link
Member

I'll merge into breaking then let CI run on that branch.

@penelopeysm penelopeysm merged commit ee0b095 into breaking Aug 12, 2025
24 of 30 checks passed
@penelopeysm penelopeysm deleted the mhauru/dppl-0.37 branch August 12, 2025 14:02
penelopeysm added a commit that referenced this pull request Aug 12, 2025
* [no ci] Bump to v0.40.0

* Uncomment tests that should be there

* Support DPPL 0.37 (#2550)

* First efforts towards DPPL 0.37 compat, WIP

* More DPPL 0.37 compat work, WIP

* Add [sources] for [email protected]

* Remove context argument from `LogDensityFunction`

* Fix MH

* Remove spurious logging

* Remove residual OptimizationContext

* Delete files that were removed in previous releases

* Fix typo

* Simplify ESS

* Fix LDF

* Fix Prior(), fix a couple more imports

* fixes

* actually fix prior

* Remove extra return value from tilde_assume

* fix ldf

* actually fix prior

* fix HMC log-density

* fix ldf

* fix make_evaluate_...

* more fixes for evaluate!!

* fix hmc

* fix run_ad

* even more fixes (oh goodness when will this end)

* more fixes

* fix

* more fix fix fix

* fix return values of tilde pipeline

* even more fixes

* Fix missing import

* More MH fixes

* Fix conversion

* don't think it really needs those type params

* implement copy for LogPriorWithoutJacAcc

* Even more fixes

* More fixes; I think the remaining failures are pMCMC related

* Fix merge

* DPPL 0.37 compat for particle MCMC (#2625)

* Progress in DPPL 0.37 compat for particle MCMC

* WIP PMCMC work

* Gibbs fixes for DPPL 0.37 (plus tiny bugfixes for ESS + HMC) (#2628)

* Obviously this single commit will make Gibbs work

* Fixes for ESS

* Fix HMC call

* improve some comments

* Fixes to ProduceLogLikelihoodAccumulator

* Use LogProbAccumulator for ProduceLogLikelihoodAccumulator

* use get_conditioned_gibbs

---------

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

* "Fixes" for PG-in-Gibbs (#2629)

* WIP PMCMC work

* Fixes to ProduceLogLikelihoodAccumulator

* inline definition of `set_retained_vns_del!`

* Fix ProduceLogLikelihoodAcc

* Remove all uses of `set_retained_vns_del!`

* Use nice functions

* Remove PG tests with dynamic number of Gibbs-conditioned-observations

* Fix essential/container tests

* Update pMCMC implementation as per discussion

* remove extra printing statements

* revert unneeded changes

* Add back (some kind of) dynamic model test

* fix rebase

* Add a todo comment for dynamic model tests

---------

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

* Use accumulators to fix all logp calculations when sampling (#2630)

* Use new `getlogjoint` for optimisation

* Change getlogjoint -> getlogjoint_internal where needed

* Enforce re-evaluation when constructing `Transition`

* fix tests

* Remove extra evaluations from SGLD and SGHMC

* Remove dead `transitions_from_chain` method (used to be part of `predict`)

* metadata -> getstats_with_lp

* Clean up some stray getlogp

* InitContext isn't for 0.37, update comments

* Fix merge

* Do not re-evaluate model for Prior (#2644)

* Allow Prior to skip model re-evaluation

* remove unneeded `default_chain_type` method

* add a test

* add a likelihood term too

* why not test correctness while we're at it

* No need to test AD for SamplingContext{<:HMC} (#2645)

* change breaking -> main

* Remove calls to resetlogp!! & add changelog (#2650)

* Remove calls to resetlogp!!

* Add a changelog for 0.40

* Update HISTORY.md

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

---------

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

* Remove `[sources]`

* Unify Turing `Transition`s, fix some tests (#2651)

* Unify `Transition` methods

* Add tests

* Add same test for SGLD/SGHMC

* Refactor so that it's nice and organised

* Fix failing test on 1.10

* just increase the atol

* Make addlogprob test more robust

* Remove stray `@show`

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

---------

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

* Update changelog for PG in Gibbs

---------

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

---------

Co-authored-by: Markus Hauru <[email protected]>
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.

3 participants