{"record":{"id":"dde88f443c1c9bcb","repo":"jax-ml/jax","slug":"cannot-select-ref","errorCode":null,"errorMessage":"Cannot select {ref}","messagePattern":"Cannot select (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/state/types.py","lineNumber":248,"sourceCode":"  def pretty_print(self, context: core.JaxprPpContext) -> pp.Doc:\n    del context  # Unused.\n    return pp.text(f\"{{transpose({list(self.permutation)})}}\")\n\n\n@tree_util.register_dataclass\n@dataclasses.dataclass(frozen=True, slots=True)\nclass SelectTransform(MultiRefTransform):\n  idx: Array | int\n\n  def transform_types(self, xs):\n    def _type(ref):\n      match ref:\n        case AbstractRef():\n          return ref\n        case core.ShapedArray():\n          raise NotImplementedError\n        case _:\n          raise TypeError(f\"Cannot select {ref}\")\n\n    assert isinstance(xs, Sequence), f\"Select expected sequence, got {xs}\"\n    types = tuple(_type(ref) for ref in xs)\n    if any(types[0] != t for t in types[1:]):\n      raise TypeError(f\"Cannot select from Refs of different types: {types}\")\n    return types[0]\n\n  def undo(self, x: core.AbstractValue) -> Transform:\n    raise NotImplementedError(type(self))\n\n  def pretty_print(self, context: core.JaxprPpContext) -> pp.Doc:\n    del context  # Unused.\n    return pp.text(f\"{{select({self.idx=})}}\")\n\n  def getattr(self, name: str, xs: Sequence[core.AbstractValue]) -> Any:\n    attrs = [getattr(x, name) for x in xs]\n    if any(attrs[0] != attr for attr in attrs[1:]):\n      raise TypeError(f\"Cannot resolve attribute {name} from: {attrs}\")","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/state/types.py#L230-L266","documentation":"Raised by SelectTransform._type when an element of the sequence being selected from is neither an AbstractRef nor a ShapedArray. JAX raises TypeError because it cannot compute a common type for the selection.","triggerScenarios":"Passing a tuple/list containing tokens or other non-ref, non-array avals to a select transform over multiple refs.","commonSituations":"Building multirefs with heterogeneous elements; custom jaxpr plumbing that mixes ref and non-ref values.","solutions":["Verify every element of the ref tuple is a ref (has .aval of AbstractRef)","Filter out non-ref values before constructing the multiref","Check for accidental nesting, e.g. a tuple inside the tuple"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"assert all(type(r).__name__ in (\"AbstractRef\",) or hasattr(r, 'inner_aval') for r in refs), \"all elements must be refs\"","typeGuard":"def all_refs(xs):\n    return all(hasattr(x, \"inner_aval\") or hasattr(x, \"aval\") for x in xs)","tryCatchPattern":null,"preventionTips":["Validate tuple contents before building multirefs","Avoid mixing tokens and refs in one group"],"tags":["jax","select","type-error"],"backgroundTag":"invalid-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}