{"record":{"id":"ca4ac1e0fcdc8642","repo":"jax-ml/jax","slug":"unsupported-preferred-element-type","errorCode":null,"errorMessage":"Unsupported {preferred_element_type=}","messagePattern":"Unsupported (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic/lowering.py","lineNumber":2904,"sourceCode":"      if ctx.avals_in[0].shape != bcast_shape:\n        x = vector.broadcast(bcast_shape, x)\n      if ctx.avals_in[1].shape != bcast_shape:\n        y = vector.broadcast(bcast_shape, y)\n    red_dtype = (\n        preferred_element_type if preferred_element_type else lhs_aval.dtype\n    )\n    red_type = ctx.aval_to_ir_type(\n        lhs_aval.update(shape=(lhs_aval.shape[0],), dtype=red_dtype),\n    )\n\n    if lhs_aval.dtype != red_dtype:\n      lhs_type = ctx.aval_to_ir_type(\n          lhs_aval.update(shape=lhs_aval.shape, dtype=red_dtype),\n      )\n      if red_dtype == jnp.float32:\n        x = arith.extf(lhs_type, x)\n      else:\n        raise NotImplementedError(f\"Unsupported {preferred_element_type=}\")\n\n    if rhs_aval.dtype != red_dtype:\n      rhs_type = ctx.aval_to_ir_type(\n          rhs_aval.update(shape=rhs_aval.shape, dtype=red_dtype),\n      )\n      if red_dtype == jnp.float32:\n        y = arith.extf(rhs_type, y)\n      else:\n        raise NotImplementedError(f\"Unsupported {preferred_element_type=}\")\n\n    acc = arith.constant(\n        red_type, ir.DenseElementsAttr.get_splat(red_type, val)\n    )\n    red = vector.multi_reduction(\n        ir.Attribute.parse(\"#vector.kind<add>\"),\n        arith.mulf(x, y),\n        acc,\n        [1]","sourceCodeStart":2886,"sourceCodeEnd":2922,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic/lowering.py#L2886-L2922","documentation":"When a dot_general prefers a wider accumulation dtype, Mosaic only knows how to extend float inputs to float32. If the LHS reduction dtype is not float32 (e.g. extending bf16 to something else, or an integer promotion), it raises with the offending preferred_element_type.","triggerScenarios":"Calling lax.dot_general with preferred_element_type set to something other than float32 while the lhs is lower-precision (e.g. bf16 lhs with a non-f32 preferred type), inside a Pallas Mosaic kernel.","commonSituations":"Setting preferred_element_type=int32 or float64 for mixed-precision matmuls on TPU; mirroring XLA-only accumulation tricks in Pallas.","solutions":["Drop preferred_element_type and let Mosaic use default accumulation","Use preferred_element_type=jnp.float32 with bf16/f16 inputs","Do the widening manually: compute at input dtype then astype the result"],"exampleFix":"// before\nout = lax.dot_general(a_bf16, b_bf16, ..., preferred_element_type=jnp.int32)\n// after\nout = lax.dot_general(a_bf16, b_bf16, ..., preferred_element_type=jnp.float32)","handlingStrategy":"validation","validationCode":"import jax.numpy as jnp\npreferred = None if preferred is None or preferred == jnp.float32 else jnp.float32  # normalize before dot","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use preferred_element_type=jnp.float32 in Mosaic kernels","Omit preferred_element_type unless you verified support"],"tags":["jax","pallas","tpu","dot-general","preferred-element-type","mixed-precision"],"backgroundTag":"unsupported-mixed-precision-accumulation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}