jax-ml/jax · error · AttributeError
has no attribute
Error message
{self.__class__.__name__} has no attribute {name} What it means
Raised by Tracer.__getattr__ in JAX when you access an attribute that exists neither on the Tracer itself nor on the underlying abstract value (aval). JAX tracers only forward a fixed set of attributes from the aval; anything else (including array-only attributes like 'sharding', as the adjacent code notes) is rejected with AttributeError so transformations stay traceable. The chained 'from err' preserves the original AttributeError from the aval lookup.
Solutions
- Read the chained original error and the traceback to identify which attribute name was requested and on which tracer.
- If the attribute is only meaningful for materialized arrays (e.g. sharding, device, addressable_data), move that access outside the traced function or compute it before jit.
- If it's a typo, fix the attribute name; compare with the attribute list of the concrete array type you intended.
- Replace runtime introspection with jax.typeof(x) or the tracer's aval (x.aval) for shape/dtype/sharding info inside traces.
- Refactor the function so host-side Python logic (attribute checks) is not applied to traced values; use static arguments or pytrees instead of duck-typed attributes.
Example fix
// before
@jax.jit
def f(x):
return x.sharding # AttributeError: JVPTracer has no attribute sharding
// after
@jax.jit
def f(x):
print(jax.typeof(x)) # inspect abstract info instead
return x * 2 Defensive patterns
Strategy: type-guard
Validate before calling
import jax
def safe_getattr_traced(x, name, default=None):
if isinstance(x, jax.core.Tracer):
allowed = {'dtype','shape','ndim','size','weak_type','named_shape'}
if name not in allowed:
return default
return getattr(x, name, default) Type guard
from jax.core import Tracer
def is_tracer(x) -> bool:
return isinstance(x, Tracer)
def has_aval_attr(x, name) -> bool:
return hasattr(getattr(x, 'aval', x), name) Try / catch
try:
attr = getattr(x, name)
except AttributeError as e:
if 'has no attribute' in str(e) and isinstance(x, jax.core.Tracer):
# attribute is array-only / misspelled; take host-side path
attr = None
else:
raise Prevention
- Keep attribute introspection of arrays out of jitted/transformed functions.
- Prefer jax.typeof(x) or x.aval for shape/dtype/sharding info inside traces.
- Lint traced code for non-allowlisted attribute access on arguments.
- Run small smoke tests through the same transforms your production path uses.
When it happens
Trigger: Accessing an arbitrary attribute on a JAX-traced value inside jit/pmap/grad/vmap/scan, e.g. `x.sharding`, `x.some_custom_field`, or a typo like `x.shappe` where x is a Tracer. Also calling getattr(x, name) on a tracer for names not present on AbstractValue.
Common situations: Refactoring code that operated on concrete jax.Arrays into a jitted function; using NumPy-style attributes or custom attributes on arrays that don't exist on tracers; typos in attribute names that only surface under tracing; relying on x.sharding inside jit (JAX explicitly points you to jax.typeof).
Related errors
- raise_if_error() should not be called within a traced…
- The problem arose with the
- The unsafe_buffer_pointer() method was called on
- TracerBoolConversionError
- TracerIntegerConversionError
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/b313fde963c66b0b.
Report an issue: GitHub.
Appendix: source
Thrown at jax/_src/core.py:1190
# 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)
elif t is aval_method:
return types.MethodType(attr.fun, self)
else:
return attr
def _short_repr(self) -> str:
return f'{self.__class__.__name__}<{self.aval}>'
def _pretty_print(self, verbose: bool = False) -> pp.Doc:
if not verbose:
return pp.text(self._short_repr())
View on GitHub (pinned to 1e1c6a8fc0)