jax-ml/jax · error · AttributeError

The '{name}' method is not available on {self._error_repr()}

Error message

The '{name}' method is not available on {self._error_repr()}.{self._origin_msg()}

What it means

Raised by JAXTracer.__getattr__ when code calls block_until_ready() or copy_to_host_async() on a JAX Tracer. These methods exist on concrete, dispatched jax.Array objects (which are backed by device buffers) but are meaningless for abstract tracer values recorded during jit/grad/vmap tracing, so attribute lookup is blocked with an AttributeError for backward compatibility.

Source

Thrown at jax/_src/core.py:1178

  def __setitem__(self, key, value):
    if not hasattr(self.aval, "_setitem"):
      raise TypeError(f"Value of type {type(self)} is not indexable.")
    return self.aval._setitem(self, key, value)

  # NumPy also only looks up special methods on classes.
  def __array_module__(self, types):
    if not hasattr(self.aval, "_array_module"):
      raise TypeError(f"Value of type {type(self)} is not compatible with the Array API.")
    return self.aval._array_module(self, types)

  def __getattr__(self, name):
    # if the aval property raises an AttributeError, gets caught here
    assert not config.enable_checks.value or name != "aval"

    # These must raise AttributeError in the base class for backward compatibility.
    # TODO(jakevdp): can we change this and make them raise NotImplementedError instead?
    if name in ["block_until_ready", "copy_to_host_async"]:
      raise AttributeError(
        f"The '{name}' method is not available on {self._error_repr()}."
        f"{self._origin_msg()}")

    if name == 'sharding':
      raise AttributeError(
        f"The 'sharding' attribute is not available on {self._error_repr()}. "
        "To query sharding information on tracers, use `jax.typeof(x)`.")

    try:
      attr = getattr(self.aval, name)
    except AttributeError as err:
      raise AttributeError(
          f"{self.__class__.__name__} has no attribute {name}"
      ) from err
    else:
      t = type(attr)
      if t is aval_property:
        return attr.fget(self)

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Only call block_until_ready()/copy_to_host_async() on concrete outputs after the transformation has run, never inside traced code.
  2. Guard with isinstance(x, jax.Array) (or type(x) is not a Tracer) before calling sync methods in generic helpers.
  3. For timing jitted code, time the returned concrete array: y = f(x); y.block_until_ready().
  4. Use jax.debug.print / jax.block_until_ready() top-level helpers rather than method calls on possibly-traced values.

Example fix

# before
@jax.jit
def f(x):
    y = x * 2
    y.block_until_ready()   # AttributeError on Tracer
    return y

# after
@jax.jit
def f(x):
    return x * 2
y = f(x)
y.block_until_ready()       # concrete jax.Array: fine
Defensive patterns

Strategy: type-guard

Validate before calling

import jax
def sync_if_concrete(x):
    if isinstance(x, jax.Array) and not isinstance(x, jax.core.Tracer):
        x.block_until_ready()
    return x

Type guard

import jax
def is_syncable_array(x) -> bool:
    return isinstance(x, jax.Array) and not isinstance(x, jax.core.Tracer)

Prevention

When it happens

Trigger: Calling x.block_until_ready() or x.copy_to_host_async() on a value produced inside a jax.jit/jax.grad/jax.vmap/scan/cond traced function; timing helpers or async-machinery shims applied uniformly to 'array-like' objects that turn out to be tracers; decorators that force synchronization on all returned arrays.

Common situations: Profiling/timing utility code that calls block_until_ready() on every array it sees, executed on traced intermediates; wrapping jitted functions with generic 'sync after op' plumbing; custom __getattr__ forwarding layers that surface these names on tracers.

Related errors


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