Skip to content

Use Threads.nthreads() * 2 in TSVI #936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented May 23, 2025

See #924 for background.

This PR adopts a similar approach to solution (1), i.e., using Threads.maxthreadid(). However, Mooncake can't differentiate maxthreadid(), so this is a hacky workaround to a hacky workaround, based on the observation that maxthreadid() is usually nthreads() * 2.

Personally, I would be much more in favour of removing TSVI (or making it opt-in), and will probably do this in a separate PR once TuringLang/Turing.jl#2555 is solved.

But this is a quick enough fix that should ensure that TSVI continues to work on Julia 1.12 (even if for the wrong reasons). Whether we merge this will probably depend on how fast that Turing issue can be fixed -- if it's soon, then we can remove TSVI, if it's not soon, then this can plug the gap.

Note that if TSVI is opt-in, then we can just use maxthreadid(), thereby removing one layer of hackiness — because Mooncake doesn't work with multithreaded execution anyway, the scenarios where you'd want to opt into TSVI have no overlap with the scenarios where you'd want to use Mooncake.

Copy link
Contributor

github-actions bot commented May 23, 2025

Benchmark Report for Commit 6b9b332

Computer Information

Julia Version 1.11.5
Commit 760b2e5b739 (2025-04-14 06:53 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.6 |                 1.6 |
|           Smorgasbord |       201 | forwarddiff |             typed |  false |                639.5 |                38.9 |
|           Smorgasbord |       201 | forwarddiff | simple_namedtuple |   true |                307.6 |                61.7 |
|           Smorgasbord |       201 | forwarddiff |           untyped |   true |               1225.7 |                26.5 |
|           Smorgasbord |       201 | forwarddiff |       simple_dict |   true |               3619.1 |                21.9 |
|           Smorgasbord |       201 | reversediff |             typed |   true |               1455.7 |                29.4 |
|           Smorgasbord |       201 |    mooncake |             typed |   true |                949.0 |                 5.2 |
|    Loop univariate 1k |      1000 |    mooncake |             typed |   true |               5482.8 |                 4.1 |
|       Multivariate 1k |      1000 |    mooncake |             typed |   true |               1023.5 |                 8.8 |
|   Loop univariate 10k |     10000 |    mooncake |             typed |   true |              62218.9 |                 3.7 |
|      Multivariate 10k |     10000 |    mooncake |             typed |   true |               8973.4 |                 9.8 |
|               Dynamic |        10 |    mooncake |             typed |   true |                138.8 |                12.0 |
|              Submodel |         1 |    mooncake |             typed |   true |                 13.8 |                 6.5 |
|                   LDA |        12 | reversediff |             typed |   true |                465.9 |                 6.2 |

Copy link

codecov bot commented May 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.91%. Comparing base (e350cd3) to head (6b9b332).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #936   +/-   ##
=======================================
  Coverage   82.91%   82.91%           
=======================================
  Files          36       36           
  Lines        3962     3962           
=======================================
  Hits         3285     3285           
  Misses        677      677           

☔ 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 May 23, 2025

Pull Request Test Coverage Report for Build 15216502921

Details

  • 3 of 3 (100.0%) changed or added relevant lines in 2 files are covered.
  • 58 unchanged lines in 5 files lost coverage.
  • Overall coverage remained the same at 83.08%

Files with Coverage Reduction New Missed Lines %
src/experimental.jl 3 0.0%
src/varinfo.jl 4 84.14%
src/logdensityfunction.jl 14 50.0%
ext/DynamicPPLJETExt.jl 16 0.0%
src/test_utils/ad.jl 21 0.0%
Totals Coverage Status
Change from base Build 15213861039: 0.0%
Covered Lines: 3285
Relevant Lines: 3954

💛 - Coveralls

1 similar comment
@coveralls
Copy link

coveralls commented May 23, 2025

Pull Request Test Coverage Report for Build 15216502921

Details

  • 3 of 3 (100.0%) changed or added relevant lines in 2 files are covered.
  • 58 unchanged lines in 5 files lost coverage.
  • Overall coverage remained the same at 83.08%

Files with Coverage Reduction New Missed Lines %
src/experimental.jl 3 0.0%
src/varinfo.jl 4 84.14%
src/logdensityfunction.jl 14 50.0%
ext/DynamicPPLJETExt.jl 16 0.0%
src/test_utils/ad.jl 21 0.0%
Totals Coverage Status
Change from base Build 15213861039: 0.0%
Covered Lines: 3285
Relevant Lines: 3954

💛 - Coveralls

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