jaxrens.sampling.batch_descriptor

Execution-topology descriptors for the NS outer loop.

Four execution topologies exist — SingleRun, VmapRuns, PmapVmapRuns, ShardedSingleRun — encapsulating the shape/RNG/ reduction bookkeeping so _run_loop (run_loop.py) and its callbacks can share one orchestration body without per-topology isinstance branching for most concerns:

  1. wrap_step — JIT-compiles (and vmaps/shard_maps as appropriate) the NS step.

  2. split_keys — Splits a PRNG key appropriately for the batch shape.

  3. reduce_for_termination — Reduces batched scalars to a single scalar for PriorMassTermination / IterationTermination.

BatchDescriptor (bottom of this module) is the SingleRun | VmapRuns | PmapVmapRuns | ShardedSingleRun type used to annotate “any of the four” — not a base class. SingleRun, VmapRuns, and PmapVmapRuns share a concrete (non-abstract) base, _UniformBatcher, because they genuinely share behavior: each satisfies n_runs == prod(shape_prefix) and treats its leading shape axes as independent-replica axes. ShardedSingleRun does not inherit from it — its shape_prefix = (n_gpu,) is a sharding axis, not a replica axis (n_runs is always 1), so several of _UniformBatcher’s methods don’t apply to it as written (see its own docstring). Rather than force it to override most of a shared contract to fit a hierarchy whose invariants it breaks, it stands alone with its own implementations — some duplicated from _UniformBatcher where the generic, shape_prefix-driven logic happens to still be correct for it.

Module Attributes

BatchDescriptor

Any of the four execution topologies (a type alias, not a base class).

Functions

from_shape_prefix

Return the batcher whose shape_prefix matches shape_prefix.

Classes

PmapVmapRuns

Descriptor for shard_map(vmap(...)) multi-GPU multi-run NS.

ShardedSingleRun

Descriptor for a single NS run sharded across n_gpu GPUs.

SingleRun

Descriptor for a single NS run (no batching).

VmapRuns

Descriptor for n_runs independent NS runs batched via jax.vmap.