{"record":{"id":"4135279dfa702ea3","repo":"jax-ml/jax","slug":"name-cannot-accept-args-with-unreduced-kind-a-m","errorCode":null,"errorMessage":"{name} cannot accept args with unreduced_kind={a.mat.unreduced_kind}. Expected unreduced_kind={kind}","messagePattern":"(.+?) cannot accept args with unreduced_kind=(.+?)\\. Expected unreduced_kind=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/core.py","lineNumber":2753,"sourceCode":"  new_axes = axes if cur_mesh.empty else order_wrt_mesh(cur_mesh, axes)\n  assert set(new_axes) == set(axes)\n  del axes\n  return tree_map(lambda leaf: reduced_vary_cast_p.bind(leaf, axes=new_axes), x)\n\nreduced_vary_cast_p = Primitive('reduced_vary_cast_p')\n\n#######################################################################\n\ndef check_unreduced_args(args, axes, name, kind=UnreducedKind.sum):\n  axes = axes if isinstance(axes, (tuple, list)) else (axes,)\n  axes = set(axes)\n  for a in args:\n    if a.mat.unreduced & axes:\n      raise ValueError(\n          f\"{name} cannot accept args which are unreduced. Got\"\n          f\" {a.str_short(True)} and axes={axes}\")\n    if a.mat.unreduced and a.mat.unreduced_kind is not kind:\n      raise ValueError(\n          f\"{name} cannot accept args with\"\n          f\" unreduced_kind={a.mat.unreduced_kind}. Expected\"\n          f\" unreduced_kind={kind}\")\n    if a.mat.reduced & axes:\n      raise ValueError(\n          f\"{name} cannot accept args which are reduced. Got\"\n          f\" {a.str_short(True)} and axes={axes}\")\n\ndef insert_reduced_reshard(args):\n  cur_mesh = mesh_lib.get_abstract_mesh()\n  if not cur_mesh.are_all_axes_explicit:\n    return args\n  # TODO(yashkatariya): Handle >2 args too\n  if len(args) != 2:\n    return args\n  in_reduced = [aval.sharding.spec.reduced\n                if isinstance(aval := shaped_abstractify(a), ShapedArray)\n                else frozenset() for a in args]","sourceCodeStart":2735,"sourceCodeEnd":2771,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/core.py#L2735-L2771","documentation":"check_unreduced_args also enforces that all unreduced operands share the same UnreducedKind as the primitive expects (default sum). An operand marked unreduced with kind=min cannot feed a primitive expecting sum-style unreduce semantics.","triggerScenarios":"Mixing pmin/pmax-produced unreduced values into primitives expecting UnreducedKind.sum (or vice versa) inside shard_map/spmd pipelines.","commonSituations":"Chaining different reduction flavors (pmin then psum paths) without resharding between; custom collectives defaulting to sum while receiving min-kind operands.","solutions":["Insert a reshard so operands lose their unreduced marking before the next collective","Match the primitive's expected kind by transforming the value appropriately (e.g. re-reduce with the same kind)","Pass the correct kind parameter to the primitive if it accepts one"],"exampleFix":"// before\nm = jax.lax.pmin(x, 'i')       # unreduced_kind=min\ns = consume_expecting_sum(m)   # rejected\n\n// after\nm = jax.lax.pmin(x, 'i')\nm = reshard(m)\ns = consume_expecting_sum(m)","handlingStrategy":"validation","validationCode":"if any(a.mat.unreduced and a.mat.unreduced_kind is not kind for a in args):\n    args = [reshard(a) for a in args]","typeGuard":"def kinds_match(args, kind): return all(a.mat.unreduced_kind is kind for a in args if a.mat.unreduced)","tryCatchPattern":null,"preventionTips":["Don't mix pmin/pmax and psum intermediates without resharding"],"tags":["jax","sharding","collectives","unreduced-kind","spmd"],"backgroundTag":"spmd-axis-misuse","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}