pmap_like

jaxrens.sampling.mesh.pmap_like(fn, axis_name, mesh, *, check_vma=False)[source]

Wrap fn so jax.shard_map reproduces jax.pmap’s calling convention for it.

fn should be written as if for jax.pmap(fn, axis_name=axis_name): it receives each input leaf with the mapped axis already removed, and returns output leaves without that axis (pmap re-adds it by stacking).

The returned callable is a plain jax.shard_map-wrapped function with in_specs = out_specs = PartitionSpec(axis_name) applied uniformly across every leaf of the (possibly pytree-valued) arguments/outputs — matching jax.pmap’s default in_axes=0/out_axes=0 behavior. Unlike jax.pmap, the result composes with jax.jit.

check_vma controls whether shard_map’s “varying manual axis” type checker (new relative to pmap, see https://docs.jax.dev/en/latest/notebooks/shard_map.html#scan-vma) is enabled. It rejects some lax.while_loop/lax.scan carries that mix a Python-literal initial value with a per-device-varying value produced inside the loop body — a pattern that was always legal under pmap, which never tracked this distinction. Defaults to False (pmap’s old “trust the caller” model) so pmap_like is a faithful, unmodified port by default; callers whose wrapped function has been updated to type-check under it (e.g. via jax.lax.pcast on the affected carry entries — see jaxrens.sampling.adaptation.stepsize_handler.adjust_step_size) can pass check_vma=True to get the checker’s safety net back.

Parameters:
Return type:

Callable