adv_jax_math.batch_vmap
- adv_jax_math.batch_vmap(f, /, in_axes=0, *, batch_size=None, reduction=None, chunk_reduction=<function identity>, shard=False, mesh=None, **kwargs)[source]
Behaves like
vmapbut uses scan to chunk the computations in smaller chunks.Warning
https://docs.jax.dev/en/latest/jep/2026-custom-derivatives.html #main-problem-descriptions.
Only
out_axes=0is supported.
See also
batch_mapIf the function supports native vectorization, use
batch_mapinstead for the reasons discussed the docstring.
- Parameters:
f (callable) – The function to be vectorised.
in_axes (int or None) – The axes that should be scanned along. Only supports
0orNone.batch_size (int or None) – Size to split computation into chunks. If no chunking should be done or the chunk size is the full input then supply
None.chunk_sizeis accepted as an alias whenbatch_sizeisNone.reduction (callable or None) – Binary reduction operation. Should take two arguments and return one output, e.g.
jnp.add, and must be associative because partial chunk results are combined in an implementation-dependent order.chunk_reduction (callable) – Chunk-wise reduction operation. Should summarize a chunk compatibly with
reductionalong the mapped axis, e.g.jnp.add.reduce.shard (bool) – Whether to shard mapped input data across devices before applying chunked batching. The divisible prefix is split across devices; when supplied,
batch_sizebounds the batches processed on each device. A local remainder is evaluated once per device, and a final global remainder is evaluated once overall. The mapped length need not be divisible by either the device count orbatch_size. Default isFalse. If a non-reduced output has a global remainder, the final concatenated output is replicated across the mesh.mesh (jax.sharding.Mesh or None) – Optional one-dimensional mesh with an
AxisType.Autoaxis. Supplying a mesh selects the devices and topology used byshard=Trueand lets already-sharded inputs retain a compatible layout. Default isNone, which creates a mesh over all available devices.
- Returns:
f (callable) – A vectorised and chunked function.