{"record":{"id":"8ea93ca91134bc3f","repo":"jax-ml/jax","slug":"broadcast-in-dim-broadcast-dimensions-must-not-con","errorCode":null,"errorMessage":"broadcast_in_dim broadcast_dimensions must not contain duplicates, got broadcast_dimensions {}","messagePattern":"broadcast_in_dim broadcast_dimensions must not contain duplicates, got broadcast_dimensions (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/lax.py","lineNumber":6940,"sourceCode":"  if not set(broadcast_dimensions).issubset(set(range(len(shape)))):\n    msg = ('broadcast_in_dim broadcast_dimensions must be a subset of output '\n           'dimensions, got {} for operand ndim {} and shape {}.')\n    raise TypeError(msg.format(broadcast_dimensions, operand_ndim, shape))\n  if not all(core.definitely_equal_one_of_dim(operand.shape[i],\n                                              [1, shape[broadcast_dimensions[i]]])\n             for i in range(operand_ndim)):\n    msg = (\n        \"broadcast_in_dim operand dimension sizes must either be 1, or be \"\n        \"equal to their corresponding dimensions in the target broadcast \"\n        \"shape; got operand of shape {}, target broadcast shape {}, \"\n        \"broadcast_dimensions {} \")\n    raise TypeError(msg.format(\n        tuple(core.replace_tracer_for_error_message(d) for d in operand.shape),\n        shape, broadcast_dimensions))\n  if len(broadcast_dimensions) != len(set(broadcast_dimensions)):\n    msg = (\"broadcast_in_dim broadcast_dimensions must not contain duplicates, \"\n           \"got broadcast_dimensions {}\")\n    raise TypeError(msg.format(broadcast_dimensions))\n  return shape\n\ndef _broadcast_in_dim_sharding_rule(operand, *, shape, broadcast_dimensions,\n                                    sharding):\n  if sharding is not None:\n    return sharding\n  bds = set(broadcast_dimensions)\n  orig_spec = iter(operand.sharding.spec.partitions)\n  new_spec = [next(orig_spec) if i in bds else None for i in range(len(shape))]\n  assert next(orig_spec, None) is None\n  mesh = (get_abstract_mesh() if operand.sharding.mesh.empty else\n          operand.sharding.mesh)\n  return operand.sharding.update(\n      mesh=mesh, spec=operand.sharding.spec.update(partitions=new_spec))\n\ndef _broadcast_in_dim_unreduced_rule(operand, sharding):\n  if sharding is not None and sharding.mesh.are_all_axes_explicit:\n    out = sharding.spec.unreduced","sourceCodeStart":6922,"sourceCodeEnd":6958,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/lax.py#L6922-L6958","documentation":"broadcast_dimensions must not repeat an index: each operand dim must map to a distinct output dim. Duplicate indices would make the mapping non-injective and the broadcast ambiguous.","triggerScenarios":"Calling broadcast_in_dim with e.g. broadcast_dimensions=(0, 0) or (1, 1, 2).","commonSituations":"Typing the same index twice when constructing index tuples by hand; generating indices with a buggy comprehension.","solutions":["Remove duplicates so each operand dim maps to a unique output dim","Build indices programmatically and assert len(set(bd)) == len(bd) before calling","Reconsider which output dims you actually intend each operand dim to align with"],"exampleFix":"// before\nx = jnp.zeros((2, 3))\ny = lax.broadcast_in_dim(x, (2, 3, 4), (0, 0))\n// after\ny = lax.broadcast_in_dim(x, (2, 3, 4), (0, 1))","handlingStrategy":"validation","validationCode":"assert len(set(broadcast_dimensions)) == len(broadcast_dimensions)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate index tuples programmatically, never by hand-repetition"],"tags":["jax","broadcast-in-dim","duplicate-index"],"backgroundTag":"invalid-broadcast-dimensions","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}