Skip to content

Conversation

penelopeysm
Copy link
Member

Transferred from TuringLang/Turing.jl#2664.

Copy link
Contributor

github-actions bot commented Sep 5, 2025

Benchmark Report for Commit aaca138

Computer Information

Julia Version 1.11.6
Commit 9615af0f269 (2025-07-09 12:58 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

|                 Model | Dimension |  AD Backend |      VarInfo Type | Linked | Eval Time / Ref Time | AD Time / Eval Time |
|-----------------------|-----------|-------------|-------------------|--------|----------------------|---------------------|
| Simple assume observe |         1 | forwarddiff |             typed |  false |                  9.1 |                 1.5 |
|           Smorgasbord |       201 | forwarddiff |             typed |  false |                643.9 |                43.0 |
|           Smorgasbord |       201 | forwarddiff | simple_namedtuple |   true |                422.7 |                53.4 |
|           Smorgasbord |       201 | forwarddiff |           untyped |   true |               1176.6 |                29.0 |
|           Smorgasbord |       201 | forwarddiff |       simple_dict |   true |               6523.5 |                29.5 |
|           Smorgasbord |       201 | reversediff |             typed |   true |               1035.8 |                39.9 |
|           Smorgasbord |       201 |    mooncake |             typed |   true |               1018.6 |                 4.5 |
|    Loop univariate 1k |      1000 |    mooncake |             typed |   true |               5753.2 |                 4.3 |
|       Multivariate 1k |      1000 |    mooncake |             typed |   true |                987.4 |                 8.9 |
|   Loop univariate 10k |     10000 |    mooncake |             typed |   true |              65784.7 |                 3.9 |
|      Multivariate 10k |     10000 |    mooncake |             typed |   true |               8536.0 |                10.1 |
|               Dynamic |        10 |    mooncake |             typed |   true |                133.4 |                11.8 |
|              Submodel |         1 |    mooncake |             typed |   true |                 13.1 |                 5.0 |
|                   LDA |        12 | reversediff |             typed |   true |               1245.1 |                 2.0 |

Copy link

codecov bot commented Sep 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.39%. Comparing base (7249158) to head (aaca138).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1036      +/-   ##
==========================================
+ Coverage   82.34%   82.39%   +0.04%     
==========================================
  Files          38       39       +1     
  Lines        3949     3960      +11     
==========================================
+ Hits         3252     3263      +11     
  Misses        697      697              

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

@coveralls
Copy link

coveralls commented Sep 5, 2025

Pull Request Test Coverage Report for Build 17500096701

Details

  • 0 of 11 (0.0%) changed or added relevant lines in 1 file are covered.
  • 27 unchanged lines in 6 files lost coverage.
  • Overall coverage increased (+0.05%) to 82.649%

Changes Missing Coverage Covered Lines Changed/Added Lines %
ext/DynamicPPLMarginalLogDensitiesExt.jl 0 11 0.0%
Files with Coverage Reduction New Missed Lines %
src/model.jl 1 86.73%
src/debug_utils.jl 3 89.27%
src/extract_priors.jl 3 60.53%
src/pointwise_logdensities.jl 3 93.06%
src/values_as_in_model.jl 4 72.41%
src/threadsafe.jl 13 62.16%
Totals Coverage Status
Change from base Build 17494778045: 0.05%
Covered Lines: 3263
Relevant Lines: 3948

💛 - Coveralls

Copy link
Member Author

@penelopeysm penelopeysm left a comment

Choose a reason for hiding this comment

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

@ElOceanografo Here's the updated PR. I got rid of the double negative sign, and added some documentation. If you'd like to have push access to this let me know and I can add you!

# Determine the indices for the variables to marginalise out.
varinfo = DynamicPPL.typed_varinfo(model)
vns = map(_to_varname, varnames)
varindices = reduce(vcat, DynamicPPL.vector_getranges(varinfo, vns))
Copy link
Member Author

Choose a reason for hiding this comment

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

It seems to me that in principle MLD should be able to handle this case fine:

using DynamicPPL, Distributions, MarginalLogDensities, LinearAlgebra

@model function f()
    x ~ MvNormal([0.0, 1.0, 2.0], I)
end

marginalize(f(), [@varname(x[1])])

Unfortunately, attempting to do this now falls over:

ERROR: KeyError: key VarName{:x, Accessors.IndexLens{Tuple{Int64}}}[x[1]] not found
Stacktrace:
 [1] vector_getranges(varinfo::VarInfo{@NamedTuple{…}, DynamicPPL.AccumulatorTuple{…}}, vns::Vector{VarName{…}})
   @ DynamicPPL ~/ppl/dppl/src/varinfo.jl:732

This is definitely a limitation of using the internal vector_getranges function. I wonder if maybe we should explicitly allow the user to specify the indices that they want to remove?

Comment on lines +66 to +67
# Use linked `varinfo` to that we're working in unconstrained space
varinfo_linked = DynamicPPL.link(varinfo, model)
Copy link
Member Author

@penelopeysm penelopeysm Sep 5, 2025

Choose a reason for hiding this comment

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

Does MLD require a linked VarInfo, or would an unlinked VarInfo be fine?

The reason I'm thinking about this is because if the VarInfo is linked, then all the parameters that are later supplied must be in linked space, which is potentially a bit confusing (though nothing that can't be fixed by documentation). Example:

julia> using DynamicPPL, Distributions, Bijectors, MarginalLogDensities

julia> @model function f()
           x ~ Normal()
           y ~ Beta(2, 2)
       end
f (generic function with 2 methods)

julia> m = marginalize(f(), [@varname(x)]);

julia> m([0.5]) # this 0.5 is in linked space
0.3436055008678415

julia> logpdf(Beta(2, 2), 0.5) # this 0.5 is unlinked, so logp is wrong
0.4054651081081644

julia> inverse(Bijectors.bijector(Beta(2, 2)))(0.5) # this is the unlinked value corresponding to 0.5
0.6224593312018546

julia> logpdf(Beta(2, 2), 0.6224593312018546) # now logp matches
0.3436055008678416

If an unlinked VarInfo is acceptable, then the choice of varinfo should probably also be added as an argument to marginalize.

Copy link
Contributor

github-actions bot commented Sep 5, 2025

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

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