ns_step_sharded¶
- jaxrens.sampling.nested_sampling.ns_step_sharded(ns_state, step_fn, n_mcmc_steps=20, n_extra=0, n_cull=1, move_key=None)[source]¶
One NS iteration with the population sharded across
n_gpuGPUs.Shape contract: every leaf of
ns_state.populationhas shape(K_per_gpu, ...)on the local device; the global population is(K_total = G * K_per_gpu, ...)reconstructable vialax.all_gather.ns_state.n_walkerscarries the global walker count.Must be called inside a
jax.shard_mapover the"shard"mesh axis (seeShardedSingleRun.wrap_step()). Useslax.all_gatherto materialise the full population on every device for the worst-walker selection and the chain seed broadcast; then writes new walkers via a global scatter that is sliced back to the local shard before return.Body mirrors
ns_step()with five substitutions:Worst-walker selection runs on the globally gathered potentials (same RNG → same global index on every shard).
Random-survivor cloning indexes globally — the chain seed is identical on every shard.
The MCMC chains are DISTRIBUTED across shards: each device walks only its
ceil(n_walk / G)slice of the (clone + n_extra) chains, then the small final walker states + per-move counters arelax.all_gather-ed back. This divides the model-eval work (the dominant per-step cost) G ways, so a sharded run is both a memory win (population storage is split) and a walk speedup of up to G× whenn_walk >= G. Chainialways consumeschain_keys[i]regardless of which shard runs it, so the walk is bit-identical to the single-device result.Writing the new walkers happens via a global
.at[].set(...)on the gathered population, then reshape-and-slice back to the local shard.Per-move counters are produced identically on every shard, so no
lax.psumis needed for correctness — they’re already coherent. The returnedinfodict has the same shapes asns_step()(per-shard view).