jax-ml/jax · error · TracerIntegerConversionError

TracerIntegerConversionError

Error message

TracerIntegerConversionError

What it means

TracerIntegerConversionError is raised when hex(), oct(), or operator.index() (implicit integer conversion, e.g., list indexing) is applied to a Tracer. Python needs a concrete int, but the Tracer's value is unknown during tracing.

Source

Thrown at jax/_src/core.py:2041

def to_concrete_value(x):
  if isinstance(x, Tracer):
    return x.to_concrete_value()
  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)

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Index JAX arrays instead of Python lists (convert list to jnp.array first)
  2. Use jax.lax.fori_loop / lax.dynamic_slice / lax.dynamic_update_slice for dynamic indexing
  3. Hoist the index computation outside the traced function and pass a concrete int
  4. Use jax.debug.print instead of hex()/bin() for debugging

Example fix

# before
@jax.jit
def get(i):
    return my_python_list[i]  # TracerIntegerConversionError

# after
arr = jnp.array(my_python_list)
@jax.jit
def get(i):
    return arr[i]  # or lax.dynamic_index / dynamic_slice
Defensive patterns

Strategy: validation

Validate before calling

import jax
def ensure_concrete_index(i):
    if isinstance(i, jax.core.Tracer):
        raise TypeError('index must be concrete; use lax.dynamic_slice')
    return int(i)

Type guard

def is_concrete_int(i) -> bool:
    import jax; return not isinstance(i, jax.core.Tracer) and isinstance(i, (int, np.integer))

Prevention

When it happens

Trigger: Using a traced scalar as a list index (data[idx]), in range(), in hex()/oct(), or anywhere Python calls __index__ on a value inside a jitted function.

Common situations: Indexing Python lists/tuples with traced loop counters inside jit; passing traced ints to bin(i) for debugging; using traced values in slicing of Python objects.

Related errors


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