{"record":{"id":"95ab4902df61b70c","repo":"jax-ml/jax","slug":"the-devices-method-was-called-on-self-error-re","errorCode":null,"errorMessage":"The devices() method was called on {self._error_repr()}.{self._origin_msg()}","messagePattern":"The devices\\(\\) method was called on (.+?)\\.(.+?)","errorType":"exception","errorClass":"ConcretizationTypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/core.py","lineNumber":1244,"sourceCode":"    except AttributeError:\n      return ()\n\n  def _origin_msg(self) -> str:\n    return \"\"\n\n  # Methods that are only valid for materialized arrays\n  def addressable_data(self, index):\n    raise ConcretizationTypeError(self,\n      f\"The addressable_data() method was called on {self._error_repr()}.\"\n      f\"{self._origin_msg()}\")\n\n  def delete(self):\n    raise ConcretizationTypeError(self,\n      f\"The delete() method was called on {self._error_repr()}.\"\n      f\"{self._origin_msg()}\")\n\n  def devices(self):\n    raise ConcretizationTypeError(self,\n      f\"The devices() method was called on {self._error_repr()}.\"\n      f\"{self._origin_msg()}\")\n\n  @property\n  def global_shards(self):\n    raise ConcretizationTypeError(self,\n      f\"The global_shards property was called on {self._error_repr()}.\"\n      f\"{self._origin_msg()}\")\n\n  def is_deleted(self):\n    raise ConcretizationTypeError(self,\n      f\"The is_deleted() method was called on {self._error_repr()}.\"\n      f\"{self._origin_msg()}\")\n\n  @property\n  def is_fully_addressable(self):\n    raise ConcretizationTypeError(self,\n      f\"The is_fully_addressable property was called on {self._error_repr()}.\"","sourceCodeStart":1226,"sourceCodeEnd":1262,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/core.py#L1226-L1262","documentation":"ConcretizationTypeError raised when Tracer.devices() is called. devices() returns the physical devices a materialized array's buffers live on; a tracer has no buffers and no placement, so during tracing the base-class stub raises ConcretizationTypeError.","triggerScenarios":"Calling `x.devices()` on a value while it is being traced by jax.jit, jax.grad, vmap, pmap, lax.scan, remat, or a custom transform rule.","commonSituations":"Device-placement assertions or logging (`assert x.devices()[0].platform == 'gpu'`) copied into jitted code; multi-host SPMD code checking replica placement inside pjit; debug utilities that introspect device residency run under a transform.","solutions":["Move device checks outside the traced function and perform them on the concrete input/output arrays.","Inside traces, use sharding info from jax.typeof(x) or the aval if placement metadata is needed.","If the check must run per-call, do it on the arguments before calling the jitted function.","Remove the introspection call from hot traced code; it cannot influence XLA compilation anyway."],"exampleFix":"// before\n@jax.jit\ndef f(x):\n    print(x.devices())  # ConcretizationTypeError\n    return x + 1\n\n// after\ndef f_outer(x):\n    print(x.devices())   # concrete array\n    return jitted_add_one(x)","handlingStrategy":"type-guard","validationCode":"import jax\n\ndef get_devices(x):\n    if isinstance(x, jax.core.Tracer):\n        return None  # or derive from jax.typeof(x) sharding\n    return x.devices()","typeGuard":"import jax\nfrom jax.core import Tracer\n\ndef has_device_info(x) -> bool:\n    return isinstance(x, jax.Array) and not isinstance(x, Tracer)","tryCatchPattern":"from jax.errors import ConcretizationTypeError\ntry:\n    devs = x.devices()\nexcept ConcretizationTypeError:\n    devs = None  # placement unknown under tracing","preventionTips":["Validate placement on concrete inputs before invoking jit.","Use jax.typeof(x) for tracing-time layout info.","Keep device assertions in test/setup code, not in kernels."],"tags":["jax","concretization","tracer","devices","placement"],"backgroundTag":"jax-tracer-concretization-error","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}