NUTS: the No-U-Turn Sampler (self-tuning trajectory length) - #56
Merged
Conversation
Multinomial NUTS (Hoffman & Gelman 2014) with dual-averaging step-size warmup: HMC that doubles each trajectory until a whole-span U-turn and tunes epsilon to target_accept, so it needs neither leapfrog_steps nor a step-size sweep. All B chains run in lockstep with a per-chain freeze mask (every state write gated by an active bool), so each chain's draw is identical to independent single-chain NUTS. Log-space multinomial weights keep the progressive sampling numerically stable; divergence and tree-depth are exposed as diagnostics. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Recovers a standard and a correlated Gaussian's covariance (pooling late near-independent draws), tunes to 0.8 acceptance with zero divergences on the Gaussian, enters Neal's funnel (finite, loose v.std band), and terminates by U-turn at small tree depths rather than bottoming out at max_depth. Plus the accept-rate lifecycle and constructor validation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Example runs NUTS on Neal's funnel and plots the per-draw tree-depth distribution (trajectory length adapts; it doesn't bottom out at max_depth), printing tuned step size, acceptance, and divergences. README samplers row + examples list and the unreleased 0.16.0 CHANGELOG updated. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
NUTS— the last item on the roadmap. HMC that tunes both of its knobs away.What
leapfrog_stepsto set; and a dual-averaging warmup tunes the step size totarget_accept(default 0.8), so there is no step-size sweep. Unbiased — targets exactlyp ∝ exp(-E).activemask (torch.where). This yields, per chain, exactly the draw an independent single-chain NUTS would produce (no cross-chain coupling; a stopped chain's state is never rewritten). Wasted leapfrogs on finished chains are the only cost.logaddexp) for progressive sampling; non-finite /ΔH > max_delta_htreated as divergence (weight 0, chain frozen) so a NaN can't leak across chains; trajectory math stays off-graph and the proposal is detached. Reuses HMC's leapfrog,_energy_grad, andAdaptiveMALA's dual-averaging recursion.last_tree_depthand adivergencescount for diagnostics.Validation (closed-form / distributional)
max_depth.Notes
examples/nuts_sampling.py(funnel + per-draw tree-depth histogram). torch-only; public API preserved; accumulates under the unreleased 0.16.0.🤖 Generated with Claude Code