Skip to content

Add SamplingOutput model evaluation and MCMCChains conversion - #1506

Merged
yebai merged 12 commits into
mainfrom
samplingoutput
Sep 21, 2026
Merged

yebai merged 12 commits into
mainfrom
samplingoutput

Conversation

@yebai

@yebai yebai commented Sep 20, 2026

Copy link
Copy Markdown
Member

This PR adds support for SamplingOutput: model returned, predict, and pointwise log densities, plus conversion to MCMCChains.Chains. It also fixes a few minor issues in MCMCChains (see code).

@model demo(y) = (x ~ Normal(); y ~ Normal(x))

chain = AbstractMCMC.SamplingOutput(fill(VarNamedTuple(; x=0.5), 10, 1))

values = returned(demo(1.0), chain)
densities = pointwise_logdensities(demo(1.0), chain)
likelihoods = pointwise_loglikelihoods(demo(1.0), chain)
priors = pointwise_prior_logdensities(demo(1.0), chain)
predictions = predict(demo(missing), chain)
mcmcchain = convert(MCMCChains.Chains, predictions)

Assisted-by: Codex <codex@openai.com>
Assisted-by: Codex <codex@openai.com>
Assisted-by: Codex <codex@openai.com>
Assisted-by: Codex <codex@openai.com>
@codecov

codecov Bot commented Sep 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.82759% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.09%. Comparing base (7a7da38) to head (7101ad6).

Files with missing lines Patch % Lines
src/chains.jl 95.12% 2 Missing ⚠️
ext/DynamicPPLMCMCChainsExt.jl 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1506      +/-   ##
==========================================
+ Coverage   83.92%   84.09%   +0.17%     
==========================================
  Files          54       54              
  Lines        4683     4741      +58     
==========================================
+ Hits         3930     3987      +57     
- Misses        753      754       +1     

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

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Benchmarks @ 7101ad6

Performance Ratio: gradient time divided by log-density time.

For very small models these ratios are noisy across runs and machines; raw primal and gradient timings are more reliable. The benchmarks are aimed at DynamicPPL developers and mainly catch obvious allocation or type-stability regressions. See benchmark notes for details.

===================================================================================================
                                               eval                       gradient                 
                                            ----------  -------------------------------------------
Model                        dim    linked      primal     FwdDiff    RvsDiff    Mooncake    Enzyme
---------------------------------------------------------------------------------------------------
Simple assume observe*         1     false     5.87 ns        9.10    1163.52        9.79      7.26
Simple assume observe*         1      true     5.87 ns        9.13    1319.69        9.25      7.30
Smorgasbord                  201     false     5.36 μs       68.95     141.69        5.95      8.27
Smorgasbord                  201      true     6.51 μs       73.22     162.30        6.09      5.68
Loop univariate 1k          1000     false     17.0 μs      782.22     316.58        3.00      7.08
Loop univariate 1k          1000      true     18.6 μs     1306.64     290.34        2.84      6.44
Multivariate 1k             1000     false    960.0 ns     1492.18    1027.98        1.86     10.15
Multivariate 1k             1000      true    989.0 ns     1493.85     772.10        1.44     11.54
Loop univariate 10k        10000     false    164.0 μs    22515.10     357.86        3.09      7.12
Loop univariate 10k        10000      true    181.0 μs    24195.48     321.62        2.82      6.48
Multivariate 10k           10000     false     9.45 μs    26765.30    1029.06        1.71      7.69
Multivariate 10k           10000      true     8.88 μs    25958.58    1090.40        1.69      8.39
Dynamic                       15     false     1.33 μs         err      72.30       15.13       err
Dynamic                       10      true     1.71 μs        1.82      59.96       18.28       err
Submodel*                      1     false     5.87 ns        9.44    1262.10        9.55      7.40
Submodel*                      1      true     5.57 ns        9.14    1269.99        9.61      7.73
LDA                            6      true     4.04 μs        1.34       8.93       30.08     30.30
===================================================================================================
Main @ 7a7da38
===================================================================================================
                                               eval                       gradient                 
                                            ----------  -------------------------------------------
Model                        dim    linked      primal     FwdDiff    RvsDiff    Mooncake    Enzyme
---------------------------------------------------------------------------------------------------
Simple assume observe*         1     false     5.56 ns        9.01    1214.69        9.84      7.70
Simple assume observe*         1      true     5.87 ns        9.06    1310.52        9.56      7.26
Smorgasbord                  201     false     5.34 μs       70.46     143.64        5.90      8.43
Smorgasbord                  201      true     6.51 μs       74.79     173.39        6.07      5.81
Loop univariate 1k          1000     false     17.0 μs      769.91     316.91        3.03      6.78
Loop univariate 1k          1000      true     18.5 μs     1209.15     274.03        2.84      6.54
Multivariate 1k             1000     false    925.0 ns     1278.99    1086.08        2.18      7.74
Multivariate 1k             1000      true    997.0 ns     1297.20     755.69        2.01     11.72
Loop univariate 10k        10000     false    164.0 μs    21559.86     352.39        3.05      7.19
Loop univariate 10k        10000      true    180.0 μs    23671.47     317.72        2.84      6.50
Multivariate 10k           10000     false     8.79 μs    27912.77    1057.18        1.61      8.27
Multivariate 10k           10000      true      8.6 μs    28264.58    1104.59        1.71      8.47
Dynamic                       15     false     1.33 μs         err      58.18       13.85       err
Dynamic                       10      true     1.73 μs        1.79      58.61       12.36       err
Submodel*                      1     false     5.87 ns        9.44    1264.72        9.37      7.31
Submodel*                      1      true     5.57 ns        8.92    1315.90        9.74      7.67
LDA                            6      true     3.99 μs        1.30       9.24       26.98     30.75
===================================================================================================
Environment
Julia Version 1.13.0
Commit d1c37793dd2 (2026-09-09 19:00 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-20.1.8 (ORCJIT, znver3)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 4 virtual cores)

Comment thread HISTORY.md Outdated

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

Should the Chains default for include_all flip to true to match this PR and FlexiChains, so the same call stops keeping supplied parameters for one chain type and dropping them for the other?

@yebai

yebai commented Sep 20, 2026

Copy link
Copy Markdown
Member Author

Thanks, @shravanngoswamii.

Both should be fixed. I think include_all=false makes sense: the supplied parameters are already available in the input chain. I’ve aligned SamplingOutput with the existing Chains default.

@yebai
yebai merged commit 13dd27f into main Sep 21, 2026
24 checks passed
@yebai
yebai deleted the samplingoutput branch September 21, 2026 08:46
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.

2 participants