jax-ml/jax · error · ValueError
varying and reduced cannot have common mesh axes. Got varyin
Error message
varying and reduced cannot have common mesh axes. Got varying={varying} and reduced={reduced} What it means
_check_mat rejects a ManualAxisType where the same mesh axis is both 'varying' and 'reduced'. An axis is either replicated-varying or already reduced (result of a collective); it cannot be declared both.
Source
Thrown at jax/_src/core.py:2349
reduced = frozenset(r for r in mat.reduced if mesh.shape[r] != 1)
u_kind = mat.unreduced_kind if unreduced else None
return mat.update(varying=varying, unreduced=unreduced, reduced=reduced,
unreduced_kind=u_kind)
return mat
def get_memory_space(memory_space):
assert memory_space is not None
return memory_space
def _check_mat(varying, unreduced, reduced, unreduced_kind):
if varying & unreduced:
raise ValueError(
"varying and unreduced cannot have common mesh axes. Got"
f" varying={varying} and unreduced={unreduced}")
if varying & reduced:
raise ValueError(
"varying and reduced cannot have common mesh axes. Got"
f" varying={varying} and reduced={reduced}")
assert not (varying & unreduced & reduced)
if unreduced_kind is not None and not isinstance(unreduced_kind, UnreducedKind):
raise TypeError(
"Expected unreduced_kind to be of type `jax.sharding.UnreducedKind`"
f" but got {type(unreduced_kind)}")
if not unreduced and unreduced_kind is not None:
raise ValueError(
"`unreduced_kind` should be `None` when `unreduced` is an empty set."
f" Got {unreduced_kind=} and {unreduced=}")
def _canonicalize_mat(name, val):
if not isinstance(val, frozenset):
if not isinstance(val, set):
raise TypeError(
f"{name} argument of ManualAxisType should "View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Remove the axis from 'reduced' if subsequent ops treat it as varying, or from 'varying' if the collective output is replicated
- Derive mats automatically (JAX computes them for standard collectives) rather than setting them by hand
Example fix
// before
mat = ManualAxisType(varying={'x'}, reduced={'x'})
// after
mat = ManualAxisType(varying={'x'}) Defensive patterns
Strategy: validation
Validate before calling
if varying & reduced:
raise ValueError('axis in both varying and reduced') Type guard
def disjoint_mat(varying, unreduced, reduced): return not (varying & unreduced) and not (varying & reduced)
Prevention
- Compute reduced as full - varying - unreduced to guarantee disjointness
When it happens
Trigger: ManualAxisType(varying={'x'}, reduced={'x'}); typically from internal code or user-built avals after collectives like psum where the axis was already marked reduced.
Common situations: Composing collectives (psum then operations that assume varying) with manual mat bookkeeping; custom spmd primitives copying mat sets incorrectly.
Related errors
- Axes mentioned in `manual_axis_type` field of ShapedArray sh
- varying and unreduced cannot have common mesh axes. Got vary
- `unreduced_kind` should be `None` when `unreduced` is an emp
- Factor {factor} is not used in the rule, but size is provide
- {kind} contains duplicated factors
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/a327e04225bb9fa8.
Report an issue: GitHub.