Skip to content

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Sep 8, 2025

As title. The challenge is not here, of course, it's making sure that Turing still works correctly. I'm about 99% sure that this can be done fairly straightforwardly because I've actually done all the work before, see TuringLang/Turing.jl#2588.

Because I branched off the InitContext branches it will have to wait until those PRs are merged.

@penelopeysm penelopeysm changed the base branch from breaking to py/remove-samplingcontext September 8, 2025 16:26
Comment on lines -42 to -55
function AbstractMCMC.sample(
rng::Random.AbstractRNG,
model::Model,
sampler::Sampler,
N::Integer;
chain_type=default_chain_type(sampler),
resume_from=nothing,
initial_state=loadstate(resume_from),
kwargs...,
)
return AbstractMCMC.mcmcsample(
rng, model, sampler, N; chain_type, initial_state, kwargs...
)
end
Copy link
Member Author

@penelopeysm penelopeysm Sep 8, 2025

Choose a reason for hiding this comment

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

This method (or to be precise its default kwargs) will have to be shifted upwards to Turing. The same is true for the multiple-chain sampling one.

Comment on lines 65 to 71
function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler;
initial_params::AbstractInitStrategy=init_strategy(spl),
kwargs...,
)
Copy link
Member Author

@penelopeysm penelopeysm Sep 8, 2025

Choose a reason for hiding this comment

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

This one requires some subtlety. It ensures that for all Samplers the first step goes via initialstep because the rest of the code is shared. We can do the same using an internal Turing.Inference.initialstep for now; in the long term that function will also be removed if we use LogDensityFunction in sample.

Copy link
Contributor

github-actions bot commented Sep 8, 2025

Benchmark Report for Commit 35d0be2

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.8 |                 1.4 |
|           Smorgasbord |       201 | forwarddiff |             typed |  false |                655.7 |                49.0 |
|           Smorgasbord |       201 | forwarddiff | simple_namedtuple |   true |                417.1 |                56.3 |
|           Smorgasbord |       201 | forwarddiff |           untyped |   true |               1068.5 |                33.1 |
|           Smorgasbord |       201 | forwarddiff |       simple_dict |   true |               8124.1 |                23.7 |
|           Smorgasbord |       201 | reversediff |             typed |   true |               1424.9 |                30.8 |
|           Smorgasbord |       201 |    mooncake |             typed |   true |                991.9 |                 4.6 |
|    Loop univariate 1k |      1000 |    mooncake |             typed |   true |               5847.2 |                 4.2 |
|       Multivariate 1k |      1000 |    mooncake |             typed |   true |                999.7 |                 8.9 |
|   Loop univariate 10k |     10000 |    mooncake |             typed |   true |              65432.2 |                 3.9 |
|      Multivariate 10k |     10000 |    mooncake |             typed |   true |               8741.3 |                10.0 |
|               Dynamic |        10 |    mooncake |             typed |   true |                145.4 |                11.7 |
|              Submodel |         1 |    mooncake |             typed |   true |                 13.9 |                 5.1 |
|                   LDA |        12 | reversediff |             typed |   true |               1044.2 |                 2.5 |

@yebai yebai self-requested a review September 9, 2025 20:44
@penelopeysm penelopeysm force-pushed the py/remove-samplingcontext branch from 8e3dcac to 0b87d0d Compare September 18, 2025 11:40
@penelopeysm penelopeysm force-pushed the py/remove-samplingcontext branch from 0b87d0d to 992569f Compare September 18, 2025 13:03
Base automatically changed from py/remove-samplingcontext to breaking September 24, 2025 15:48
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