Skip to content

model: unify conditioned, fixed, and argument bindings - #1501

Open
yebai wants to merge 3 commits into
tracesfrom
bindings
Open

yebai wants to merge 3 commits into
tracesfrom
bindings

Conversation

@yebai

@yebai yebai commented Sep 16, 2026

Copy link
Copy Markdown
Member

This replaces CondFixContext with model bindings that store each value together with its conditioned or fixed role. Later bindings replace earlier ones at the same address, and parent bindings override child bindings. For a model containing x ~ Normal(), condition(fix(m; x=1); x=2) observes x=2 and includes its likelihood. Model arguments provide default observations; decondition(m, :x) makes x latent. missing no longer marks latent sites. Submodel bindings address internal variables rather than return values.

Closes #1012; closes #958; closes #1464; closes #1246.

@yebai
yebai added this pull request to stack #1505 September 16, 2026 21:16
@yebai
yebai requested a balanced review from Copilot September 16, 2026 21:18
@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.40268% with 87 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.55%. Comparing base (8e7f466) to head (f7f79bf).

Files with missing lines Patch % Lines
src/model.jl 85.74% 62 Missing ⚠️
src/compiler.jl 76.38% 17 Missing ⚠️
src/varnamedtuple/getset.jl 82.60% 4 Missing ⚠️
src/submodel.jl 91.89% 3 Missing ⚠️
src/contexts/prefix.jl 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           traces    #1501      +/-   ##
==========================================
- Coverage   83.79%   82.55%   -1.24%     
==========================================
  Files          53       51       -2     
  Lines        4590     4889     +299     
==========================================
+ Hits         3846     4036     +190     
- Misses        744      853     +109     

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

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.

🟡 Changes recommended

The no-prefix submodel path can silently ignore an argument binding, and the documented context access emits an internal-variable warning.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Unifies model arguments, conditioned values, and fixed values as role-tagged model bindings, replacing CondFixContext and missing-based latent selection.

Changes:

  • Implements binding precedence, partial overrides, deconditioning, and unfixing.
  • Updates compiler, prefix, submodel, and VarNamedTuple handling.
  • Migrates extensions, documentation, and regression tests.
File summaries
File Description
HISTORY.md Documents binding semantics.
docs/src/api.md Updates prediction and context APIs.
docs/src/conditionfix.md Documents explicit bindings.
docs/src/evaluation.md Explains evaluation data flow.
docs/src/onboarding.md Updates contributor guidance.
docs/src/tilde.md Revises tilde lowering documentation.
ext/DynamicPPLComponentArraysExt.jl Supports component-backed bindings.
ext/DynamicPPLInputProvenanceExt.jl Traces model-bound inputs.
ext/DynamicPPLMCMCChainsExt.jl Handles absent chain values.
src/DynamicPPL.jl Removes obsolete includes.
src/compiler.jl Generates role-aware model evaluation.
src/contexts.jl Updates context examples.
src/contexts/conditionfix.jl Removes CondFixContext.
src/contexts/init.jl Rejects missing parameters.
src/contexts/prefix.jl Adds prefix templates.
src/debug_utils.jl Adapts model diagnostics.
src/model.jl Implements unified model bindings.
src/submodel.jl Merges parent and child bindings.
src/subsample.jl Accepts argument observations.
src/varname.jl Removes obsolete argument helpers.
src/varnamedtuple.jl Adds nested templates.
src/varnamedtuple/getset.jl Handles nested template indexing.
src/varnamedtuple/partial_array.jl Adds indexed-value preparation.
src/varnamedtuple/vnt.jl Refines lookup and documentation.
test/compiler.jl Tests new lowering behavior.
test/conditionfix.jl Expands binding regression coverage.
test/context_implementations.jl Tests evaluation separation.
test/contexts.jl Removes obsolete context tests.
test/contexts/init.jl Tests missing-value rejection.
test/debug_utils.jl Updates diagnostic tests.
test/ext/DynamicPPLInputProvenanceExt.jl Tests bound-input provenance.
test/model.jl Migrates model behavior tests.
test/runtests.jl Removes deleted test suite.
test/submodels.jl Tests nested binding behavior.
test/subsample.jl Updates observation tests.
test/utils.jl Revises transformation tests.
test/varnamedtuple.jl Tests nested templates and equality.
Review details
  • Files reviewed: 37/37 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/submodel.jl
Comment thread docs/src/evaluation.md
Assisted-by: Codex <codex@openai.com>
Assisted-by: Codex <codex@openai.com>
Assisted-by: Codex <codex@openai.com>
@github-actions

Copy link
Copy Markdown
Contributor

Benchmarks @ f7f79bf

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     6.23 ns        8.97    1142.26        9.44      6.70
Simple assume observe*         1      true      6.5 ns        7.93    1210.32        8.65      6.67
Smorgasbord                  201     false     5.37 μs       72.83     145.74        6.22      8.58
Smorgasbord                  201      true     6.57 μs       76.03     177.06        6.14      6.90
Loop univariate 1k          1000     false     17.5 μs      769.80     317.06        2.96      6.78
Loop univariate 1k          1000      true     19.3 μs     1277.16     291.22        2.68      6.53
Multivariate 1k             1000     false     1.28 μs     1269.65     756.82        2.03      6.78
Multivariate 1k             1000      true     1.19 μs     1445.24     849.99        1.66      7.97
Loop univariate 10k        10000     false    168.0 μs    19513.49     361.87        3.04      7.12
Loop univariate 10k        10000      true    180.0 μs    26587.88     331.56        2.64      6.60
Multivariate 10k           10000     false     9.91 μs    26058.25     964.62        1.80      7.77
Multivariate 10k           10000      true     9.69 μs    26688.46     987.48        1.82      7.79
Dynamic                      err     false     1.35 μs         err      50.81       14.34       err
Dynamic                       10      true     1.78 μs        1.77      59.16       13.04       err
Submodel*                      1     false     5.88 ns        7.46    1201.93       15.75      7.28
Submodel*                      1      true     6.06 ns        6.93    1082.79        9.79      7.14
LDA                            6      true     4.07 μs        1.35       9.20       32.16     30.66
===================================================================================================
Main @ 7a7da38
===================================================================================================
                                               eval                       gradient                 
                                            ----------  -------------------------------------------
Model                        dim    linked      primal     FwdDiff    RvsDiff    Mooncake    Enzyme
---------------------------------------------------------------------------------------------------
Simple assume observe*         1     false     3.57 ns       10.31    1416.79       11.02      9.54
Simple assume observe*         1      true     3.56 ns        9.48    1598.13       10.66      9.47
Smorgasbord                  201     false     3.57 μs       71.29     141.47        7.47     12.55
Smorgasbord                  201      true     4.43 μs       64.72     158.03        7.38      8.10
Loop univariate 1k          1000     false     9.44 μs     1267.54     362.81        4.37      9.08
Loop univariate 1k          1000      true     12.5 μs     1529.58     234.54        3.09      7.33
Multivariate 1k             1000     false     1.11 μs      931.77     564.02        1.95      8.44
Multivariate 1k             1000      true     1.07 μs      846.86     473.82        1.78     10.05
Loop univariate 10k        10000     false     87.6 μs    32650.27     438.30        4.47      9.82
Loop univariate 10k        10000      true    121.0 μs    26409.57     300.94        3.27      7.26
Multivariate 10k           10000     false     11.7 μs    23551.51     531.85        1.63      5.68
Multivariate 10k           10000      true     12.1 μs    21031.79     477.12        1.66      5.51
Dynamic                       15     false    980.0 ns         err      95.67       17.36     21.19
Dynamic                       10      true     1.31 μs        2.22      83.63       15.61     34.64
Submodel*                      1     false     3.45 ns        9.28    1509.25       12.51     11.92
Submodel*                      1      true     3.69 ns       10.90    1673.07       12.10      8.39
LDA                            6      true     3.05 μs        1.35      14.27       43.32     44.88
===================================================================================================
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)

@github-actions

Copy link
Copy Markdown
Contributor

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

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

2 participants