Skip to content

Add more LDF accessor functions that Turing requires#1366

Merged
penelopeysm merged 4 commits into
mainfrom
py/ldf-again
Apr 22, 2026
Merged

Add more LDF accessor functions that Turing requires#1366
penelopeysm merged 4 commits into
mainfrom
py/ldf-again

Conversation

@penelopeysm
Copy link
Copy Markdown
Member

@penelopeysm penelopeysm commented Apr 21, 2026

Working on TuringLang/Turing.jl#2790 made me realise that LDF simply doesn't make enough of its internals explicit. Turing thus faces a choice of either depending on DPPL internals or using hacky workarounds. This PR therefore exposes a lower-level constructor for LogDensityFunction that allows Turing to essentially update the model in an LDF without having to rely on private fields (bad) or recreate any of the other arguments (hacky). See TuringLang/Turing.jl#2790 (comment).

@penelopeysm penelopeysm changed the title Add more accessor functions that Turing requires Add more LDF accessor functions that Turing requires Apr 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 21, 2026

Benchmark Report

  • this PR's head: 20c394c1cc9e023e7577ea7c6d4089b35f10c0e3
  • base branch: 10380bf7da86efc23768c977988306d4b6f1be41

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 │   274.56 │   295.58 │    0.93 │   7.73 │    7.45 │    1.04 │   2121.23 │   2201.34 │    0.96 │
│                   LDA │    12 │ reversediff │   true │  2578.63 │  2700.81 │    0.95 │   2.00 │    2.10 │    0.95 │   5151.29 │   5673.16 │    0.91 │
│   Loop univariate 10k │ 10000 │    mooncake │   true │ 30728.69 │ 31209.28 │    0.98 │   6.52 │    7.25 │    0.90 │ 200244.12 │ 226160.46 │    0.89 │
├───────────────────────┼───────┼─────────────┼────────┼──────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│    Loop univariate 1k │  1000 │    mooncake │   true │  3128.91 │  4107.06 │    0.76 │   6.38 │    5.55 │    1.15 │  19949.09 │  22805.87 │    0.87 │
│      Multivariate 10k │ 10000 │    mooncake │   true │ 31811.95 │ 40567.63 │    0.78 │   9.82 │    7.99 │    1.23 │ 312447.48 │ 324142.18 │    0.96 │
│       Multivariate 1k │  1000 │    mooncake │   true │  3360.48 │  4351.41 │    0.77 │   9.34 │    7.68 │    1.22 │  31379.69 │  33399.08 │    0.94 │
├───────────────────────┼───────┼─────────────┼────────┼──────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│ Simple assume observe │     1 │ forwarddiff │  false │     0.88 │     0.92 │    0.95 │  10.49 │   11.16 │    0.94 │      9.18 │     10.31 │    0.89 │
│           Smorgasbord │   201 │ forwarddiff │  false │   955.94 │   972.69 │    0.98 │ 143.73 │   77.04 │    1.87 │ 137398.79 │  74939.16 │    1.83 │
│           Smorgasbord │   201 │      enzyme │   true │  1273.65 │  1322.21 │    0.96 │   4.95 │    4.68 │    1.06 │   6300.95 │   6194.39 │    1.02 │
├───────────────────────┼───────┼─────────────┼────────┼──────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│           Smorgasbord │   201 │ forwarddiff │   true │  1342.43 │  1353.30 │    0.99 │  65.52 │   70.19 │    0.93 │  87957.05 │  94990.78 │    0.93 │
│           Smorgasbord │   201 │    mooncake │   true │  1275.64 │  1369.30 │    0.93 │   4.65 │    4.50 │    1.03 │   5934.64 │   6166.51 │    0.96 │
│           Smorgasbord │   201 │ reversediff │   true │  1273.15 │  1327.38 │    0.96 │ 126.94 │  126.76 │    1.00 │ 161611.38 │ 168256.19 │    0.96 │
├───────────────────────┼───────┼─────────────┼────────┼──────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│              Submodel │     1 │    mooncake │   true │     0.88 │     0.92 │    0.95 │  26.41 │   28.90 │    0.91 │     23.12 │     26.70 │    0.87 │
└───────────────────────┴───────┴─────────────┴────────┴──────────┴──────────┴─────────┴────────┴─────────┴─────────┴───────────┴───────────┴─────────┘

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.35%. Comparing base (10380bf) to head (20c394c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/logdensityfunction.jl 96.15% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1366   +/-   ##
=======================================
  Coverage   82.35%   82.35%           
=======================================
  Files          49       49           
  Lines        3502     3502           
=======================================
  Hits         2884     2884           
  Misses        618      618           

☔ 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

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

@penelopeysm penelopeysm merged commit 81a245a into main Apr 22, 2026
22 checks passed
@penelopeysm penelopeysm deleted the py/ldf-again branch April 22, 2026 09:07
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