jax-ml/jax · error · AttributeError

{self!r} has no `sharding`.

Error message

{self!r} has no `sharding`.

What it means

A wrapper aval's .shape property delegates to inner_aval; when the inner aval has no shape (e.g. an abstract token or a ref of a non-shaped type), AttributeError is re-raised with a slightly misleading message saying the wrapper 'has no sharding'. It means the underlying value has no array shape at all.

Source

Thrown at jax/_src/core.py:3129

  def __hash__(self):
    return hash(self.inner_aval)

  def str_short(self, short_dtypes=False, mesh_axis_types=False) -> str:
    return f'AbstractFuture{{{self.inner_aval.str_short(True)}}}'

  ndim = property(lambda self: len(self.shape))
  size = property(lambda self: math.prod(self.shape))

  @aval_method
  def done(tracer):
    return tracer.aval.done_fun(tracer)  # type: ignore

  @property
  def shape(self):
    try:
      return self.inner_aval.shape
    except AttributeError:
      raise AttributeError(f"{self!r} has no `sharding`.") from None

  @property
  def dtype(self):
    try:
      return self.inner_aval.dtype
    except AttributeError:
      raise AttributeError(f"{self!r} has no `sharding`.") from None

  @property
  def sharding(self):
    try:
      return self.inner_aval.sharding
    except AttributeError:
      raise AttributeError(f"{self!r} has no `sharding`.") from None

  @property
  def manual_axis_type(self):
    try:

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Skip shape access for token/ref avals (check a is abstract_token or hasattr(inner, 'shape'))
  2. Restrict shape-touching code to ShapedArray instances
  3. Guard with getattr(aval, 'shape', None)

Example fix

// before
shapes = [a.shape for a in avals]  # crashes on tokens

// after
shapes = [a.shape for a in avals if hasattr(a.inner_aval, 'shape')]
Defensive patterns

Strategy: type-guard

Type guard

def aval_has_shape(a):
    return hasattr(getattr(a, 'inner_aval', a), 'shape')

Try / catch

try:
    s = a.shape
except AttributeError:
    s = None  # token-like operand

Prevention

When it happens

Trigger: Calling .shape on an aval wrapping an abstract token or similar shapeless value, e.g. AbstractRef/AbstractToken accessed through generic aval code.

Common situations: Generic code (logging, assertions) calling .shape/.dtype on every operand including tokens/refs; custom primitives receiving token arguments.

Related errors


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