Skip to content

Reuse one memo when recovering the marginalized latents of a draw - #573

Draft
shravanngoswamii wants to merge 1 commit into
mainfrom
sg/backward-sample-memo
Draft

shravanngoswamii wants to merge 1 commit into
mainfrom
sg/backward-sample-memo

Conversation

@shravanngoswamii

Copy link
Copy Markdown
Member

Each latent built a fresh memo for every candidate value, so recovering one draw summed out the rest of the model once per latent.
A memo key already holds the values of the earlier latents the rest of the model depends on, which is why one log density evaluation can share a memo across all its branches.
Recovering a draw drops from about 3 s to 7 ms on Eye Tracking and from about 110 s to 0.05 s on Cervix, with the same draws for a given seed.

@github-actions

Copy link
Copy Markdown
Contributor

JuliaBUGS.jl documentation for PR #573 is available at:
https://TuringLang.github.io/JuliaBUGS.jl/previews/PR573/

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark Results

Julia 1.13.4 on AMD EPYC 9V74 80-Core Processor (Linux)

Ratio = JuliaBUGS/Stan (lower is better for JuliaBUGS)

# Params shows Stan / JuliaBUGS when parameter counts differ.

Log Density uses generated evaluation. Gradient columns measure log density + gradient.

McRvs = Mooncake reverse mode with generated evaluation; FwdDiff = ForwardDiff with graph evaluation.

Model # Params Log Density Ratio McRvs Ratio FwdDiff Ratio
rats 65 0.44x 1.97x 100.97x
pumps 12 1.66x 2.38x 19.41x
bones 13 0.62x 3.96x 0.28x
oxford 244 1.81x 5.40x 699.83x
epil 303 0.50x 1.91x 766.24x
lsat 1006 0.79x 2.55x 2158.94x
schools 133 0.34x 1.71x 126.63x
beetles 2 2.55x 7.00x 10.45x
air 5 1.86x 1.98x 12.57x

Note: Stan benchmarks use hand-optimized Stan models, not direct BUGS translations. Comparison is illustrative only.

@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.13%. Comparing base (5fd788c) to head (cabddd4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #573      +/-   ##
==========================================
- Coverage   88.49%   88.13%   -0.37%     
==========================================
  Files          30       30              
  Lines        3851     3851              
==========================================
- Hits         3408     3394      -14     
- Misses        443      457      +14     
Flag Coverage Δ
callbacks 28.50% <0.00%> (ø)
compilation_model 50.00% <0.00%> (ø)
compilation_source_gen 44.85% <0.00%> (ø)
distributed_sampling 38.55% <0.00%> (ø)
elementary 27.89% <0.00%> (ø)
frontend 47.02% <0.00%> (ø)
gibbs 39.63% <100.00%> (ø)
graphs 21.14% <0.00%> (ø)
inference_chains 37.07% <100.00%> (ø)
inference_flexichains ?
inference_hmc 29.90% <0.00%> (ø)
inference_marginalization 31.10% <100.00%> (ø)
inference_mh 35.46% <100.00%> (ø)
inference_slice_sampling 26.27% <0.00%> (ø)
log_density 59.15% <100.00%> (ø)
model_operations 43.01% <0.00%> (ø)
parallel_sampling ?
params_with_stats 38.18% <100.00%> (ø)
serialization 34.28% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

This branch has not been deployed

No deployments
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