Skip to content

Handle multinomial latents in auto-marginalization - #574

Open
umrndem wants to merge 2 commits into
TuringLang:mainfrom
umrndem:fix/auto-marginalization-multivariate-discrete
Open

umrndem wants to merge 2 commits into
TuringLang:mainfrom
umrndem:fix/auto-marginalization-multivariate-discrete

Conversation

@umrndem

@umrndem umrndem commented Nov 18, 2026

Copy link
Copy Markdown

Fixes #561.

Auto-marginalization treated a latent dmulti node as continuous. Classify multivariate discrete variables explicitly so unsupported latents warn and fall back to UseGraph(). Observed multinomial nodes can still be used in auto-marginalization mode.

The two new warning and fallback assertions failed before the fix. All 5,309 assertions in model/auto_marginalization.jl passed afterward on Julia 1.12.7, including the observed multinomial case.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the change adding graph fallback for unsupported multivariate discrete latents.

No open issues 🎉

What changed in this PR

Fixes #561 by preventing JuliaBUGS auto-marginalization from treating latent multinomial counts as continuous parameters. Unsupported multivariate discrete latents now trigger a warning and fall back to UseGraph().

Changes:

  • Adds explicit classification and fallback handling for multivariate discrete latents.
  • Adds regression tests for latent fallback and continued acceptance of observed multinomial nodes.
  • Updates documentation to clarify supported latents and fallback behavior.
File Description
JuliaBUGS/​test/​model/​auto_marginalization.jl Tests latent multinomial fallback and observed multinomial compatibility.
JuliaBUGS/​src/​model/​evaluation.jl Adds explicit multivariate discrete classification.
JuliaBUGS/​src/​model/​bugsmodel.jl Rejects unsupported multivariate discrete latents to trigger graph fallback.
JuliaBUGS/​docs/​src/​inference/​auto_marginalization.md Documents supported latents and multinomial fallback behavior.

Review effort: Balanced

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #574      +/-   ##
==========================================
+ Coverage   88.49%   88.56%   +0.06%     
==========================================
  Files          30       30              
  Lines        3851     3855       +4     
==========================================
+ Hits         3408     3414       +6     
+ Misses        443      441       -2     
Flag Coverage Δ
callbacks 28.52% <50.00%> (+0.02%) ⬆️
compilation_model 49.94% <0.00%> (-0.06%) ⬇️
compilation_source_gen 44.81% <0.00%> (-0.05%) ⬇️
distributed_sampling 38.51% <0.00%> (-0.05%) ⬇️
elementary 27.86% <0.00%> (-0.03%) ⬇️
frontend 46.97% <0.00%> (-0.05%) ⬇️
gibbs 40.24% <75.00%> (+0.60%) ⬆️
graphs 21.12% <0.00%> (-0.03%) ⬇️
inference_chains 37.08% <50.00%> (+0.01%) ⬆️
inference_flexichains 41.26% <50.00%> (+<0.01%) ⬆️
inference_hmc 29.87% <0.00%> (-0.04%) ⬇️
inference_marginalization 31.12% <50.00%> (+0.01%) ⬆️
inference_mh 35.47% <50.00%> (+0.01%) ⬆️
inference_slice_sampling 26.27% <25.00%> (-0.01%) ⬇️
log_density 59.29% <100.00%> (+0.14%) ⬆️
model_operations 42.96% <0.00%> (-0.05%) ⬇️
parallel_sampling 24.04% <0.00%> (-0.03%) ⬇️
params_with_stats 38.19% <50.00%> (+0.01%) ⬆️
serialization 34.24% <0.00%> (-0.04%) ⬇️

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.

@shravanngoswamii shravanngoswamii left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_require_continuous_gibbs_component still lets :discrete_multivariate through, so Gibbs accepts NUTS on a latent dmulti while it rejects it on a latent dpois (gibbs.jl#L86-L99).

Could it reject :discrete_multivariate too? cc @sunxd3

@shravanngoswamii shravanngoswamii left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this get a History.md entry under Bug Fixes? 0.18.1 is tagged, so it would go under a new 0.18.2 heading.

@umrndem

umrndem commented Nov 19, 2026

Copy link
Copy Markdown
Author

thanks for catching that. the Gibbs guard now rejects multivariate discrete variables for NUTS and slice sampling, and i added a regression test for each. i also added the bug fix entry under 0.18.2 in History.md. both test groups passed locally.

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark Results

Julia 1.13.4 on Intel(R) Xeon(R) 6975P-C (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.86x 82.17x
pumps 12 1.70x 1.99x 15.33x
bones 13 0.49x 4.13x 0.50x
oxford 244 1.57x 4.20x 548.87x
epil 303 0.47x 1.46x 1023.77x
lsat 1006 0.66x 1.75x 1663.27x
schools 133 0.29x 1.69x 51.55x
beetles 2 2.77x 5.13x 21.93x
air 5 2.11x 1.77x 12.48x

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

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.

Auto-marginalization classifies dmulti nodes as continuous

3 participants