Skip to content

Check the input length in logdensity - #1446

Merged
shravanngoswamii merged 2 commits into
mainfrom
sg/logdensity-dim-check
Aug 25, 2026
Merged

Check the input length in logdensity#1446
shravanngoswamii merged 2 commits into
mainfrom
sg/logdensity-dim-check

Conversation

@shravanngoswamii

@shravanngoswamii shravanngoswamii commented Aug 23, 2026

Copy link
Copy Markdown
Member

Fixes #1445.

LogDensityProblems.logdensity now checks the input length against ldf._dim and throws the same ArgumentError that the two-argument InitFromVector(vect, ldf) constructor already throws. Previously a shorter vector gave a BoundsError from inside model evaluation and a longer one silently returned the log density of the first dimension(ldf) elements.

ldf._dim is already stored, so the check costs nothing measurable. On a 21-dimensional model, logdensity takes 48.3 ns before and 48.2 ns after.

HISTORY.md also gains the missing entry for #1448, so the 0.42.5 section covers everything merged since 0.42.4. Project.toml is already at 0.42.5 on main.

@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.85%. Comparing base (e65fee2) to head (b5f3ffb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1446      +/-   ##
==========================================
+ Coverage   81.84%   81.85%   +0.01%     
==========================================
  Files          50       50              
  Lines        3581     3583       +2     
==========================================
+ Hits         2931     2933       +2     
  Misses        650      650              

☔ 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 force-pushed the sg/logdensity-dim-check branch from 39222c9 to d7a66c8 Compare August 23, 2026 19:38
@shravanngoswamii
shravanngoswamii changed the base branch from main to fix/issue-1407-logjac August 23, 2026 19:38
@github-actions

Copy link
Copy Markdown
Contributor

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

@shravanngoswamii
shravanngoswamii force-pushed the sg/logdensity-dim-check branch from d7a66c8 to 682d000 Compare August 23, 2026 19:43
@shravanngoswamii
shravanngoswamii changed the base branch from fix/issue-1407-logjac to main August 23, 2026 19:43
@github-actions

github-actions Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Benchmarks @ b5f3ffb

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.94 ns       12.26    1367.36       39.67     14.71
Simple assume observe*         1      true     5.05 ns       11.61    1493.81       38.99     15.71
Smorgasbord                  201     false     5.72 μs       75.10     140.81        7.18      7.61
Smorgasbord                  201      true     7.46 μs       72.26     142.43        6.35      5.57
Loop univariate 1k          1000     false     16.5 μs     1137.54     316.36       10.09      7.78
Loop univariate 1k          1000      true     19.7 μs     1037.78     269.67        8.08      6.63
Multivariate 1k             1000     false     23.9 μs      323.83      69.57        8.30      2.03
Multivariate 1k             1000      true     22.6 μs      278.14      74.24        9.74      2.12
Loop univariate 10k        10000     false    159.0 μs    15549.87     358.41        9.95      7.83
Loop univariate 10k        10000      true    194.0 μs    14276.55     303.14        8.28      6.60
Multivariate 10k           10000     false    213.0 μs     5824.32      80.37       10.18      1.91
Multivariate 10k           10000      true    214.0 μs     5685.59      83.33       10.28      1.93
Dynamic                       15     false     1.39 μs         err      44.44       14.57     11.28
Dynamic                       10      true     1.99 μs        1.90      59.57       11.17     18.00
Submodel*                      1     false     4.93 ns       12.62    1709.85       43.43     15.09
Submodel*                      1      true     4.93 ns       12.75    1729.48       39.08     16.79
LDA                           12      true     24.4 μs        0.64       2.04       28.43       err
===================================================================================================
Main @ e65fee2
===================================================================================================
                                               eval                       gradient                 
                                            ----------  -------------------------------------------
Model                        dim    linked      primal     FwdDiff    RvsDiff    Mooncake    Enzyme
---------------------------------------------------------------------------------------------------
Simple assume observe*         1     false     4.63 ns       12.77    1584.01       39.79     12.35
Simple assume observe*         1      true     4.63 ns       13.27    1742.87       40.20     12.14
Smorgasbord                  201     false     5.95 μs       69.69     135.12        6.95      9.65
Smorgasbord                  201      true     7.71 μs       67.83     144.32        6.22      7.02
Loop univariate 1k          1000     false     17.8 μs      996.73     314.24        8.57      6.80
Loop univariate 1k          1000      true     19.0 μs     1489.64     297.09        7.66      6.25
Multivariate 1k             1000     false     21.9 μs      371.25      81.24        8.92      2.90
Multivariate 1k             1000      true     29.4 μs      320.52      57.18        7.82      3.26
Loop univariate 10k        10000     false    174.0 μs    12383.01     347.33        8.43      6.78
Loop univariate 10k        10000      true    186.0 μs    12670.40     325.69        7.89      6.29
Multivariate 10k           10000     false    198.0 μs     5048.19      91.02       11.59      2.38
Multivariate 10k           10000      true    198.0 μs     5131.65      92.14       11.54      2.35
Dynamic                       15     false     1.43 μs         err      43.74       15.42     11.83
Dynamic                       10      true      2.0 μs        1.77      57.80       19.17     20.12
Submodel*                      1     false     4.64 ns       12.62    1787.35       40.14     12.64
Submodel*                      1      true     4.64 ns       12.66    1955.32       40.44     12.26
LDA                           12      true     24.2 μs        0.62       2.23       30.92       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 9V74 80-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver4)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)

@shravanngoswamii
shravanngoswamii requested a review from yebai August 23, 2026 21:52

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

looks fine

@shravanngoswamii
shravanngoswamii force-pushed the sg/logdensity-dim-check branch from 682d000 to e14fd43 Compare August 25, 2026 10:07
A shorter vector gave a BoundsError from inside model evaluation and a longer one
silently returned the density of the first `dimension(ldf)` elements.
@shravanngoswamii
shravanngoswamii force-pushed the sg/logdensity-dim-check branch from e14fd43 to b5f3ffb Compare August 25, 2026 15:07
@shravanngoswamii
shravanngoswamii added this pull request to the merge queue Aug 25, 2026
Merged via the queue into main with commit 66a5b73 Aug 25, 2026
24 checks passed
@shravanngoswamii
shravanngoswamii deleted the sg/logdensity-dim-check branch August 25, 2026 16:02
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.

logdensity silently accepts an over-long parameter vector

2 participants