{"record":{"id":"9c0836167d9cc63a","repo":"jax-ml/jax","slug":"cannot-cast-to-dtype-name","errorCode":null,"errorMessage":"cannot cast to `{dtype_name}`","messagePattern":"cannot cast to `(.+?)`","errorType":"validation","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/triton/lowering.py","lineNumber":1688,"sourceCode":"    src_type = ir.RankedTensorType(src.type)\n    dst_type = ir.RankedTensorType.get(\n        src_type.shape,\n        dst_type,\n        src_type.encoding,\n    )\n  if src.type == dst_type:\n    return src\n\n  src_element_type = _element_type(src.type)\n  dst_element_type = _element_type(dst_type)\n\n  for dtype, dtype_name, is_supported in _UNSUPPORTED_CAST_DTYPES:\n    if isinstance(src_element_type, dtype):\n      if not is_supported(compute_capability):\n        raise NotImplementedError(f\"cannot cast from `{dtype_name}`\")\n    if isinstance(dst_element_type, dtype):\n      if not is_supported(compute_capability):\n        raise NotImplementedError(f\"cannot cast to `{dtype_name}`\")\n\n  if isinstance(src_element_type, (ir.F16Type, ir.BF16Type)) and not isinstance(\n      dst_element_type, ir.F32Type\n  ):\n    return _ir_cast(\n        _ir_cast(src, ir.F32Type.get(), signed=False),\n        dst_type, signed=False, dst_signed=dst_signed\n    )\n\n  if isinstance(src_element_type, ir.FloatType) and isinstance(\n      dst_element_type, ir.FloatType\n  ):\n    return _float_float_cast(src, dst_type)\n\n  if isinstance(src_element_type, ir.IntegerType) and isinstance(\n      dst_element_type, ir.IntegerType\n  ):\n    return _int_int_cast(src, dst_type, signed=signed)","sourceCodeStart":1670,"sourceCodeEnd":1706,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/triton/lowering.py#L1670-L1706","documentation":"Same _ir_cast check as the source-dtype variant, but here the destination element type is a dtype unsupported at the GPU's compute capability. The lowering refuses to emit a Triton cast to that type because the hardware cannot execute it natively.","triggerScenarios":"Casting a value TO an unsupported dtype (e.g. float8_e4m3fn, float8_e5m2) inside a Triton Pallas kernel on a GPU below the required compute capability; reached via _cast, _load with `other`, masked loads/stores, or offset computation casting to the index type.","commonSituations":"Quantization-style kernels writing fp8 outputs on Ampere or older GPUs; kernels ported from Triton-lang code that assume newer hardware; CI on older GPUs failing while dev machines with H100 pass.","solutions":["Cast to the dtype outside the kernel (on the XLA side) or after the store, keeping the kernel in f16/f32/bf16","Move execution to a GPU with sufficient compute capability for the target dtype","Upgrade JAX to a version with wider fp8 cast support in the Triton lowering","Restructure the kernel to store the wider type and bit-cast later if semantics allow"],"exampleFix":"// before\nout_ref[...] = x.astype(jnp.float8_e4m3fn)  # inside kernel on sm80\n\n// after\nout_ref[...] = x.astype(jnp.float16)  # cast to fp8 outside the kernel","handlingStrategy":"validation","validationCode":"dst = jnp.float8_e4m3fn\ncc = float(jax.devices()[0].compute_capability)\nif dst in (jnp.float8_e4m3fn, jnp.float8_e5m2) and cc < 8.9:\n    dst = jnp.float16  # degrade gracefully inside the kernel","typeGuard":"def output_dtype_ok(dst_dtype, cc: float) -> bool:\n    return not (dst_dtype in (jnp.float8_e4m3fn, jnp.float8_e5m2) and cc < 8.9)","tryCatchPattern":"try:\n    out_ref[...] = x.astype(fp8_dtype)\nexcept NotImplementedError:\n    out_ref[...] = x.astype(jnp.float16)  # fallback store","preventionTips":["Do quantization to fp8 outside the kernel on older GPUs","Parameterize kernel output dtype so tests can downgrade it per-device","Document hardware requirements next to kernels using narrow dtypes"],"tags":["jax","triton","pallas","dtype","cast","gpu"],"backgroundTag":"unsupported-dtype-cast","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}