Skip to content

Conversation

@penelopeysm
Copy link
Member

Sort of along the lines of #1142.

I suspect that this small patch might provide most of the perf benefits.

Comment on lines -449 to -451
# UnivariateDistributions need to be handled as a special case, because size(dist) is (),
# which makes the usual machinery think we are dealing with a 0-dim array, whereas in
# actuality we are dealing with a scalar.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i mean isn't this just annoying, this is what i mean when i say bijectors is a pain to deal with

Copy link
Member Author

@penelopeysm penelopeysm Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also distributions to a lesser extent

size(dist) and Bijectors.output_size are not well-defined for things like LKJCholesky or ProductNamedTupleDistribution

that's fine because their use cases are (possibly) different, but dynamicppl has its own needs, and the correct solution is to have a clean api that generalises across all of these cases

@github-actions
Copy link
Contributor

github-actions bot commented Nov 18, 2025

Benchmark Report

  • this PR's head: a302b9d9ece3f21468ebda39c769f79789efe2bc
  • base branch: 052bc1950df3a42e14b56eae51af236881092f90

Computer Information

Julia Version 1.11.7
Commit f2b3dbda30a (2025-09-08 12:10 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)

Benchmark Results

┌───────────────────────┬───────┬─────────────┬───────────────────┬────────┬─────────────────────────────────┬────────────────────────────┐
│                       │       │             │                   │        │        t(eval) / t(ref)         │     t(grad) / t(eval)      │
│                       │       │             │                   │        │ ──────────┬───────────┬──────── │ ───────┬─────────┬──────── │
│                 Model │   Dim │  AD Backend │           VarInfo │ Linked │      base │   this PR │ speedup │   base │ this PR │ speedup │
├───────────────────────┼───────┼─────────────┼───────────────────┼────────┼───────────┼───────────┼─────────┼────────┼─────────┼─────────┤
│               Dynamic │    10 │    mooncake │             typed │   true │    398.57 │    435.63 │    0.91 │  11.64 │   10.36 │    1.12 │
│                   LDA │    12 │ reversediff │             typed │   true │   2761.55 │   2927.77 │    0.94 │   2.07 │    2.15 │    0.96 │
│   Loop univariate 10k │ 10000 │    mooncake │             typed │   true │ 151539.66 │ 127439.34 │    1.19 │   5.61 │    5.22 │    1.07 │
│    Loop univariate 1k │  1000 │    mooncake │             typed │   true │  15455.07 │  12951.41 │    1.19 │   5.12 │    5.75 │    0.89 │
│      Multivariate 10k │ 10000 │    mooncake │             typed │   true │  31126.99 │  32278.50 │    0.96 │   9.70 │    9.79 │    0.99 │
│       Multivariate 1k │  1000 │    mooncake │             typed │   true │   4217.05 │   3800.45 │    1.11 │   7.47 │    8.60 │    0.87 │
│ Simple assume observe │     1 │ forwarddiff │             typed │  false │     16.78 │     21.48 │    0.78 │   1.87 │    1.50 │    1.24 │
│           Smorgasbord │   201 │      enzyme │             typed │   true │   2544.57 │   3175.27 │    0.80 │   4.72 │    4.03 │    1.17 │
│           Smorgasbord │   201 │ forwarddiff │       simple_dict │   true │  23330.22 │  24952.11 │    0.93 │  24.52 │   24.78 │    0.99 │
│           Smorgasbord │   201 │ forwarddiff │ simple_namedtuple │   true │   1029.85 │   1073.88 │    0.96 │ 173.45 │   78.50 │    2.21 │
│           Smorgasbord │   201 │ forwarddiff │             typed │  false │   2520.19 │   2675.93 │    0.94 │  47.85 │   85.01 │    0.56 │
│           Smorgasbord │   201 │ forwarddiff │      typed_vector │   true │   2646.54 │   3131.72 │    0.85 │  44.60 │   40.51 │    1.10 │
│           Smorgasbord │   201 │ forwarddiff │           untyped │   true │   2229.92 │   2822.88 │    0.79 │  48.70 │   42.68 │    1.14 │
│           Smorgasbord │   201 │ forwarddiff │    untyped_vector │   true │   2284.56 │   2851.46 │    0.80 │  45.70 │   42.56 │    1.07 │
│           Smorgasbord │   201 │    mooncake │             typed │   true │   2549.02 │   3160.30 │    0.81 │   5.73 │    5.59 │    1.02 │
│           Smorgasbord │   201 │ reversediff │             typed │   true │   2656.72 │   3110.77 │    0.85 │  54.96 │   50.19 │    1.09 │
│              Submodel │     1 │    mooncake │             typed │   true │     24.96 │     26.31 │    0.95 │   5.42 │    5.48 │    0.99 │
└───────────────────────┴───────┴─────────────┴───────────────────┴────────┴───────────┴───────────┴─────────┴────────┴─────────┴─────────┘

@github-actions
Copy link
Contributor

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

@codecov
Copy link

codecov bot commented Nov 18, 2025

Codecov Report

❌ Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.47%. Comparing base (052bc19) to head (a302b9d).

Files with missing lines Patch % Lines
src/utils.jl 85.71% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1145       +/-   ##
===========================================
+ Coverage   37.18%   81.47%   +44.29%     
===========================================
  Files          40       40               
  Lines        3819     3839       +20     
===========================================
+ Hits         1420     3128     +1708     
+ Misses       2399      711     -1688     

☔ View full report in Codecov by Sentry.
📢 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.

@penelopeysm
Copy link
Member Author

What a shocker, it doesn't. Maybe it's only noticeable for FastLDF, which is what I ran the benchmarks in #1142 on. We can shelve this for now and come back to it later.

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