Isolate initial_params/initial_state per chain in multi-chain sampling#215
Closed
yebai wants to merge 1 commit into
Closed
Isolate initial_params/initial_state per chain in multi-chain sampling#215yebai wants to merge 1 commit into
yebai wants to merge 1 commit into
Conversation
Multi-chain `mcmcsample` already deep-copies `model` and `sampler` per chain, but passed each `initial_params[i]`/`initial_state[i]` through uncopied, so a shared init object -- e.g. `fill(init, nchains)`, a natural idiom -- reached every chain. Under ForwardDiff this reliably triggers a heap-corruption segfault (a Julia GC bug we can only work around here); `deepcopy` per chain gives each chain its own copy, matching the existing model/sampler isolation. See #214. Co-Authored-By: Claude Code <noreply@anthropic.com>
Contributor
|
AbstractMCMC.jl documentation for PR #215 is available at: |
Member
Author
|
Closed in favour of TuringLang/DynamicPPL.jl#1440 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Multi-chain
mcmcsamplealready deep-copiesmodelandsamplerper chain, but passed eachinitial_params[i]/initial_state[i]through uncopied. So a shared init object — e.g.fill(init, nchains), a natural idiom — reaches every chain. With Turing + ForwardDiff this reliably segfaults (heap corruption surfaced during GC mark) within a few iterations; a distinct object per chain is clean.This
deepcopys the per-chain init so each chain gets its own copy, matching the existing per-chain isolation ofmodel/sampler. The underlying corruption is almost certainly an upstream Julia GC bug — it only occurs under ForwardDiff, is non-deterministic, and is independent of the init's values (the shared arrays are never mutated) — so this can only work around it, but per-chain isolation removes the footgun regardless of the Julia fix.It's hard to add tests for these as it is a Julia GC bug.
Fixes #214.