{"record":{"id":"f8d8427af2303693","repo":"jax-ml/jax","slug":"out-specs-passed-to-shard-map-should-be-equal-to-t-f8d842","errorCode":null,"errorMessage":"out_specs passed to shard_map should be equal to the reduced present on the out_aval. Got out_specs={spec} and out_aval={aval.str_short(True)}","messagePattern":"out_specs passed to shard_map should be equal to the reduced present on the out_aval\\. Got out_specs=(.+?) and out_aval=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/shard_map.py","lineNumber":899,"sourceCode":"  return aval.update(shape=new_shape, sharding=new_sharding,\n                     manual_axis_type=mat)\ncore.shard_aval_handlers[core.ShapedArray] = _shard_shaped_array\n\ndef _unshard_shaped_array(mesh: Mesh, check_vma, spec, aval: core.ShapedArray\n                          ) -> core.ShapedArray:\n  assert isinstance(aval, core.ShapedArray)\n  if check_vma and spec.unreduced != aval.mat.unreduced:\n    raise ValueError(\n        \"out_specs passed to shard_map should be equal to the unreduced\"\n        f\" present on the out_aval. Got out_specs={spec} and\"\n        f\" out_aval={aval.str_short(True)}\")\n  if check_vma and spec.unreduced_kind is not aval.mat.unreduced_kind:\n    raise ValueError(\n        \"out_specs passed to shard_map should be equal to the unreduced_kind\"\n        f\" present on the out_aval. Got out_specs={spec} and\"\n        f\" out_aval={aval.str_short(True)}\")\n  if check_vma and spec.reduced != aval.mat.reduced:\n    raise ValueError(\n        \"out_specs passed to shard_map should be equal to the reduced present\"\n        f\" on the out_aval. Got out_specs={spec} and\"\n        f\" out_aval={aval.str_short(True)}\")\n  names = _spec_to_names(spec)\n  new_shape = tuple(sz * prod(mesh.shape[n] for n in names.get(i, ()))\n                    for i, sz in enumerate(aval.shape))\n  names_spec = spec._normalized_spec_for_aval(aval.ndim).partitions\n  if aval.ndim == 0:\n    out_spec = P(unreduced=spec.unreduced, reduced=spec.reduced,\n                 unreduced_kind=spec.unreduced_kind)\n  else:\n    out_spec = []\n    for name_s, aval_s in zip(names_spec, aval.sharding.spec.partitions):\n      if name_s and not aval_s:\n        out_spec.append(name_s)\n      elif aval_s and not name_s:\n        out_spec.append(aval_s)\n      elif not name_s and not aval_s:","sourceCodeStart":881,"sourceCodeEnd":917,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/shard_map.py#L881-L917","documentation":"When checking is enabled, out_specs' reduced tuple must equal the output aval's reduced tuple; the declared output reduction must agree with the reduction the body actually produced.","triggerScenarios":"Body yields arrays with reduced=('y',) but out_specs declares reduced=() or different axes.","commonSituations":"Partial-manual pipelines returning partially reduced tensors (gradient accumulation patterns) with plain out_specs.","solutions":["Declare the same reduced axes in out_specs as on the output aval","Fully reduce the output inside the body if plain out_specs is desired","Log aval.str_short(True) of outputs during development to align specs"],"exampleFix":"// before\nout = shard_map(f, mesh, x, out_specs=P('d'))\n// after\nout = shard_map(f, mesh, x, out_specs=P('d', reduced=('y',)))","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try: shard_map(...) except ValueError as e: if 'reduced present' in str(e): add the reduced axes to out_specs; else: raise","preventionTips":["Fully reduce outputs in the body unless reduced out_specs are intended"],"tags":["shard-map","reduced","out-specs","sharding-mismatch","jax"],"backgroundTag":"sharding-spec-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}