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
- Verify the ref's type is array-backed before bitcast
- Use hasattr/getattr guard on .dtype
- 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
- Check .type.dtype before bitcast
- Validate ref aval kinds in helpers
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
- primal and tangent arguments to jax.jvp do not match; dtypes
- unexpected JAX type (e.g. shape/dtype) for gradient ref pass
- Accumulator aval mismatch: expected {aval}, got {acc.aval}
- unexpected JAX type (e.g. shape/dtype) for argument to VJP f
- linear_transpose only supports [float or complex] -> [float
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/51c744e952304158.
Report an issue: GitHub.