{"record":{"id":"fe370b26a2b952f3","repo":"jax-ml/jax","slug":"reduced-axes-can-only-refer-to-mesh-axes-that-is-o","errorCode":null,"errorMessage":"Reduced axes can only refer to mesh axes that is of type `Explicit`. Got reduced axes: {pspec.reduced} and mesh: {mesh}","messagePattern":"Reduced axes can only refer to mesh axes that is of type `Explicit`\\. Got reduced axes: (.+?) and mesh: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/named_sharding.py","lineNumber":605,"sourceCode":"def _check_mesh_unreduced(mesh, pspec):\n  for u in pspec.unreduced:\n    if u not in mesh.axis_names:\n      raise ValueError(\n          f'Unreduced axes {u} is not found in {mesh.axis_names=}. '\n          f'Got {pspec=}')\n    if mesh._name_to_type[u] in (AxisType.Auto, AxisType.Manual):\n      raise ValueError(\n          'Unreduced axes can only refer to mesh axes that is of type'\n          f' `Explicit`. Got unreduced axes: {pspec.unreduced} and'\n          f' mesh: {mesh}')\n\n  for u in pspec.reduced:\n    if u not in mesh.axis_names:\n      raise ValueError(\n          f'Reduced axes {u} is not found in {mesh.axis_names=}. '\n          f'Got {pspec=}')\n    if mesh._name_to_type[u] in (AxisType.Auto, AxisType.Manual):\n      raise ValueError(\n          'Reduced axes can only refer to mesh axes that is of type'\n          f' `Explicit`. Got reduced axes: {pspec.reduced} and'\n          f' mesh: {mesh}')\n","sourceCodeStart":587,"sourceCodeEnd":609,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/named_sharding.py#L587-L609","documentation":"Raised by jax's NamedSharding PSpec validation (check_pspec/_check_mesh_unreduced) when a PartitionSpec marks axes as 'reduced', but the corresponding mesh axis is not an Explicit axis (it is Auto or Manual, i.e. created via automatic or manual/spmd partitioning rather than explicitly named in the Mesh). Reduction semantics are only defined over explicitly-declared mesh axes.","triggerScenarios":"Passing a NamedSharding whose PSpec uses reduced axes (e.g. P(None, 'x', reduced=('x',))) where mesh axis 'x' was created as AxisType.Auto (from jax.experimental.mesh_utils or auto-partitioned meshes) or AxisType.Manual (from spmd manual partitioning), then using it as an out_sharding.","commonSituations":"Migrating SPMD/manual-partition code to NamedSharding out_sharding APIs; mixing Mesh created with auto axes (e.g. openxla mesh_utils) with PSpec reduced syntax; specifying out_sharding on initializers/one_hot with a mesh built for auto-sharding.","solutions":["Use a Mesh whose axes are all explicit (jax.sharding.Mesh with named device lists) so the reduced axis resolves to AxisType.Explicit","Remove the reduced axes from the PSpec and do the reduction manually (e.g. jax.lax.psum / .sum) instead of relying on unreduced/reduced spec semantics","If on Auto axes, rely on the GSPMD auto partitioner instead of NamedSharding reduced specs"],"exampleFix":"// before\npspec = P(None, 'x', reduced=('x',))  # mesh axis 'x' is Auto/Manual\nsharding = NamedSharding(mesh, pspec)\n\n// after\nout = jax.pmap(lambda x: x.sum('x'))(arr)  # explicit reduction\n# or use an all-Explicit Mesh:\nmesh = jax.sharding.Mesh(jax.devices(), ('x',))\nsharding = NamedSharding(mesh, P(None, 'x', reduced=('x',)))","handlingStrategy":"validation","validationCode":"from jax.experimental.mesh_utils import ...  # if needed\nfor u in pspec.reduced:\n    assert u in mesh.axis_names, f'{u} not in mesh'\n    # mirror the internal check without private access: ensure the axis was\n    # created explicitly via jax.sharding.Mesh(devices, (names...))\nassert all(a in mesh.axis_names for a in pspec.reduced)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use PSpec reduced axes with fully explicit jax.sharding.Mesh axes","Keep auto/manual-partitioned meshes separate from NamedSharding reduced-spec codepaths","Document which mesh axes are Explicit in multi-team distributed code"],"tags":["jax","sharding","mesh","distributed","named-sharding"],"backgroundTag":"sharding-spec-validation-failed","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}