liveBook · Manning

In_axes

As explained in Deep Learning with JAX

The vmap() argument that specifies, for each function argument, which axis to map over or whether to leave it unmapped.

in_axes tells vmap() which input axes to vectorize over and which arguments to leave unchanged. It lets a single-element function run over batches without rewriting the function itself. section 2.5

The value can be an integer, None, or a matching Python container such as a tuple, list, or dict. A None entry means that argument is broadcast rather than split for mapping. section 6.2.1 section 7.2.1

Common patterns include:

  • Use 0 for ordinary batch dimensions on positional arguments. section 6.2.1
  • Use a different integer when the batch axis is not first, such as transposed data. section 6.2.1
  • Use None for scalars or shared values that should be copied unchanged across mapped calls. section 6.2.1
  • Mirror nested input structure with dicts or other standard containers. section 6.2.1

Mixed-axis vectorization

A scaled dot product can batch one vector on axis 0, another on axis 1, and keep a coefficient fixed with in_axes=(0,1,None). The same idea works when the vectors arrive inside a dict. section 6.2.1 section 6.2.1

Keyword arguments are always mapped over their leading axis, so they do not follow the positional in_axes tuple. When a keyword value should stay fixed, wrap or partially apply it first. section 6.2.3 section 6.2.3

How Deep Learning with JAX covers it

How deep it goes
Explains the parameter definition, default leading-axis behavior, container-shaped specifications, and keyword-argument caveats.
Examples
Uses dot products, scaled dot products, transposed arrays, dict inputs, and batch augmentation with random keys.
What it assumes
Assumes basic familiarity with function arguments, arrays, and batch dimensions, while teaching the mapping rules from zero.
What you can do after
Apply vmapped functions to batches with mixed input layouts and shared parameters.
How it connects
Links vmap, pmap, out_axes, batching, and partial application.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with JAX. The section links point to the parts of the book it draws on.