{"record":{"id":"bc5884f604c52a65","repo":"jax-ml/jax","slug":"op-has-name-of-an-unexpected-type-result","errorCode":null,"errorMessage":"{op} has {name} of an unexpected type: {result}","messagePattern":"(.+?) has (.+?) of an unexpected type: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/experimental/mosaic/gpu/inference_utils.py","lineNumber":90,"sourceCode":"  return _array_attr(op, \"in_tmem_layouts\")\n\n\ndef out_tmem_layouts(op: MlirOperation) -> Sequence[ir.Attribute]:\n  \"\"\"Returns the out_tmem_layouts attribute of the given operation.\n\n  Raises:\n    ValueError: If the operation does not have an out_tmem_layouts attribute.\n  \"\"\"\n  return _array_attr(op, \"out_tmem_layouts\")\n\n\ndef _array_attr(op: MlirOperation, name: str) -> Sequence[ir.Attribute]:\n  try:\n    result = op.attributes[name]\n  except KeyError:\n    raise ValueError(f\"{op} does not have an {name} attribute\") from None\n  if not isinstance(result, ir.ArrayAttr):\n    raise TypeError(f\"{op} has {name} of an unexpected type: {result}\")\n  return result  # pyrefly: ignore[bad-return]\n\n\ndef should_have_in_tmem_layout(op: MlirOperation) -> bool:\n  \"\"\"Returns 'true' if the operation operands should be assigned a TMEM layout.\"\"\"\n  return any(\n      isinstance(v.type, ir.MemRefType) and utils.is_tmem_ref(v)\n      for v in op.operands\n  )\n\n\ndef should_have_out_tmem_layout(op: MlirOperation) -> bool:\n  \"\"\"Returns 'true' if the operation results should be assigned a TMEM layout.\"\"\"\n  return any(\n      isinstance(v.type, ir.MemRefType) and utils.is_tmem_ref(v)\n      for v in op.results\n  )\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/mosaic/gpu/inference_utils.py#L72-L108","documentation":"_array_attr requires the named attribute (in_layouts, out_layouts, transforms, tmem layouts) to be an MLIR ir.ArrayAttr. If the attribute exists but has another type (e.g. a single layout attribute, a string, or a malformed encoding), a TypeError is raised showing the unexpected value. This usually indicates the op was serialized/parsed or constructed incorrectly.","triggerScenarios":"Calling in_layouts/out_layouts/in_transforms/out_transforms/in_tmem_layouts/out_tmem_layouts on an op whose attribute of that name is present but not an ir.ArrayAttr, e.g. a single layout object stored directly instead of a one-element array, or an attribute decoded from a mismatched MLIR context/version.","commonSituations":"Round-tripping MLIR through textual IR where an attribute got attached without array syntax ([...]); building ops with a helper that sets a bare attribute; version mismatch between the MLIR bindings and the Mosaic dialect definitions.","solutions":["Rebuild or re-attach the attribute as an ir.ArrayAttr, e.g. op.attributes['in_layouts'] = ir.ArrayAttr.get([layout_attr])","Inspect the printed attribute (the error message includes {result}) to identify why it is not an array and fix the construction site","If parsing textual MLIR, ensure array attributes use array syntax and the correct dialect types"],"exampleFix":"# before\nop.attributes['in_layouts'] = some_layout_attr  # not an ArrayAttr\n\n# after\nop.attributes['in_layouts'] = ir.ArrayAttr.get([some_layout_attr])","handlingStrategy":"type-guard","validationCode":"import iree.compiler.dialects.ir as ir\n\nattr = op.attributes.get('in_layouts')\nif attr is not None and not isinstance(attr, ir.ArrayAttr):\n  op.attributes['in_layouts'] = ir.ArrayAttr.get([attr])","typeGuard":"def is_array_attr(op, name) -> bool:\n  import iree.compiler.dialects.ir as ir\n  return isinstance(op.attributes.get(name), ir.ArrayAttr)","tryCatchPattern":"try:\n  layouts = inference_utils.in_layouts(op)\nexcept TypeError as e:\n  if 'unexpected type' in str(e):\n    op.attributes['in_layouts'] = ir.ArrayAttr.get([op.attributes['in_layouts']])\n    layouts = inference_utils.in_layouts(op)\n  else:\n    raise","preventionTips":["Always wrap single layout attributes in ir.ArrayAttr.get([...])","Validate attribute types after parsing/round-tripping MLIR text","Keep MLIR binding versions in sync with the Mosaic dialect"],"tags":["mosaic-gpu","mlir","type-mismatch","attribute-type","layout-inference"],"backgroundTag":"attribute-type-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}