jax-ml/jax · error · AttributeError

{self!r} has no `sharding`.

Error message

{self!r} has no `sharding`.

What it means

RefRValue.sharding raises AttributeError when the inner aval carries no sharding information (e.g. an unsharded or non-array aval).

Source

Thrown at jax/_src/state/types.py:548

      raise AttributeError(
          f"{self!r} has no `shape`."
      ) from None

  @property
  def dtype(self):
    try:
      return self.inner_aval.dtype  # pyrefly: ignore[missing-attribute]
    except AttributeError:
      raise AttributeError(
          f"{self!r} has no `dtype`."
      ) from None

  @property
  def sharding(self):
    try:
      return self.inner_aval.sharding  # pyrefly: ignore[missing-attribute]
    except AttributeError:
      raise AttributeError(
          f"{self!r} has no `sharding`."
      ) from None

  @property
  def manual_axis_type(self):
    try:
      return self.inner_aval.manual_axis_type  # pyrefly: ignore[missing-attribute]
    except AttributeError:
      raise AttributeError(
          f"{self!r} has no `manual_axis_type`."
      ) from None

  @property
  def mat(self):
    return self.manual_axis_type

  @core.aval_property
  def at(self):

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Use getattr(ref, 'sharding', None)
  2. Check inner_aval type first
  3. Only inspect sharding on refs known to be sharded
Defensive patterns

Strategy: type-guard

Type guard

def ref_has_sharding(ref):
    return hasattr(getattr(ref, "inner_aval", None), "sharding")

Prevention

When it happens

Trigger: Reading .sharding on a ref whose inner_aval doesn't expose a sharding property.

Common situations: Inspecting sharding in generic code across mixed ref types; refs created outside sharded contexts.

Related errors


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