jax-ml/jax · error · AttributeError

{self!r} has no `dtype`.

Error message

{self!r} has no `dtype`.

What it means

TransformedRef.dtype raises AttributeError when the transformed type has no dtype attribute. Since bitcast reads .dtype, calling bitcast on such a ref surfaces this error.

Source

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

    if self.multiref:
      ref_ty = tuple(_type(r) for r in self.ref)
      return cast(MultiRefTransform, self.transforms[0]).transform_types(ref_ty)
    ref_ty = _type(self.ref)
    for t in self.transforms:
      ref_ty = t.transform_type(ref_ty)
    return ref_ty

  @property
  def shape(self) -> tuple[int | Array, ...]:
    if not hasattr(self.type, "shape"):
      raise AttributeError(f"{self!r} has no `shape`.") from None
    return self.type.shape

  @property
  def dtype(self):
    if not hasattr(self.type, "dtype"):
      raise AttributeError(f"{self!r} has no `dtype`.") from None
    return self.type.dtype

  ndim = property(lambda self: len(self.shape))
  size = property(lambda self: math.prod(self.shape))
  T = property(lambda self: self.transpose(tuple(reversed(range(self.ndim)))))

  @property
  def at(self) -> RefIndexer:
    return RefIndexer(self)

  def bitcast(self, dtype):
    if self.is_dynamic_size:
      raise NotImplementedError(
          "Bitcast ref with dynamic size is not supported."
      )
    dtype = dtypes.dtype(dtype)
    if self.multiref:
      return TransformedRef(self, (BitcastTransform(dtype),))

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Verify the ref's type is array-backed before bitcast
  2. Use hasattr/getattr guard on .dtype
  3. Inspect ref.type to understand the transformed aval

Example fix

// before
ref.bitcast(jnp.int32)
// after
if hasattr(ref.type, "dtype"):
    ref.bitcast(jnp.int32)
Defensive patterns

Strategy: type-guard

Type guard

def has_dtype(ref):
    return hasattr(getattr(ref, "type", ref), "dtype")

Prevention

When it happens

Trigger: Calling .bitcast(dtype) or accessing .dtype on a ref whose aval has no dtype (non-array aval after transforms).

Common situations: Bitcasting refs wrapped around non-standard avals; utility code assuming array-like dtype presence.

Related errors


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