{"record":{"id":"eb5529cf1a916b95","repo":"jax-ml/jax","slug":"out-specs-passed-to-shard-map-should-be-equal-to-t","errorCode":null,"errorMessage":"out_specs passed to shard_map should be equal to the unreduced 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 unreduced 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":889,"sourceCode":"  manual_mesh = _as_manual_mesh(mesh, manual_axes)\n  new_sharding = aval.sharding.update(\n      mesh=manual_mesh,\n      spec=core.modify_spec_for_auto_manual(aval.sharding.spec, manual_mesh))\n  vma = (_spec_to_vma(spec) if check_vma else frozenset()) | aval.mat.varying\n  unreduced = aval.sharding.spec.unreduced if check_vma else frozenset()\n  reduced = aval.sharding.spec.reduced if check_vma else frozenset()\n  u_kind = aval.sharding.spec.unreduced_kind if check_vma else None\n  mat = core.ManualAxisType(varying=vma, unreduced=unreduced, reduced=reduced,\n                            unreduced_kind=u_kind)\n  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:","sourceCodeStart":871,"sourceCodeEnd":907,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/shard_map.py#L871-L907","documentation":"On the output side (when VMA checking is enabled), shard_map verifies that out_specs' unreduced tuple matches the unreduced information on the output aval produced by the mapped function. A mismatch means the declared output replication contradicts what the body computed.","triggerScenarios":"The function's outputs carry unreduced=('r',) semantics (e.g. from input mat info) but out_specs omits or changes unreduced.","commonSituations":"Writing manual/partial-manual shard_map bodies that return partially-replicated arrays while out_specs was written as a plain partition.","solutions":["Set out_specs' unreduced equal to the output aval's unreduced (see aval.str_short(True))","Adjust the body so outputs are fully materialized (no unreduced) if out_specs must stay simple","Keep check_vma enabled during development to catch this early"],"exampleFix":"// before\nout = shard_map(f, mesh, x, out_specs=P('d'))  # body yields unreduced 'r'\n// after\nout = shard_map(f, mesh, x, out_specs=P('d', unreduced=('r',)))","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try: shard_map(...) except ValueError as e: if 'out_specs' in str(e) and 'unreduced' in str(e): adjust out_specs to match printed aval; else: raise","preventionTips":["During development run with checking enabled and print output avals","Keep out_specs symmetric with the input unreduced axes"],"tags":["shard-map","unreduced","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"}