jax-ml/jax · error · TypeError

pmap in_axes must be an int, None, or (nested) container…

Error message

pmap in_axes must be an int, None, or (nested) container with those types as leaves, but got {in_axes}.

What it means

Validation in _prepare_pmap: in_axes is flattened as a pytree and every leaf must be an int, None, or a nested container of those types (matching jax.vmap conventions). Any leaf of another type — e.g., a string or array — fails this check with the offending in_axes shown.

Solutions

  1. Replace leaves with Python `int(...)` or None
  2. Flatten/normalize numpy ints: `in_axes = tree_map(lambda a: None if a is None else int(a), in_axes)`
  3. Verify each leaf is `type(l) is int` before calling pmap

Example fix

# before
f = jax.pmap(fn, in_axes=(np.int64(0), None))
# after
f = jax.pmap(fn, in_axes=(int(np.int64(0)), None))
Defensive patterns

Strategy: type-guard

Validate before calling

from jax.tree_util import tree_leaves
assert all(type(a) is int or a is None for a in tree_leaves(in_axes)), 'bad in_axes leaves'

Type guard

from jax.tree_util import tree_map
def normalize_axes(ax):
    return tree_map(lambda a: None if a is None else int(a), ax)

Prevention

When it happens

Trigger: `jax.pmap(f, in_axes=0.0)`, `in_axes=(0, 'batch')`, or a nested container containing a non-int leaf; also NumPy integer types fail the strict `type(l) is int` check.

Common situations: Using np.int64 values from computed configs; confusing pmap in_axes with vjp/vmap-style axis specs or with shard_map specs; typos like True instead of 0.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/6d4b54f6474ab31c. Report an issue: GitHub.

Appendix: source

Thrown at jax/_src/pmap.py:356

    )

  wrapped.lower = lower  # pyrefly: ignore[missing-attribute]
  return wrapped


def _prepare_pmap(fun, axis_name, static_broadcasted_argnums,
                      donate_argnums, in_axes, out_axes):
  # axis_size is an optional integer representing the global axis size.  The
  # aggregate size (across all processes) size of the mapped axis must match the
  # given value.
  check_callable(fun)
  axis_name = "_internal_pmap_axis_name" if axis_name is None else axis_name
  static_broadcasted_tuple = _ensure_index_tuple(static_broadcasted_argnums)
  donate_tuple = rebase_donate_argnums(
      _ensure_index_tuple(donate_argnums), static_broadcasted_tuple)

  if not all(type(l) is int for l in tree_leaves(in_axes)):
    raise TypeError("pmap in_axes must be an int, None, or (nested) container "
                    f"with those types as leaves, but got {in_axes}.")
  if not all(type(l) is int for l in tree_leaves(out_axes)):
    raise TypeError("pmap out_axes must be an int, None, or (nested) container "
                    f"with those types as leaves, but got {out_axes}.")

  return axis_name, static_broadcasted_tuple, donate_tuple


class CachedShardMap(NamedTuple):
  """Core cached pmap result.

  Attributes:
    pmapped: The shard_map-transformed function.
    in_specs_flat: Flattened input PartitionSpecs for array conversion.
    local_devices: List of devices in the local mesh.
    in_local_shardings: NamedSharding for each input using local mesh.
    in_global_shardings: NamedSharding for each input using global mesh.
    mesh: The global Mesh for this pmap invocation.

View on GitHub (pinned to 1e1c6a8fc0)