jax-ml/jax · error · ConcretizationTypeError

The problem arose with the `{fname}` function.

Error message

The problem arose with the `{fname}` function. 

What it means

This is the ConcretizationTypeError raised by concrete_or_error when a non-bool/non-int builtin (e.g., float(), len(), str()) is applied to a Tracer; the message includes 'The problem arose with the `{fname}` function.' explaining which conversion forced concreteness.

Source

Thrown at jax/_src/core.py:2044

  else:
    return x

def concretization_function_error(fun, suggest_astype=False):
  fname = getattr(fun, "__name__", fun)
  fname_context = f"The problem arose with the `{fname}` function. "
  if suggest_astype:
    fname_context += ("If trying to convert the data type of a value, "
                      f"try using `x.astype({fun.__name__})` "
                      f"or `jnp.array(x, {fun.__name__})` instead.")
  if fun is bool:
    def error(self, arg):
      raise TracerBoolConversionError(arg)
  elif fun in (hex, oct, operator.index):
    def error(self, arg):
      raise TracerIntegerConversionError(arg)
  else:
    def error(self, arg):
      raise ConcretizationTypeError(arg, fname_context)
  return error

def concrete_or_error(force: Any, val: Any, context=""):
  """Like force(val), but gives the context in the error message."""
  if force is None:
    force = lambda x: x
  if isinstance(val, Tracer):
    maybe_concrete = val.to_concrete_value()
    if maybe_concrete is None:
      raise ConcretizationTypeError(val, context)
    else:
      return force(maybe_concrete)
  else:
    return force(val)

def concrete_dim_or_error(val: Any, context=""):
  """Like concrete_or_error(operator.index), allowing symbolic dimensions."""
  if is_symbolic_dim(val):

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Move the concrete conversion (float/len/str) outside the traced function
  2. Use jax.debug.print or .item() after the jit call returns for logging
  3. Use static arguments or x.shape known at trace time instead of len(tracer)
  4. Replace Python print of tracers with jax.debug.print inside traces

Example fix

# before
@jax.jit
def f(x):
    print(f"value: {float(x)}")
    return x * 2

# after
@jax.jit
def f(x):
    jax.debug.print("value: {x}", x=x)
    return x * 2
Defensive patterns

Strategy: try-catch

Validate before calling

import jax
def concrete(x):
    return None if isinstance(x, jax.core.Tracer) else float(x)

Type guard

def is_tracer(x) -> bool:
    import jax; return isinstance(x, jax.core.Tracer)

Try / catch

try:
    val = float(x)
except jax.errors.ConcretizationTypeError as e:
    logging.warning('tracer concretized: %s', e)
    val = None

Prevention

When it happens

Trigger: concrete_or_error(force, tracer) being invoked because user code called float(x), len(x), format(x), or similar on a Tracer inside a jax.jit/grad/vmap transformation.

Common situations: Calling float() on traced scalars for logging; len() on traced shapes assumed static; str() interpolation of tracers in f-strings inside traced code.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/d1058338c070e8d3. Report an issue: GitHub.