PmapVmapRuns¶
- class jaxrens.sampling.batch_descriptor.PmapVmapRuns(n_gpu, n_per_gpu, n_runs=0, shape_prefix=())[source]¶
Bases:
_UniformBatcherDescriptor for
shard_map(vmap(...))multi-GPU multi-run NS.Shape convention:
(G, P, K, ...)whereG = n_gpu— sharded axis (one shard per GPU device).P = n_per_gpu— vmap axis (independent NS runs per GPU).K— walker axis (already handled insidens_stepvia vmap).
For
n_gpu=1this degenerates to(1, P, K, ...)and runs on the single available device, which is useful for testing.wrap_step composes a
"gpu"-axisjax.shard_map(G axis) overjax.vmap(P axis), with one move-schedule key shared by every run on every device (simplified; squeezing of the G axis omitted):per_run = lambda s, mk: ns_step_fn( s, step_fn, n_mcmc_steps, n_extra, move_key=mk) sharded = jax.shard_map( # ns_states: P("gpu"), mk: P() jax.vmap(per_run, in_axes=(0, None)), mesh=mesh, in_specs=(P("gpu"), P()), out_specs=P("gpu")) jit_step = jax.jit( lambda s: sharded(s, _shared_move_key(s.rng_key)))
Unlike
jax.pmap,shard_mapcomposes cleanly withjax.jit, so the result is explicitly jit-wrapped.split_keys produces
(G, P, n_sub_keys)-shaped key arrays via two nested splits: first(G,)per-GPU keys, then(P, n_sub_keys)per GPU viajax.vmap.reduce_for_termination takes the worst-of across both G and P axes (same as VmapRuns but over a 2-D input rather than 1-D).
- Variables:
- Parameters:
- property mesh¶
The
"gpu"-axisjax.sharding.Meshfor this topology.Built once per instance (not per
wrap_step/wrap_for_batchcall) and shared by every consumer —InterREManagerpulls this same object rather than building its own equivalent-but-distinct mesh.
- wrap_step(ns_step_fn, step_fn, n_mcmc_steps, n_extra)[source]¶
Return a shard_map(vmap(…)) NS step callable (pmap-equivalent).
The returned callable has signature:
pmap_step(ns_states) -> (ns_states, infos)
where
ns_stateshas leading shape(G, P, ...).Built on
jax.shard_map(viawrap_for_batch()) rather thanjax.pmap— this is the"gpu"-axis leg of the pmap -> shard_map migration. Unlikejax.pmap,shard_mapcomposes withjax.jit, so the returned callable is explicitly jit-wrapped.- Parameters:
- Returns:
jax.jit(shard_map(vmap(per_run)))withns_statessharded over G and one globally sharedmove_keyreplicated to every device (see_wrap_batched_step()).- Return type:
callable
- split_keys(rng_key, n_sub_keys)[source]¶
Split a per-replica PRNG key array into
(G, P, n_sub_keys).Input shape equals
shape_prefix((G, P)here), output prepends ann_sub_keysaxis at the end. Implemented as a 2-D vmap (one for each prefix axis) ofjax.random.split.