Skip to content

Conversation

@penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Jan 5, 2026

Closes #1090
Closes #796

This PR documents matchingvalue, etc. and adds unit tests. It also renames the functions for clarity.

It also fixes the behaviour in some edge cases, for example,

@model function f(::Type{T}=Vector{Real}) where {T}
    x ~ Normal()
end
f()

When running this with ForwardDiff AD, previously T would be promoted to Vector{Dual{Float64}}, which was over-aggressively concrete. Now it is promoted to Vector{Dual{Real}}.

This is accomplished by using Base.promote_type rather than float_type_with_fallback which is responsible for casting to Float64.

Now, float_type_with_fallback's only use is to generate the logp type in accumulators. It should also be renamed and tidied up (one could argue that it should be part of the accumulator API), but that's for a future PR.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2026

Benchmark Report

  • this PR's head: d0047d8071a4d033f7b1a01738cad7e5d5587062
  • base branch: a21b21de849fc17b245416e370da4fa805deeecf

Computer Information

Julia Version 1.11.8
Commit cf1da5e20e3 (2025-11-06 17:49 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)      │        t(grad) / t(ref)         │
│                       │       │             │                   │        │ ──────────┬──────────┬──────── │ ───────┬─────────┬──────── │ ──────────┬───────────┬──────── │
│                 Model │   Dim │  AD Backend │           VarInfo │ Linked │      base │  this PR │ speedup │   base │ this PR │ speedup │      base │   this PR │ speedup │
├───────────────────────┼───────┼─────────────┼───────────────────┼────────┼───────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│               Dynamic │    10 │    mooncake │             typed │   true │    380.10 │   343.35 │    1.11 │   9.57 │   10.04 │    0.95 │   3637.82 │   3447.13 │    1.06 │
│                   LDA │    12 │ reversediff │             typed │   true │   2701.85 │  2422.49 │    1.12 │   5.06 │    4.95 │    1.02 │  13678.62 │  11995.56 │    1.14 │
│   Loop univariate 10k │ 10000 │    mooncake │             typed │   true │ 102923.50 │ 97499.10 │    1.06 │   3.82 │    4.05 │    0.94 │ 393316.78 │ 394611.79 │    1.00 │
├───────────────────────┼───────┼─────────────┼───────────────────┼────────┼───────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│    Loop univariate 1k │  1000 │    mooncake │             typed │   true │   8032.67 │  7318.39 │    1.10 │   4.58 │    4.62 │    0.99 │  36750.49 │  33829.62 │    1.09 │
│      Multivariate 10k │ 10000 │    mooncake │             typed │   true │  32101.45 │ 30203.21 │    1.06 │  10.16 │   10.20 │    1.00 │ 326084.02 │ 307960.16 │    1.06 │
│       Multivariate 1k │  1000 │    mooncake │             typed │   true │   3582.34 │  3353.36 │    1.07 │   9.52 │   12.83 │    0.74 │  34108.87 │  43020.55 │    0.79 │
├───────────────────────┼───────┼─────────────┼───────────────────┼────────┼───────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│ Simple assume observe │     1 │ forwarddiff │             typed │  false │      2.70 │     2.47 │    1.10 │   3.92 │    3.96 │    0.99 │     10.59 │      9.76 │    1.09 │
│           Smorgasbord │   201 │ forwarddiff │             typed │  false │   1223.73 │  1124.77 │    1.09 │ 125.25 │  126.79 │    0.99 │ 153275.55 │ 142612.45 │    1.07 │
│           Smorgasbord │   201 │ forwarddiff │       simple_dict │   true │       err │      err │     err │    err │     err │     err │       err │       err │     err │
├───────────────────────┼───────┼─────────────┼───────────────────┼────────┼───────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│           Smorgasbord │   201 │ forwarddiff │ simple_namedtuple │   true │       err │      err │     err │    err │     err │     err │       err │       err │     err │
│           Smorgasbord │   201 │      enzyme │             typed │   true │   1676.33 │  1533.11 │    1.09 │   6.13 │    6.82 │    0.90 │  10281.63 │  10459.62 │    0.98 │
│           Smorgasbord │   201 │    mooncake │             typed │   true │   1661.31 │  1529.49 │    1.09 │   5.31 │    5.30 │    1.00 │   8818.16 │   8106.02 │    1.09 │
├───────────────────────┼───────┼─────────────┼───────────────────┼────────┼───────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│           Smorgasbord │   201 │ reversediff │             typed │   true │   1691.42 │  1530.29 │    1.11 │  91.02 │   93.63 │    0.97 │ 153953.86 │ 143274.24 │    1.07 │
│           Smorgasbord │   201 │ forwarddiff │      typed_vector │   true │   1669.29 │  1538.26 │    1.09 │  58.58 │   57.32 │    1.02 │  97787.50 │  88173.06 │    1.11 │
│           Smorgasbord │   201 │ forwarddiff │           untyped │   true │   1685.10 │  1534.64 │    1.10 │  59.31 │   58.75 │    1.01 │  99947.86 │  90156.63 │    1.11 │
├───────────────────────┼───────┼─────────────┼───────────────────┼────────┼───────────┼──────────┼─────────┼────────┼─────────┼─────────┼───────────┼───────────┼─────────┤
│           Smorgasbord │   201 │ forwarddiff │    untyped_vector │   true │   1674.03 │  1544.94 │    1.08 │  57.36 │   59.19 │    0.97 │  96022.58 │  91445.70 │    1.05 │
│              Submodel │     1 │    mooncake │             typed │   true │      7.07 │     6.96 │    1.02 │   5.44 │    5.00 │    1.09 │     38.41 │     34.79 │    1.10 │
└───────────────────────┴───────┴─────────────┴───────────────────┴────────┴───────────┴──────────┴─────────┴────────┴─────────┴─────────┴───────────┴───────────┴─────────┘

@penelopeysm penelopeysm force-pushed the py/floattype branch 2 times, most recently from 7145038 to 82e9e2e Compare January 5, 2026 14:43
@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2026

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

@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

❌ Patch coverage is 94.59459% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.99%. Comparing base (a21b21d) to head (d0047d8).

Files with missing lines Patch % Lines
src/compiler.jl 90.90% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1190      +/-   ##
==========================================
+ Coverage   78.91%   78.99%   +0.08%     
==========================================
  Files          41       41              
  Lines        3927     3938      +11     
==========================================
+ Hits         3099     3111      +12     
+ Misses        828      827       -1     

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

Copy link
Member

@mhauru mhauru left a comment

Choose a reason for hiding this comment

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

LGTM

@penelopeysm penelopeysm merged commit 47f6b7e into main Jan 7, 2026
@penelopeysm penelopeysm deleted the py/floattype branch January 7, 2026 19:33
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.

Decouple usage of float_type_with_fallback Document and move matchingvalue

3 participants