{"record":{"id":"4ed3e6b607b1bebd","repo":"jax-ml/jax","slug":"cannot-broadcast-shape-self-shape-to-layout-o-l","errorCode":null,"errorMessage":"Cannot broadcast shape {self.shape} to layout {o.layout}","messagePattern":"Cannot broadcast shape (.+?) to layout (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/mosaic/gpu/fragmented_array.py","lineNumber":1495,"sourceCode":"        return self.broadcast(output_shape)._pointwise(\n            op, *other, output_is_signed=output_is_signed\n        )\n\n    other_arrs = []\n    for o in other:\n      if not isinstance(o, FragmentedArray):\n        if isinstance(o, (float, int)):\n          o = utils.c(o, self.mlir_dtype)\n        elif not isinstance(o, ir.Value):\n          raise NotImplementedError(o)\n\n        o = FragmentedArray.splat(\n            o, shape=self.shape, layout=self.layout, is_signed=self.is_signed\n        )\n\n      if isinstance(o.layout, WGSplatFragLayout):\n        if not o.layout.can_broadcast_to(self.shape):\n          raise ValueError(\n              f\"Cannot broadcast shape {self.shape} to layout {o.layout}\")\n        o = FragmentedArray.splat(\n            o.registers.flat[0],\n            shape=self.shape,\n            layout=self.layout,\n            is_signed=o.is_signed,\n        )\n      else:\n        if self.layout != o.layout:\n          raise ValueError(\"Incompatible FragmentedArray layouts\")\n        if self.registers.shape != o.registers.shape:\n          raise ValueError(\"Incompatible FragmentedArray shapes\")\n\n      other_arrs.append(o)\n    new_regs = np.empty_like(self.registers)\n\n    for idx, reg in np.ndenumerate(self.registers):\n      new_regs[idx] = op(reg, *(o.registers[idx] for o in other_arrs))","sourceCodeStart":1477,"sourceCodeEnd":1513,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/mosaic/gpu/fragmented_array.py#L1477-L1513","documentation":"In _pointwise, when the other operand is a splat (WGSplatFragLayout), the library tries to materialize it at self's shape via WGSplatFragLayout.can_broadcast_to. If self.shape is not broadcast-compatible with the splat's layout shape, broadcasting is impossible and ValueError is raised.","triggerScenarios":"Combining a FragmentedArray with a splat constant whose stored layout shape doesn't broadcast to self.shape, e.g. adding a splat of shape (8, 16) to an array of shape (8,) or (16, 8) with mismatched leading dims, or shape (3,) against layouts implying power-of-two shapes.","commonSituations":"Adding bias/scale splats built with a different tile shape than the accumulation array; reusing constants across kernels with different tiling; constructing splats from scalars with an explicit stale shape argument.","solutions":["Recreate the splat with a shape that broadcasts: FragmentedArray.splat(value, shape=self.shape, ...) or shape=()","Reshape/expand self so the dims align with the splat's layout shape","Verify tile-shape consistency between constants and operands before fusing ops"],"exampleFix":"# before\nbias = FragmentedArray.splat(b, shape=(1, 64), layout=L)\nz = x + bias  # x.shape == (64,)\n# after\nbias = FragmentedArray.splat(b, shape=x.shape, layout=x.layout)\nz = x + bias","handlingStrategy":"validation","validationCode":"if isinstance(o.layout, WGSplatFragLayout):\n    assert o.layout.can_broadcast_to(x.shape), f\"{o.layout} cannot broadcast to {x.shape}\"","typeGuard":null,"tryCatchPattern":"try:\n    z = x + o\nexcept ValueError as e:\n    if 'Cannot broadcast' in str(e):\n        o = FragmentedArray.splat(o.registers.flat[0], shape=x.shape, layout=x.layout)\n        z = x + o\n    else:\n        raise","preventionTips":["Build splat constants with shape=x.shape (or ()) of the operand they combine with","Keep constant tile shapes in one config shared by the whole kernel"],"tags":["jax","mosaic-gpu","broadcasting","splat-layout","shape-mismatch"],"backgroundTag":"broadcast-shape-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}