Skip to content

Use the inner Product constructor in arraydist#1441

Draft
shravanngoswamii wants to merge 1 commit into
mainfrom
sg/arraydist-inner-product-ctor
Draft

Use the inner Product constructor in arraydist#1441
shravanngoswamii wants to merge 1 commit into
mainfrom
sg/arraydist-inner-product-ctor

Conversation

@shravanngoswamii

@shravanngoswamii shravanngoswamii commented Jul 26, 2026

Copy link
Copy Markdown
Member

arraydist on a vector of univariate distributions returns Product(dists). That outer constructor is deprecated, so it calls Base.depwarn, which walks a backtrace on every call. Models with an arraydist likelihood pay it once per evaluation, and tests run with --depwarn=yes by default.

#1305 was meant to be a no-op when it moved these definitions in, but the DistributionsAD version used the inner constructor exactly to avoid this (dc92604, "Avoid changing return type"). This puts that back, so the return type is unchanged and the warning goes away. Keeping this method separate from the generic one still makes sense: product_distribution gives DiagNormal for a vector of Normals, and Product is faster there, 345 ns and 2 allocations against 582 ns and 8, at n = 100.

It does keep a deprecated type alive though. Product is due to be removed from Distributions, and DistributionsAD is archived now, so there is no upstream to follow. If you would rather drop arraydist altogether (DistributionsAD#274) or take the DiagNormal change instead, I can close this.

Switching the likelihoods away from arraydist in TuringGLM took its lts CI job from 88 minutes to 8, see TuringLang/TuringGLM.jl#195.

@shravanngoswamii
shravanngoswamii marked this pull request as draft July 26, 2026 07:42
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.70%. Comparing base (8415f12) to head (0adc101).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1441      +/-   ##
==========================================
+ Coverage   81.63%   81.70%   +0.07%     
==========================================
  Files          50       50              
  Lines        3578     3581       +3     
==========================================
+ Hits         2921     2926       +5     
+ Misses        657      655       -2     

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

@github-actions

Copy link
Copy Markdown
Contributor

Benchmarks @ 0adc101

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     4.63 ns       12.49    1557.12       40.01     12.34
Simple assume observe*         1      true     4.63 ns       12.55    1721.50       39.61     12.33
Smorgasbord                  201     false     6.02 μs       71.40     137.53        7.03      9.85
Smorgasbord                  201      true     7.68 μs       74.40     142.18        6.35      6.99
Loop univariate 1k          1000     false     17.8 μs      979.41     308.24        8.18      6.83
Loop univariate 1k          1000      true     19.1 μs     1432.76     290.23        7.97      6.24
Multivariate 1k             1000     false     22.2 μs      396.27      80.02        8.94      3.17
Multivariate 1k             1000      true     28.3 μs      330.90      57.74        8.39      3.35
Loop univariate 10k        10000     false    174.0 μs    12854.66     344.18        8.41      6.77
Loop univariate 10k        10000      true    186.0 μs    12871.97     327.95        7.81      6.35
Multivariate 10k           10000     false    197.0 μs     6093.73      92.37       11.71      2.36
Multivariate 10k           10000      true    198.0 μs     6023.74      92.51       11.63      2.31
Dynamic                       15     false     1.43 μs         err      45.40       15.90     12.22
Dynamic                       10      true     2.07 μs        1.96      56.25       21.13     20.13
Submodel*                      1     false     4.64 ns       12.52    1850.65       40.98     12.38
Submodel*                      1      true     4.63 ns       12.64    1981.77       41.01     12.37
LDA                           12      true     26.6 μs        0.61       1.96       29.92       err
===================================================================================================
Main @ 8415f12
===================================================================================================
                                               eval                       gradient                 
                                            ----------  -------------------------------------------
Model                        dim    linked      primal     FwdDiff    RvsDiff    Mooncake    Enzyme
---------------------------------------------------------------------------------------------------
Simple assume observe*         1     false     4.63 ns       12.85    1481.93       39.95     12.33
Simple assume observe*         1      true     4.63 ns       12.47    1688.49       39.76     12.25
Smorgasbord                  201     false     5.99 μs       71.74     138.65        6.96      9.92
Smorgasbord                  201      true     7.63 μs       73.76     142.76        6.36      7.11
Loop univariate 1k          1000     false     17.8 μs      993.00     301.74        8.08      6.46
Loop univariate 1k          1000      true     19.3 μs     1433.23     280.55        7.53      6.15
Multivariate 1k             1000     false     21.9 μs      358.54      80.17        9.15      3.24
Multivariate 1k             1000      true     26.9 μs      292.41      62.01        8.42      3.01
Loop univariate 10k        10000     false    174.0 μs    12299.49     332.79        8.42      6.46
Loop univariate 10k        10000      true    188.0 μs    12397.04     305.57        7.77      6.07
Multivariate 10k           10000     false    196.0 μs     5175.00      90.89       11.22      2.39
Multivariate 10k           10000      true    196.0 μs     4997.48      90.69       11.78      2.47
Dynamic                       15     false     1.42 μs         err      42.38       16.10     12.38
Dynamic                       10      true     1.94 μs        2.16      64.08       24.11     22.81
Submodel*                      1     false     4.63 ns       12.53    1695.66       40.12     12.35
Submodel*                      1      true     4.63 ns       12.56    1818.51       40.50     12.36
LDA                           12      true     23.3 μs        0.46       2.25       23.30       err
===================================================================================================
Environment
Julia Version 1.11.9
Commit 53a02c0720c (2026-02-06 00:27 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-16.0.6 (ORCJIT, znver3)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)

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