{"record":{"id":"fc1eb1150ac98ef2","repo":"jax-ml/jax","slug":"array-shape-mismatch-expected-ty-shape-got-v-s","errorCode":null,"errorMessage":"Array shape mismatch: expected {ty.shape} got {v.shape}.","messagePattern":"Array shape mismatch: expected (.+?) got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic_gpu/primitives.py","lineNumber":3533,"sourceCode":"\n@discharge.register_discharge_rule(inline_mgpu_p)\ndef _inline_mgpu_discharge(*args, **kwargs):\n  del args, kwargs\n  raise NotImplementedError(\"inline_mgpu_p does not support discharge.\")\n\n\ndef _type_check_mgpu_lane_semantics(v, ty):\n  match (ty, v):\n    case (RefType(), ir.Value()) if isinstance(v.type, ir.MemRefType):\n      pass\n    case (ShapeDtypeStruct(), mgpu.FragmentedArray()):\n      mlir_dtype = mgpu_utils.dtype_to_ir_type(ty.dtype)\n      if v.mlir_dtype != mlir_dtype:\n        raise ValueError(\n            f\"Array dtype mismatch: expected {v.mlir_dtype} got {mlir_dtype}.\"\n        )\n      if ty.shape != v.shape:\n        raise ValueError(\n            f\"Array shape mismatch: expected {ty.shape} got {v.shape}.\"\n        )\n      if v.layout != ty.layout.to_mgpu():\n        raise ValueError(\n            f\"Array layout mismatch: expected {v.layout} got {ty.layout.to_mgpu()}.\"\n        )\n    case (SomeLayout(), mgpu.FragmentedArray()):\n      if ty.to_mgpu() != v.layout:\n        raise ValueError(f\"Unexpected layout for {v} (expected: {ty})\")\n    case _:\n      raise ValueError(f\"Unexpected type {ty} for value {v}\")\n\n\ndef _inline_mgpu_flat_transformed_args(\n    ctx: lowering.LoweringRuleContext,\n    flat_args_and_transforms,\n    flat_arg_types,\n    pytree_args,","sourceCodeStart":3515,"sourceCodeEnd":3551,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic_gpu/primitives.py#L3515-L3551","documentation":"Same per-argument type check as the dtype case, but for shapes: the FragmentedArray's runtime shape must equal the shape declared in the ShapeDtypeStruct passed to inline_mgpu.","triggerScenarios":"Declaring ShapeDtypeStruct((16,16), dtype) while the wrapped function emits a FragmentedArray of shape (16,32), or returning a scalar where an array was declared.","commonSituations":"Hard-coding block shapes that later change when block specs are updated.","solutions":["Update the declared shape to the actual produced shape","Reshape/splat the output inside the wrapped function to the declared shape"],"exampleFix":"# before\nreturn_type=ShapeDtypeStruct((16,16), dt)\n# after\nreturn_type=ShapeDtypeStruct((16,32), dt)  # matches actual output","handlingStrategy":"validation","validationCode":"assert v.shape == declared.shape","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive declared shapes from block specs rather than hard-coding","Assert output shapes in kernel unit tests"],"tags":["jax","pallas","inline-mgpu","shape-mismatch"],"backgroundTag":"shape-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}