jax-ml/jax · error · ValueError
Unsupported constant type: {x.type}
Error message
Unsupported constant type: {x.type} What it means
The Mosaic constant-folding helper only understands arith.constant ops with IntegerType or FloatType results. A constant of any other MLIR type (bool/i1 handled elsewhere, complex, etc.) raises ValueError when the folder tries to extract its value.
Source
Thrown at jax/_src/pallas/mosaic/lowering.py:3494
class FoldingError(Exception):
pass
def _fold(x, fuel):
if fuel <= 0:
raise FoldingError()
op_name = getattr(x.owner, "name", None)
binop_folds = {
"arith.maxsi": max,
"arith.minsi": min,
}
if op_name == "arith.constant":
if isinstance(x.type, ir.IntegerType):
return ir.IntegerAttr(x.owner.attributes["value"]).value
elif isinstance(x.type, ir.FloatType):
return ir.FloatAttr(x.owner.attributes["value"]).value
else:
raise ValueError(f"Unsupported constant type: {x.type}")
if op_name in binop_folds:
return binop_folds[op_name](_fold(v, fuel - 1) for v in x.owner.operands)
raise FoldingError()
def _fold_and_get_constant_value(x):
try:
return _fold(x, 10)
except FoldingError:
return None
@register_lowering_rule(lax.stop_gradient_p)
def _stop_gradient_lowering_rule(_: LoweringRuleContext, x):
return x
@register_lowering_rule(
lax.max_p, ensure_mlir_values=False, kernel_types=[*tpu_core.CoreType]View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Update jaxlib to match your JAX version — this is often an internal version-mismatch bug
- Simplify the kernel to avoid constants of exotic types reaching the folder (materialize them as kernel inputs)
- Replace bool constants with int32 0/1
- Report upstream at github.com/google/jax with a minimal repro
Example fix
// before flag = True # traced bool constant used in arithmetic // after flag = jnp.int32(1) # passed as kernel argument
Defensive patterns
Strategy: retry
Try / catch
catch ValueError from constant folding, simplify kernel constants, and retry; report if persistent
Prevention
- Keep jax and jaxlib versions in lockstep
- Avoid exotic-typed constants in kernels
- Materialize unusual constants as kernel inputs
When it happens
Trigger: Constant folding encountering an arith.constant with a non-integer/non-float MLIR type while lowering a Pallas kernel, typically triggered indirectly by an operation whose operands fold to unusual constants.
Common situations: Kernels with boolean constants feeding into arithmetic; complex or index-type constants; version skew between JAX and jaxlib where new constant types appear in the pipeline.
Related errors
- Unsupported block shape type: {type(dim)}
- BlockMapping for {self.origin} has captured constants: {self
- Unsupported aval type: {aval}, {type(aval)}, {t}
- cannot cast {src} to {dst_type}
- Unexpected dim_block_size: {dim_block_size}
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/2c775d09c3bcb66e.
Report an issue: GitHub.