Skip to content

push people towards init!! with explicit accs/init strategy/transform strategy#1264

Open
penelopeysm wants to merge 4 commits intobreakingfrom
py/more-docs
Open

push people towards init!! with explicit accs/init strategy/transform strategy#1264
penelopeysm wants to merge 4 commits intobreakingfrom
py/more-docs

Conversation

@penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Feb 7, 2026

see #1184

this PR is basically me trying to get people to stop using evaluate!!(model, vi) which is pretty hard to reason about. it depends on a lot of things:

  • the accs are taken from vi
  • the transform strategy is taken from model.context if it's an InitContext and otherwise it's inferred from vi,
  • the init strategy is taken from model.context if it's an InitContext and otherwise it's inferred from vi

(yeah, that's quite nasty)

instead of this the intention is to push people towards using

init!!([rng,] model, ::OnlyAccsVarInfo, init_strategy, transform_strategy)

because the end goal for DPPL (at least, my end goal) is to have a single evaluation method, whose name is not yet determined, but should take exactly those five arguments (perhaps in a different order).

i'll write docs on this soon.


unfortunately we still need to keep the old two-argument evaluate!! method around in DynamicPPL because things like init!! are defined in terms of it. it is possible to switch it round and make this depend on init!!, but that's a bit harder to do since that relies on getting rid of DefaultContext.

@penelopeysm
Copy link
Member Author

It might seem like I'm jumping the gun a bit with this and that v0.40 already has enough breaking changes. (The changelog is disgustingly complex)

The way I see it, though, I think that we've already done too many things to not commit to this. I think it's important that even though we might not yet be able to get rid of VarInfo*, we have a clear vision of what's going to happen going forward. It's one thing to say that there are 40 breaking changes and there might be 40 more to come; but if you say there are 40 breaking changes AND if you write your code this way you can avoid the worst of the 40 more breaking changes that have not yet landed, then that's just more friendly.

* This mostly depends on Turing & Gibbs. Although, I will note I was quite pleased that there are only five calls to evaluate!!(model, varinfo) in the Turing source code, and some of them can quite obviously be refactored to be init!!!

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

Benchmark Report

  • this PR's head: a8390de93fe193de67f495603c2094089ebb2432
  • base branch: 81c319cbd21f6580f4dbfaf97ed1e9684007754e

Computer Information

Julia Version 1.11.8
Commit cf1da5e20e3 (2025-11-06 17:49 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 4 × AMD EPYC 9V74 80-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver4)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)

Benchmark Results

┌───────────────────────┬───────┬─────────────┬────────┬───────────────────────────────┬────────────────────────────┬─────────────────────────────────┐
│                       │       │             │        │       t(eval) / t(ref)        │     t(grad) / t(eval)      │        t(grad) / t(ref)         │
│                       │       │             │        │ ─────────┬──────────┬──────── │ ───────┬─────────┬──────── │ ──────────┬───────────┬──────── │
│                 Model │   Dim │  AD Backend │ Linked │     base │  this PR │ speedup │   base │ this PR │ speedup │      base │   this PR │ speedup │
├───────────────────────┼───────┼─────────────┼────────┼──────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│               Dynamic │    10 │    mooncake │   true │   360.72 │   346.92 │    1.04 │  11.61 │   12.39 │    0.94 │   4186.44 │   4298.36 │    0.97 │
│                   LDA │    12 │ reversediff │   true │  2405.46 │  2563.41 │    0.94 │   5.15 │    4.84 │    1.06 │  12381.41 │  12406.17 │    1.00 │
│   Loop univariate 10k │ 10000 │    mooncake │   true │ 59058.66 │ 59703.46 │    0.99 │   5.35 │    5.28 │    1.01 │ 315720.58 │ 315380.27 │    1.00 │
├───────────────────────┼───────┼─────────────┼────────┼──────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│    Loop univariate 1k │  1000 │    mooncake │   true │  5890.64 │  5973.21 │    0.99 │   5.28 │    5.27 │    1.00 │  31077.40 │  31498.76 │    0.99 │
│      Multivariate 10k │ 10000 │    mooncake │   true │ 35139.17 │ 31319.18 │    1.12 │   8.78 │    9.77 │    0.90 │ 308630.83 │ 305934.52 │    1.01 │
│       Multivariate 1k │  1000 │    mooncake │   true │  7115.75 │  3344.01 │    2.13 │   4.32 │    9.76 │    0.44 │  30733.44 │  32646.10 │    0.94 │
├───────────────────────┼───────┼─────────────┼────────┼──────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│ Simple assume observe │     1 │ forwarddiff │  false │     2.55 │     2.49 │    1.02 │   3.72 │    3.87 │    0.96 │      9.48 │      9.63 │    0.98 │
│           Smorgasbord │   201 │ forwarddiff │  false │  1015.39 │  1029.26 │    0.99 │ 134.52 │  132.22 │    1.02 │ 136594.96 │ 136088.77 │    1.00 │
│           Smorgasbord │   201 │      enzyme │   true │  1402.97 │  1427.15 │    0.98 │   5.85 │    5.87 │    1.00 │   8204.53 │   8380.38 │    0.98 │
├───────────────────────┼───────┼─────────────┼────────┼──────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│           Smorgasbord │   201 │ forwarddiff │   true │  1392.58 │  1408.91 │    0.99 │  64.27 │   65.57 │    0.98 │  89500.87 │  92383.19 │    0.97 │
│           Smorgasbord │   201 │    mooncake │   true │  1400.79 │  1422.84 │    0.98 │   5.44 │    5.45 │    1.00 │   7615.12 │   7749.01 │    0.98 │
│           Smorgasbord │   201 │ reversediff │   true │  1396.93 │  1424.96 │    0.98 │ 101.06 │   99.46 │    1.02 │ 141179.13 │ 141728.79 │    1.00 │
├───────────────────────┼───────┼─────────────┼────────┼──────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│              Submodel │     1 │    mooncake │   true │     3.05 │     3.14 │    0.97 │  54.34 │   64.89 │    0.84 │    165.86 │    203.83 │    0.81 │
└───────────────────────┴───────┴─────────────┴────────┴──────────┴──────────┴─────────┴────────┴─────────┴─────────┴───────────┴───────────┴─────────┘

@codecov
Copy link

codecov bot commented Feb 7, 2026

Codecov Report

❌ Patch coverage is 80.76923% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.70%. Comparing base (81c319c) to head (a8390de).

Files with missing lines Patch % Lines
src/test_utils/model_interface.jl 0.00% 5 Missing ⚠️
src/accumulators/priors.jl 0.00% 3 Missing ⚠️
src/model.jl 90.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           breaking    #1264      +/-   ##
============================================
- Coverage     78.78%   78.70%   -0.09%     
============================================
  Files            46       46              
  Lines          3564     3555       -9     
============================================
- Hits           2808     2798      -10     
- Misses          756      757       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

DynamicPPL.jl documentation for PR #1264 is available at:
https://TuringLang.github.io/DynamicPPL.jl/previews/PR1264/

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.

1 participant