{"record":{"id":"8d6fd06c8a70fbec","repo":"jax-ml/jax","slug":"expected-0d-shape-but-got-fa-shape","errorCode":null,"errorMessage":"Expected 0D shape, but got {fa.shape}","messagePattern":"Expected 0D shape, but got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic_gpu/primitives.py","lineNumber":3848,"sourceCode":"    ):\n      if not isinstance(fa, mgpu.FragmentedArray):\n        raise ValueError(f\"Expected a FragmentedArray, but got: {fa}\")\n      if isinstance(result_ty, ir.VectorType):\n        result_shape = ir.VectorType(result_ty).shape\n        if fa.shape != tuple(result_shape):\n          raise ValueError(f\"Expected {result_shape} but got {fa.shape}\")\n        if out_layout != mgpu.layouts.to_layout_attr(fa.layout):\n          raise ValueError(\n              f\"Output layout {out_layout} does not match the layout of the\"\n              f\" returned fragmented array {fa.layout}.\"\n          )\n        ir_ret.append(\n            mgpu.dialect_lowering.fragmented_array_to_ir(fa, result_ty)\n        )\n      else:  # scalar case.\n        assert out_layout is None\n        if fa.shape:\n          raise ValueError(f\"Expected 0D shape, but got {fa.shape}\")\n        if not isinstance(fa.layout, mgpu.WGSplatFragLayout):\n          raise ValueError(f\"Expected WGSplatFragLayout, but got {fa.layout}\")\n        value = fa.registers.item()\n        ir_ret.append(value)\n\n    mgpu.dialect.return_(ir_ret)\n\n\n@lowering.register_lowering_rule(inline_mgpu_p, mgpu.LoweringSemantics.Warpgroup)\n@lowering.register_lowering_rule(inline_mgpu_p, *gpu_core.WGxWARP_SEMANTICS)\ndef _inline_mgpu_lowering_rule_wg_semantics(\n    ctx: lowering.LoweringRuleContext,\n    *flat_args_and_transforms,\n    mgpu_fn: Callable[..., Any],\n    flat_arg_types,\n    flat_ret_ty,\n    pytree_args,\n    pytree_ref_transforms,","sourceCodeStart":3830,"sourceCodeEnd":3866,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic_gpu/primitives.py#L3830-L3866","documentation":"For scalar-typed outputs of inline_mgpu, the returned FragmentedArray must be 0D. A non-empty shape on a value declared as scalar raises this ValueError.","triggerScenarios":"Declaring an output as scalar (empty-shape ShapeDtypeStruct) while the callback returns a FragmentedArray with a non-empty shape.","commonSituations":"Forgetting to reduce an array result to a scalar; shape bookkeeping errors in the output type list.","solutions":["Reduce the value to a scalar inside the callback, or declare the output with its true shape"],"exampleFix":"// before\nret_ty = jax.ShapeDtypeStruct((), jnp.float32)  # callback returns (4,)\n// after\ninline_mgpu(lambda x: jnp.sum(x), x)  # scalar returned","handlingStrategy":"validation","validationCode":"assert not fa.shape, fa.shape  # scalar output must be 0D","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reduce arrays to scalars before returning scalar-typed outputs"],"tags":["jax","pallas","scalar","shape-mismatch"],"backgroundTag":"shape-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}