Skip to content

varnamedtuple: tuple nodes and partial-array storage - #1539

Merged
yebai merged 1 commit into
mainfrom
vnt-tuples
Nov 18, 2026
Merged

yebai merged 1 commit into
mainfrom
vnt-tuples

Conversation

@yebai

@yebai yebai commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Split of #1529 (part 1 of 12). Part 4 stores condition and fix values in a VarNamedTuple keyed by address, such as x[1] => v, and copies and merges these tables whenever bindings change. This PR adds the storage that requires:

  • Tuple nodes, so a tuple argument can hold per-element values. For x = (0.0, 0.0); x[1] ~ Normal(); x[2] ~ Normal(), rand(model) records both elements instead of throwing, and fix(model; x=(1.0, 2.0)) now takes effect. Mixed-type tuple values such as (1.0, 2) throw an ArgumentError, as does indexing into one stored in a VarNamedTuple (main returned the element).
  • Partial arrays that keep their unassigned entries when widened, copied and merged, so a stored binding neither gains nor loses entries. Widening non-Array storage with unassigned elements, such as an OffsetArray of vectors, no longer throws an UndefRefError.

Independently of bindings, Boolean-mask and empty integer-vector indices work without a template (they threw a BoundsError and an ArgumentError), and templated_setindex!! accepts another VarNamedTuple's storage as a template.

Tests are in test/varnamedtuple.jl, with the model-level tuple checks in test/compiler.jl; HISTORY records each change.

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.18310% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.07%. Comparing base (bba6eaa) to head (380fe52).

Files with missing lines Patch % Lines
src/varnamedtuple/getset.jl 97.36% 1 Missing ⚠️
src/varnamedtuple/partial_array.jl 96.87% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1539      +/-   ##
==========================================
+ Coverage   84.84%   85.07%   +0.22%     
==========================================
  Files          52       52              
  Lines        4626     4663      +37     
==========================================
+ Hits         3925     3967      +42     
+ Misses        701      696       -5     

☔ 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 #1539 is available at:
https://TuringLang.github.io/DynamicPPL.jl/previews/PR1539/

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Benchmarks

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.

Primal times: main bba6eaa, PR 380fe52

=================================================================================================================================
                                                                      primal                            gradient                 
                                                             -----------------------  -------------------------------------------
Model                                         dim    linked         main          PR     FwdDiff    RvsDiff    Mooncake    Enzyme
---------------------------------------------------------------------------------------------------------------------------------
Simple assume observe*                          1     false      5.25 ns     5.37 ns       10.36    1290.33       10.46      9.62
Simple assume observe*                          1      true      5.25 ns     5.38 ns       10.51    1321.33       10.89      8.57
Smorgasbord                                   201     false      5.45 μs     5.32 μs       89.48     139.38        5.53      1.31
Smorgasbord                                   201      true      6.53 μs     6.31 μs       83.16     169.74        5.71      1.45
Smorgasbord fixed                             100     false      2.62 μs     2.76 μs       48.31     156.79        6.50      1.30
Smorgasbord fixed                             100      true      3.04 μs     3.13 μs       64.05     180.69        6.68      1.51
NamedTuple-field LHS variable*                  1     false      5.25 ns     5.37 ns       10.46    1447.36       10.99      8.83
NamedTuple-field LHS variable*                  1      true      5.26 ns     5.38 ns       10.55    1410.21       10.64      9.66
MvNormal argument-supplied observation*         1     false      75.3 ns     86.1 ns        2.15     579.58        3.05      2.27
MvNormal argument-supplied observation*         1      true      73.5 ns     82.3 ns        2.18     634.57        3.05      2.21
Loop univariate 1k                           1000     false      17.0 μs     15.7 μs     1041.18     350.14        3.56      0.92
Loop univariate 1k                           1000      true      18.3 μs     18.2 μs     1432.66     299.79        3.12      0.79
Multivariate 1k                              1000     false    1000.0 ns     1.11 μs     1068.19     631.50        1.79      3.05
Multivariate 1k                              1000      true      1.08 μs     1.18 μs     1315.04     537.36        1.86      2.71
Loop univariate 10k                         10000     false     165.0 μs    152.0 μs    16056.34     418.89        3.63      0.81
Loop univariate 10k                         10000      true     177.0 μs    176.0 μs    15490.92     371.41        3.16      0.70
Multivariate 10k                            10000     false      10.4 μs      9.9 μs    18849.41     764.19        1.47      2.93
Multivariate 10k                            10000      true      9.69 μs     9.94 μs    24500.88     772.25        1.66      2.82
Dynamic                                       err     false      1.41 μs     1.41 μs         err      44.61       17.96      4.83
Dynamic                                        10      true      1.87 μs      1.9 μs        1.68      61.64       12.93      7.23
Submodel*                                       1     false      5.26 ns      5.4 ns       10.64    1487.13       11.07      9.86
Submodel*                                       1      true      5.26 ns     5.42 ns       10.56    1424.75       10.74      9.92
LDA                                             6      true      3.67 μs      4.1 μs        1.58      10.13       32.87     34.15
=================================================================================================================================
Environment
Julia Version 1.13.4
Commit c1ac32ab733 (2026-11-13 17:30 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 4 × AMD EPYC 9V74 80-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-20.1.8 (ORCJIT, znver4)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 4 virtual cores)

@yebai
yebai force-pushed the vnt-tuples branch 2 times, most recently from c2ff02a to e688d90 Compare November 18, 2026 10:13

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

Look good to me, thanks!

Retain unassigned storage when widening,
copying and merging partial values. Accept same-type tuple templates.
Boolean-mask and empty integer-vector indices work without a template;
they threw a `BoundsError` and an `ArgumentError`.

Assisted-by: Claude Code <noreply@anthropic.com>
@yebai
yebai added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit fd8f8a6 Nov 18, 2026
23 checks passed
@yebai
yebai deleted the vnt-tuples branch November 18, 2026 22:34
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