You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JAX ODE solves under a vmapped sampler: chains that are done still solve at their last state #65
A sampler that advances several chains as one jax.vmap batch (BlackJAX's NUTS, for example) runs each of its while loops until the last chain is done. JAX runs a batched loop's body for every lane and keeps the old carry where a lane's loop has ended, so a chain whose trajectory has ended is still evaluated on every later leapfrog step of the batch, one step past its last state. After a divergence that state is often far out.
With an rk_ode_rk45_tol solve in the density, the cost of an evaluation depends on the position. Past a divergence the system can be stiff, and on CUDA (the per-lane Pallas kernel, 0.1.353) one lane's long solve then holds every call of the batch. RK computes these discarded values correctly; the batched loop passes the body no mask, so nothing in the module can tell a discarded lane from a live one.
Measured (four-chain BlackJAX 1.7.1 NUTS warm-up, a density with a five-state solve in each of 24 plate cells, float64, tolerances 1e-8, at most 100,000 steps per output, RTX 5060 Ti):
One chain diverged after 5 of 127 leapfrog steps. Its remaining evaluations took 175,276 solver attempts against about 17,500 for each running chain, and the transition 25 s where the others took about 4 s.
At a point whose solves exhaust the step budget, one value and gradient takes 16.7 s on the card and 0.11 s on one CPU core.
Workaround, documented in "JAX runtime and derivatives", section "Chains under vmap": guard the sampler so that a chain that is done evaluates a state it has already evaluated. In BlackJAX 1.7.1 that is two changes in blackjax.mcmc.trajectory (dynamic_progressive_integration and dynamic_multiplicative_expansion). Only discarded results change: compiled to round alike, guarded and unguarded NUTS gave bitwise identical draws on Neal's funnel. With the guard, the same warm-up had no transition over 6.4 s.
This issue tracks the boundary until the samplers RK's JAX modules are used with skip finished lanes themselves (BlackJAX upstream main still integrates from trajectory.rightmost_state for every lane).
Activity