{"record":{"id":"442ffdbfc7b7c66d","repo":"jax-ml/jax","slug":"cannot-cast-from-dtype-name","errorCode":null,"errorMessage":"cannot cast from `{dtype_name}`","messagePattern":"cannot cast from `(.+?)`","errorType":"validation","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/triton/lowering.py","lineNumber":1685,"sourceCode":"  if isinstance(src.type, ir.RankedTensorType) and not isinstance(\n      dst_type, ir.RankedTensorType\n  ):\n    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(","sourceCodeStart":1667,"sourceCodeEnd":1703,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/triton/lowering.py#L1667-L1703","documentation":"Raised by the Triton Pallas lowering path in JAX when a cast (convert_element_type) has a source dtype that is not supported by the GPU's compute capability. The _UNSUPPORTED_CAST_DTYPES table lists dtypes (e.g. float8 variants, bfloat16 on older GPUs) whose is_supported(compute_capability) check fails, so the kernel cannot be lowered to Triton.","triggerScenarios":"Calling lax.convert_element_type (or a Pallas kernel that loads/stores/casts) with a source dtype such as f8e4m3/f8e5m2/bfloat16 on a GPU whose compute capability (e.g. pre-Hopper/Ada for fp8) does not support that type; also reached via _load/_store/_compute_offsets_from_indices which internally cast indices.","commonSituations":"Running fp8 kernels on Ampere or older GPUs; bf16 on very old GPUs; assuming JAX's default XLA path supports a dtype that the experimental Mosaic/Triton Pallas backend does not.","solutions":["Check your GPU compute capability and avoid fp8/bf16 source dtypes on unsupported hardware (fp8 needs Hopper/Ada+, sm89/sm90)","Convert the tensor to f32/f16 before passing it into the Triton Pallas kernel","Update JAX — support for more dtypes/casts is added over time in the Triton lowering","If the dtype is essential, fall back to the standard XLA backend instead of the Triton Pallas backend"],"exampleFix":"// before\nout = lax.convert_element_type(x, jnp.float8_e4m3fn)  # on sm80\n\n// after\nout = lax.convert_element_type(lax.convert_element_type(x, jnp.float16), jnp.float8_e4m3fn)  # or run on sm89+","handlingStrategy":"validation","validationCode":"from jax._src.pallas.triton import helpers\n# Before the kernel, gate on compute capability for exotic dtypes\nimport jax\ncc = jax.devices()[0].compute_capability\nFP8_OK = float(cc) >= 8.9\nassert FP8_OK or x.dtype not in (jnp.float8_e4m3fn, jnp.float8_e5m2), 'fp8 unsupported on this GPU'","typeGuard":"def cast_supported_on_device(dtype, cc: float) -> bool:\n    if dtype in (jnp.float8_e4m3fn, jnp.float8_e5m2):\n        return cc >= 8.9\n    if dtype == jnp.bfloat16:\n        return cc >= 8.0\n    return True","tryCatchPattern":"try:\n    kernel_lowered = triton_kernel(...)  \nexcept NotImplementedError as e:\n    if 'cannot cast' in str(e):\n        x = x.astype(jnp.float16)  # widen and retry","preventionTips":["Check GPU compute capability before running fp8/bf16 Pallas kernels","Keep kernel dtypes to f32/f16 unless hardware support is confirmed","Write a dtype-compatibility unit test that runs on CI's weakest GPU"],"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"}