Skip to content

[breaking] v0.41#1286

Merged
penelopeysm merged 39 commits intomainfrom
breaking
Apr 16, 2026
Merged

[breaking] v0.41#1286
penelopeysm merged 39 commits intomainfrom
breaking

Conversation

@penelopeysm
Copy link
Copy Markdown
Member

@penelopeysm penelopeysm commented Feb 24, 2026

Please see changelog for info. The main changes are fixed transforms + removal of vi[vn].

CI on Turing has already been run against this branch and there are no blockers. See TuringLang/Turing.jl#2803.

@penelopeysm penelopeysm marked this pull request as draft February 24, 2026 20:25
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 83.88278% with 44 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.32%. Comparing base (ff55ee8) to head (d7109bd).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/transformed_values.jl 75.82% 22 Missing ⚠️
src/varinfo.jl 88.88% 6 Missing ⚠️
src/abstract_varinfo.jl 33.33% 4 Missing ⚠️
src/accumulators/vector_values.jl 63.63% 4 Missing ⚠️
src/contexts/default.jl 40.00% 3 Missing ⚠️
src/accumulators/fixed_transforms.jl 85.71% 2 Missing ⚠️
src/contexts/init.jl 88.88% 2 Missing ⚠️
src/test_utils/ad.jl 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1286      +/-   ##
==========================================
+ Coverage   78.62%   82.32%   +3.69%     
==========================================
  Files          50       49       -1     
  Lines        3631     3496     -135     
==========================================
+ Hits         2855     2878      +23     
+ Misses        776      618     -158     

☔ 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
Copy Markdown
Contributor

github-actions bot commented Mar 6, 2026

Benchmark Report

  • this PR's head: d7109bdccbb470383be43a4505eead26461d6a65
  • base branch: ff55ee80d0ef66b82ab00195c3589d89574ccdea

Computer Information

Julia Version 1.11.9
Commit 53a02c0720c (2026-02-06 00:27 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 4 × AMD EPYC 7763 64-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver3)
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 │   318.00 │   271.11 │    1.17 │   6.89 │    6.48 │    1.06 │   2189.74 │   1757.28 │    1.25 │
│                   LDA │    12 │ reversediff │   true │  2735.21 │  2458.80 │    1.11 │   2.00 │    1.97 │    1.02 │   5462.67 │   4836.23 │    1.13 │
│   Loop univariate 10k │ 10000 │    mooncake │   true │ 30242.62 │ 30976.26 │    0.98 │   7.53 │    6.63 │    1.14 │ 227876.81 │ 205286.50 │    1.11 │
├───────────────────────┼───────┼─────────────┼────────┼──────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│    Loop univariate 1k │  1000 │    mooncake │   true │  4179.56 │  3866.41 │    1.08 │   5.41 │    5.37 │    1.01 │  22626.49 │  20770.58 │    1.09 │
│      Multivariate 10k │ 10000 │    mooncake │   true │ 45829.54 │ 34292.93 │    1.34 │   7.01 │    8.39 │    0.84 │ 321119.66 │ 287703.21 │    1.12 │
│       Multivariate 1k │  1000 │    mooncake │   true │  4033.79 │  3898.66 │    1.03 │   8.19 │    8.08 │    1.01 │  33024.24 │  31512.50 │    1.05 │
├───────────────────────┼───────┼─────────────┼────────┼──────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│ Simple assume observe │     1 │ forwarddiff │  false │     0.92 │     0.84 │    1.10 │  11.27 │   11.29 │    1.00 │     10.40 │      9.47 │    1.10 │
│           Smorgasbord │   201 │ forwarddiff │  false │   988.72 │   891.99 │    1.11 │  75.36 │   75.23 │    1.00 │  74513.83 │  67107.35 │    1.11 │
│           Smorgasbord │   201 │      enzyme │   true │  1345.11 │  1223.61 │    1.10 │   4.48 │    4.47 │    1.00 │   6031.50 │   5473.10 │    1.10 │
├───────────────────────┼───────┼─────────────┼────────┼──────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│           Smorgasbord │   201 │ forwarddiff │   true │  1362.19 │  1260.16 │    1.08 │  71.02 │   71.74 │    0.99 │  96739.08 │  90400.82 │    1.07 │
│           Smorgasbord │   201 │    mooncake │   true │  1348.78 │  1717.82 │    0.79 │   4.54 │    3.33 │    1.36 │   6116.76 │   5715.75 │    1.07 │
│           Smorgasbord │   201 │ reversediff │   true │  1337.94 │  1240.48 │    1.08 │ 123.02 │  126.46 │    0.97 │ 164589.99 │ 156868.56 │    1.05 │
├───────────────────────┼───────┼─────────────┼────────┼──────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│              Submodel │     1 │    mooncake │   true │     0.92 │     0.84 │    1.10 │  30.86 │   28.97 │    1.07 │     28.48 │     24.27 │    1.17 │
└───────────────────────┴───────┴─────────────┴────────┴──────────┴──────────┴─────────┴────────┴─────────┴─────────┴───────────┴───────────┴─────────┘

Closes #1309 

Simplifies `run_ad` by removing the `varinfo` keyword and using a single
`transform_strategy` path. Also replaces the `varinfo` field in
`ADResult` with `ldf::LogDensityFunction` and removes unused imports.

### Migration note

Before: `run_ad(model, adtype; varinfo=linked_vi)`
After: `run_ad(model, adtype; transform_strategy=LinkAll())`

---------

Co-authored-by: Penelope Yong <penelopeysm@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 8, 2026

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

penelopeysm and others added 11 commits March 21, 2026 04:09
closes #1256

---------

Co-authored-by: hardik-xi11 <hardiklaha@gmail.com>
Co-authored-by: Penelope Yong <penelopeysm@gmail.com>
Closes #1249. I'll write more here later, but you can see the changelog
for a good overview of this PR.

Things to do

- [x] Generalise LinkedVecTransformAccumulator to something that's more
like FixedTransformAccumulator
- [x] Add a convenience function for 'static'-fying an LDF (?)
- [x] Add tests for new behaviour
- [x] Add dev docs on FixedTransform

Possibly in a separate PR:

- [ ] Look at the Turing VI interface to see what it needs from
`bijector(model)`, and whether that can be removed (though, note also
TuringLang/Turing.jl#2783)

----

Some scripts to use to benchmark:

```julia
using DynamicPPL, Distributions, LogDensityProblems, Random, Chairmarks, ForwardDiff, ADTypes, LinearAlgebra

# @model function esc(J, y, sigma)
#     mu ~ Normal(0, 5)
#     tau ~ truncated(Cauchy(0, 5); lower=0)
#     theta ~ MvNormal(fill(mu, J), tau^2 * I)
#     for i in 1:J
#         y[i] ~ Normal(theta[i], sigma[i])
#     end
# end
# J = 8
# y = [28, 8, -3, 7, -1, 1, 18, 12]
# sigma = [15, 10, 16, 11, 9, 11, 10, 18]
# m = esc(J, y, sigma)

@model function f()
    x ~ product_distribution([Beta(2,2), Uniform(4, 5), Normal()])
end
m = f()

ldf1 = LogDensityFunction(m, getlogjoint_internal, LinkAll(); adtype=AutoForwardDiff(), fix_transforms=true);
p = rand(Xoshiro(468), ldf1);
@b LogDensityProblems.logdensity(ldf1 ,p)
@b LogDensityProblems.logdensity_and_gradient(ldf1 ,p)

ldf2 = LogDensityFunction(m, getlogjoint_internal, LinkAll(); adtype=AutoForwardDiff());
p = rand(Xoshiro(468), ldf2);
@b LogDensityProblems.logdensity(ldf2 ,p)
@b LogDensityProblems.logdensity_and_gradient(ldf2 ,p)
```

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Hardik Kumar <hardikkumarpro0005@gmail.com>
Co-authored-by: hardik-xi11 <hardiklaha@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This extracts the raw value from a `TransformedValue`. In the cases
where the transform is dynamic, it also demands that the distribution be
supplied.

It also adds an overload for `ParamsWithStats(vector, ldf)`, which
avoids re-evaluating the model when it's not needed (i.e., in the
special case where the LDF is constructed with fixed transforms for all
variables).

- ~~I found that not having this was actually a blocker for the VI stuff
upstream because in the docs there's an example of `rand(vi_result,
100000)`
(https://turinglang.org/docs/tutorials/variational-inference/#obtaining-summary-statistics).
Previously, this would just return each sample as a raw vector, which I
don't like (TuringLang/Turing.jl#2783): I
would much prefer it return a `VarNamedTuple`, and so I changed it to do
so. However, in the process, it ends up evaluating the model 100000
times and (for some unknown reason) crashes Julia on my laptop. This is
a quick workaround to avoid having to evaluate the model, although in
general I'd probably still like to know why it crashes (it can't be that
handling 100000 VNTs is problematic, otherwise we would already have
tons of issues with MCMC).~~ The crash (which I think is an OOM) is
fixed by #1350

The code is mostly Claude, but I gave it a lot of steering, and did a
few changes by hand. I will self-review this tomorrow.

Closes #1347 (partly ... for now)
@penelopeysm penelopeysm marked this pull request as ready for review April 14, 2026 16:32
@penelopeysm
Copy link
Copy Markdown
Member Author

@sunxd3 Would you be happy to release this in its current state? (For context, about 90% of the changes are the fixed transform stuff which you already reviewed)

@penelopeysm
Copy link
Copy Markdown
Member Author

This was discussed offline and I've addressed all of the review comments, so will merge. I will keep the MLD extension here for this release and maybe remove it in a patch release once it can be synchronised with upstream.

@penelopeysm penelopeysm merged commit 6595674 into main Apr 16, 2026
22 checks passed
@penelopeysm penelopeysm deleted the breaking branch April 16, 2026 17:10
@sunxd3
Copy link
Copy Markdown
Member

sunxd3 commented Apr 17, 2026

Thanks, Penny!

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.

4 participants