Skip to content

Conversation

@penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Jan 8, 2026

This PR fixes another feature regression in FastLDF, which is that the accumulators used for actual evaluation of the log-density are hardcoded. (Technically not hardcoded, but you have to overload some internal function, which is not good.)

In SlowLDF the accs were taken from the VarInfo passed in:

function LogDensityFunction(
model::Model,
getlogdensity::Function=getlogjoint_internal,
varinfo::AbstractVarInfo=ldf_default_varinfo(model, getlogdensity);
adtype::Union{ADTypes.AbstractADType,Nothing}=nothing,
)

I found that I needed this functionality in the optimisation code so that I can pass in the accumulator that checks at runtime whether constraints are satisfied.

I think this isn't breaking, since it's the final positional argument and it is optional.

@penelopeysm penelopeysm force-pushed the py/ldf-accs branch 3 times, most recently from ee6f77b to c04612a Compare January 8, 2026 15:05
@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

Benchmark Report

  • this PR's head: 7e63b619e58d19b9a7005a188dd82373477085f4
  • base branch: 47f6b7e9e72e23ba5f777d91b16c1f4064962992

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 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 │           VarInfo │ Linked │      base │   this PR │ speedup │   base │ this PR │ speedup │      base │   this PR │ speedup │
├───────────────────────┼───────┼─────────────┼───────────────────┼────────┼───────────┼───────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│               Dynamic │    10 │    mooncake │             typed │   true │    386.72 │    369.83 │    1.05 │  10.63 │   10.02 │    1.06 │   4109.95 │   3706.79 │    1.11 │
│                   LDA │    12 │ reversediff │             typed │   true │   2741.07 │   2630.28 │    1.04 │   4.94 │    5.01 │    0.98 │  13535.52 │  13188.03 │    1.03 │
│   Loop univariate 10k │ 10000 │    mooncake │             typed │   true │ 105343.13 │ 104025.91 │    1.01 │   4.14 │    3.83 │    1.08 │ 435985.15 │ 398535.16 │    1.09 │
├───────────────────────┼───────┼─────────────┼───────────────────┼────────┼───────────┼───────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│    Loop univariate 1k │  1000 │    mooncake │             typed │   true │   7890.33 │   7961.12 │    0.99 │   4.76 │    4.59 │    1.04 │  37538.22 │  36544.55 │    1.03 │
│      Multivariate 10k │ 10000 │    mooncake │             typed │   true │  30832.29 │  33311.59 │    0.93 │  10.55 │    9.89 │    1.07 │ 325340.55 │ 329366.03 │    0.99 │
│       Multivariate 1k │  1000 │    mooncake │             typed │   true │   3630.62 │   3620.74 │    1.00 │  12.88 │    9.20 │    1.40 │  46760.18 │  33304.56 │    1.40 │
├───────────────────────┼───────┼─────────────┼───────────────────┼────────┼───────────┼───────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│ Simple assume observe │     1 │ forwarddiff │             typed │  false │      2.73 │      2.66 │    1.03 │   3.92 │    3.98 │    0.99 │     10.72 │     10.60 │    1.01 │
│           Smorgasbord │   201 │ forwarddiff │             typed │  false │   1225.28 │   1210.56 │    1.01 │ 123.49 │  124.77 │    0.99 │ 151311.89 │ 151038.02 │    1.00 │
│           Smorgasbord │   201 │ forwarddiff │       simple_dict │   true │       err │       err │     err │    err │     err │     err │       err │       err │     err │
├───────────────────────┼───────┼─────────────┼───────────────────┼────────┼───────────┼───────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│           Smorgasbord │   201 │ forwarddiff │ simple_namedtuple │   true │       err │       err │     err │    err │     err │     err │       err │       err │     err │
│           Smorgasbord │   201 │      enzyme │             typed │   true │   1674.72 │   1675.04 │    1.00 │   6.72 │    6.18 │    1.09 │  11255.59 │  10356.75 │    1.09 │
│           Smorgasbord │   201 │    mooncake │             typed │   true │   1672.35 │   2346.28 │    0.71 │   5.19 │    3.77 │    1.38 │   8676.14 │   8842.10 │    0.98 │
├───────────────────────┼───────┼─────────────┼───────────────────┼────────┼───────────┼───────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│           Smorgasbord │   201 │ reversediff │             typed │   true │   1717.42 │   1662.47 │    1.03 │  89.21 │   93.20 │    0.96 │ 153218.69 │ 154935.49 │    0.99 │
│           Smorgasbord │   201 │ forwarddiff │      typed_vector │   true │   1673.14 │   1659.35 │    1.01 │  56.10 │   58.24 │    0.96 │  93865.83 │  96636.85 │    0.97 │
│           Smorgasbord │   201 │ forwarddiff │           untyped │   true │   1669.19 │   1654.66 │    1.01 │  58.12 │   58.30 │    1.00 │  97013.17 │  96463.03 │    1.01 │
├───────────────────────┼───────┼─────────────┼───────────────────┼────────┼───────────┼───────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│           Smorgasbord │   201 │ forwarddiff │    untyped_vector │   true │   1683.50 │   1674.34 │    1.01 │  55.73 │   57.53 │    0.97 │  93827.79 │  96316.85 │    0.97 │
│              Submodel │     1 │    mooncake │             typed │   true │      7.56 │      7.51 │    1.01 │   5.34 │    5.16 │    1.04 │     40.41 │     38.74 │    1.04 │
└───────────────────────┴───────┴─────────────┴───────────────────┴────────┴───────────┴───────────┴─────────┴────────┴─────────┴─────────┴───────────┴───────────┴─────────┘

@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

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

@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.00%. Comparing base (47f6b7e) to head (7e63b61).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1196   +/-   ##
=======================================
  Coverage   78.99%   79.00%           
=======================================
  Files          41       41           
  Lines        3938     3939    +1     
=======================================
+ Hits         3111     3112    +1     
  Misses        827      827           

☔ 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.

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

@penelopeysm penelopeysm merged commit 4caff69 into main Jan 9, 2026
21 checks passed
@penelopeysm penelopeysm deleted the py/ldf-accs branch January 9, 2026 16:24
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