Skip to content

InitContext, part 5 - Remove SamplingContext, SampleFrom{Prior,Uniform}, {tilde_,}assume #985

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 19 commits into
base: py/actually-use-init
Choose a base branch
from

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Jul 10, 2025

Part 1: Adding hasvalue and getvalue to AbstractPPL
Part 2: Removing hasvalue and getvalue from DynamicPPL
Part 3: Introducing InitContext and init!!
Part 4: Using InitFromParams to implement predict, returned, and initialize_values

This is part 5/N of #967.

This PR removes everything that is no longer needed. SamplingContext, SampleFromPrior, SampleFromUniform, now have direct one-to-one replacements (albeit with slightly different behaviour since they now always overwrite variables in the varinfo).

It also removes assume and tilde_assume.

Prior to this PR we had two different kinds of assume, one with a sampler and one without. Now we only have the one without, so we can just move that definition into tilde_assume!!(::DefaultContext, ...).

Finally, tilde_assume has been subsumed into tilde_assume!! as we can just dispatch on the type of right. (Previously this wasn't possible because there was a lot of stuff about is_rhs_model, etc. etc. which was removed in #960.)

Closes #859
Closes #955

@penelopeysm penelopeysm changed the base branch from main to py/actually-use-init July 10, 2025 17:00
@penelopeysm penelopeysm force-pushed the py/remove-samplingcontext branch 2 times, most recently from c32d112 to b7221cc Compare July 10, 2025 17:16
@penelopeysm penelopeysm changed the title InitContext, part 5 - Remove SamplingContext, SampleFromPrior, SampleFromUniform, and associated code InitContext, part 5 - Remove SamplingContext, SampleFrom{Prior,Uniform}, {tilde_,}assume Jul 10, 2025
This was referenced Jul 10, 2025
@penelopeysm penelopeysm force-pushed the py/remove-samplingcontext branch from b7221cc to 3835d01 Compare July 10, 2025 17:24
@penelopeysm penelopeysm force-pushed the py/actually-use-init branch from d55d378 to a392451 Compare July 10, 2025 17:33
@penelopeysm penelopeysm force-pushed the py/remove-samplingcontext branch from 3835d01 to 713034f Compare July 10, 2025 17:42
@penelopeysm penelopeysm force-pushed the py/actually-use-init branch from a392451 to 12d93e5 Compare July 10, 2025 17:44
@penelopeysm penelopeysm force-pushed the py/remove-samplingcontext branch from 713034f to 45a97ee Compare July 10, 2025 17:45
@penelopeysm penelopeysm force-pushed the py/actually-use-init branch from 12d93e5 to 7a8e7e3 Compare July 10, 2025 17:47
@penelopeysm penelopeysm force-pushed the py/remove-samplingcontext branch from 45a97ee to e817d9c Compare July 10, 2025 17:48
@penelopeysm penelopeysm force-pushed the py/actually-use-init branch from 7e38bbe to 1d8bceb Compare July 19, 2025 22:37
@penelopeysm penelopeysm force-pushed the py/remove-samplingcontext branch from 92772b5 to 1ffc409 Compare July 19, 2025 22:39
@penelopeysm penelopeysm force-pushed the py/actually-use-init branch from 1d8bceb to 2edcd10 Compare July 20, 2025 00:59
@penelopeysm penelopeysm force-pushed the py/remove-samplingcontext branch 2 times, most recently from 1957b06 to 4fc60dc Compare July 20, 2025 17:47
Copy link
Contributor

github-actions bot commented Jul 20, 2025

Benchmark Report for Commit 8e3dcac

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 |                  8.4 |                 1.6 |
|           Smorgasbord |       201 | forwarddiff |             typed |  false |                630.8 |                41.9 |
|           Smorgasbord |       201 | forwarddiff | simple_namedtuple |   true |                402.0 |                54.6 |
|           Smorgasbord |       201 | forwarddiff |           untyped |   true |               1094.5 |                29.7 |
|           Smorgasbord |       201 | forwarddiff |       simple_dict |   true |               6369.2 |                28.2 |
|           Smorgasbord |       201 | reversediff |             typed |   true |               1009.1 |                40.3 |
|           Smorgasbord |       201 |    mooncake |             typed |   true |                960.3 |                 4.2 |
|    Loop univariate 1k |      1000 |    mooncake |             typed |   true |               5577.2 |                 3.9 |
|       Multivariate 1k |      1000 |    mooncake |             typed |   true |                950.4 |                 9.1 |
|   Loop univariate 10k |     10000 |    mooncake |             typed |   true |              62727.0 |                 3.5 |
|      Multivariate 10k |     10000 |    mooncake |             typed |   true |               8418.4 |                 9.9 |
|               Dynamic |        10 |    mooncake |             typed |   true |                126.9 |                12.0 |
|              Submodel |         1 |    mooncake |             typed |   true |                 12.7 |                 4.7 |
|                   LDA |        12 | reversediff |             typed |   true |               1195.9 |                 2.8 |

Copy link

codecov bot commented Jul 20, 2025

Codecov Report

❌ Patch coverage is 89.47368% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.46%. Comparing base (23cafe0) to head (331279c).

Files with missing lines Patch % Lines
src/context_implementations.jl 86.66% 2 Missing ⚠️
Additional details and impacted files
@@                   Coverage Diff                    @@
##           py/actually-use-init     #985      +/-   ##
========================================================
+ Coverage                 80.57%   81.46%   +0.89%     
========================================================
  Files                        39       39              
  Lines                      3927     3825     -102     
========================================================
- Hits                       3164     3116      -48     
+ Misses                      763      709      -54     

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

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

@penelopeysm penelopeysm force-pushed the py/actually-use-init branch 2 times, most recently from 3a16f9c to 4c96020 Compare July 26, 2025 18:47
@penelopeysm penelopeysm force-pushed the py/remove-samplingcontext branch from 3951d1d to 79a5f3c Compare July 26, 2025 19:20
@@ -77,48 +77,6 @@ using DynamicPPL.TestUtils.AD: run_ad, WithExpectedResult, NoTest
end
end

@testset "Turing#2151: ReverseDiff compilation & eltype(vi, spl)" begin
Copy link
Member Author

@penelopeysm penelopeysm Jul 26, 2025

Choose a reason for hiding this comment

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

I couldn't find a way to reproduce this test without SamplingContext and the whole tilde-pipeline machinery that this PR removes, so I think that this is no longer relevant.

@penelopeysm penelopeysm mentioned this pull request Aug 8, 2025
8 tasks
@penelopeysm penelopeysm force-pushed the py/actually-use-init branch from 7b4c5fa to 23cafe0 Compare August 8, 2025 10:22
@penelopeysm penelopeysm force-pushed the py/remove-samplingcontext branch from 5278370 to 331279c Compare August 8, 2025 10:23
@penelopeysm penelopeysm force-pushed the py/actually-use-init branch from 23cafe0 to 8587eb7 Compare August 10, 2025 13:34
@penelopeysm penelopeysm force-pushed the py/remove-samplingcontext branch from 331279c to 7b0d5a9 Compare August 10, 2025 13:34
@penelopeysm penelopeysm force-pushed the py/actually-use-init branch from 8587eb7 to a6a42bd Compare August 10, 2025 13:45
@penelopeysm penelopeysm force-pushed the py/remove-samplingcontext branch from 7b0d5a9 to 0bd4e02 Compare August 10, 2025 13:46
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.

1 participant