Skip to content

Unify HMC + externalsampler + DynamicHMC parameter initialisation; re-export DynamicPPL.set_logprob_type!#2794

Merged
penelopeysm merged 9 commits intomainfrom
py/ldf-init
Mar 26, 2026
Merged

Unify HMC + externalsampler + DynamicHMC parameter initialisation; re-export DynamicPPL.set_logprob_type!#2794
penelopeysm merged 9 commits intomainfrom
py/ldf-init

Conversation

@penelopeysm
Copy link
Copy Markdown
Member

@penelopeysm penelopeysm commented Mar 23, 2026

Closes #2739.

As a nice by-product of using rand(ldf) rather than vi[:], we also avoid accidentally promoting Float32 to Float64. This means that (together with TuringLang/DynamicPPL.jl#1328 and tpapp/DynamicHMC.jl#199) one can do

julia> using DynamicPPL; DynamicPPL.set_logprob_type!(Float32)
┌ Info: DynamicPPL's log probability type has been set to Float32.
└ Please note you will need to restart your Julia session for this change to take effect.

and then after restarting

julia> using Turing, FlexiChains, DynamicHMC

julia> @model function f()
           x ~ Normal(0.0f0, 1.0f0)
       end
f (generic function with 2 methods)

julia> chn = sample(f(), externalsampler(DynamicHMC.NUTS()), 100; chain_type=VNChain)
Sampling 100%|████████████████████████████████████████████| Time: 0:00:02
FlexiChain (100 iterations, 1 chain)
 iter=1:100 |  chain=1:1

Parameter type   VarName
Parameters       x
Extra keys       :logprior, :loglikelihood, :logjoint


julia> eltype(chn[@varname(x)])
Float32

julia> eltype(chn[:logjoint])
Float32

(Previously, the values of x would be Float32, but logjoint would be Float64. And if you used MCMCChains, everything would be Float64.)

@github-actions
Copy link
Copy Markdown
Contributor

Turing.jl documentation for PR #2794 is available at:
https://TuringLang.github.io/Turing.jl/previews/PR2794/

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.44%. Comparing base (838ae6a) to head (8eafaba).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2794   +/-   ##
=======================================
  Coverage   86.44%   86.44%           
=======================================
  Files          22       22           
  Lines        1446     1446           
=======================================
  Hits         1250     1250           
  Misses        196      196           

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

@penelopeysm penelopeysm mentioned this pull request Mar 23, 2026
@penelopeysm penelopeysm changed the title Unify HMC + externalsampler + DynamicHMC parameter initialisation Unify HMC + externalsampler + DynamicHMC parameter initialisation; re-export set_logprob_type! Mar 26, 2026
@penelopeysm penelopeysm changed the title Unify HMC + externalsampler + DynamicHMC parameter initialisation; re-export set_logprob_type! Unify HMC + externalsampler + DynamicHMC parameter initialisation; re-export DynamicPPL.set_logprob_type! Mar 26, 2026
@penelopeysm penelopeysm merged commit f86999b into main Mar 26, 2026
30 checks passed
@penelopeysm penelopeysm deleted the py/ldf-init branch March 26, 2026 19:05
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.

External sampler should try harder at generating initial params

1 participant