jax-ml/jax · error · TypeError

Cannot resolve attribute {name} from: {attrs}

Error message

Cannot resolve attribute {name} from: {attrs}

What it means

SelectTransform.getattr raises TypeError when the requested attribute differs across the elements (e.g. shapes differ across refs), so a single consistent value can't be returned.

Source

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

          raise TypeError(f"Cannot select {ref}")

    assert isinstance(xs, Sequence), f"Select expected sequence, got {xs}"
    types = tuple(_type(ref) for ref in xs)
    if any(types[0] != t for t in types[1:]):
      raise TypeError(f"Cannot select from Refs of different types: {types}")
    return types[0]

  def undo(self, x: core.AbstractValue) -> Transform:
    raise NotImplementedError(type(self))

  def pretty_print(self, context: core.JaxprPpContext) -> pp.Doc:
    del context  # Unused.
    return pp.text(f"{{select({self.idx=})}}")

  def getattr(self, name: str, xs: Sequence[core.AbstractValue]) -> Any:
    attrs = [getattr(x, name) for x in xs]
    if any(attrs[0] != attr for attr in attrs[1:]):
      raise TypeError(f"Cannot resolve attribute {name} from: {attrs}")
    return attrs[0]


@dataclasses.dataclass(slots=True)
class RefIndexer:
  """An object temporarily generated when doing ``ref.at``."""
  ref_or_view: Any

  def __getitem__(self, slc) -> TransformedRef:
    if not isinstance(slc, tuple):
      slc = (slc,)
    from jax._src.state import indexing
    indexer = indexing.NDIndexer.from_indices_shape(slc, self.ref_or_view.shape)
    if (
        isinstance(self.ref_or_view, TransformedRef)
        and not self.ref_or_view.multiref
    ):
      view = self.ref_or_view

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Ensure all refs in the multiref share the attribute value
  2. Query each ref individually instead of the group
  3. Normalize shapes/dtypes at construction time
Defensive patterns

Strategy: validation

Validate before calling

shapes = {r.shape for r in refs}
assert len(shapes) == 1

Prevention

When it happens

Trigger: Accessing an aggregate property like shape or dtype on a multiref whose refs disagree on that attribute.

Common situations: Querying .shape on grouped refs after one was reshaped or created with different dimensions.

Related errors


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