{"record":{"id":"9602082e4166be59","repo":"jax-ml/jax","slug":"couldn-t-get-local-hardware-id-for-dlpack","errorCode":null,"errorMessage":"Couldn't get local_hardware_id for __dlpack__","messagePattern":"Couldn't get local_hardware_id for __dlpack__","errorType":"exception","errorClass":"BufferError","httpStatus":null,"severity":"error","filePath":"jax/_src/array.py","lineNumber":465,"sourceCode":"      if \"cuda\" in platform_version:\n        if self.sharding.memory_kind == \"pinned_host\":\n          dl_device_type = DLDeviceType.kDLCUDAHost\n        else:\n          dl_device_type = DLDeviceType.kDLCUDA\n      elif \"rocm\" in platform_version:\n        if self.sharding.memory_kind == \"pinned_host\":\n          dl_device_type = DLDeviceType.kDLROCMHost\n        else:\n          dl_device_type = DLDeviceType.kDLROCM\n      elif \"oneapi\" in platform_version:\n        dl_device_type = DLDeviceType.kDLOneAPI\n      else:\n        raise BufferError(\"Unknown GPU platform for __dlpack__: \"\n                         f\"{platform_version}\")\n\n      local_hardware_id = _get_device(self).local_hardware_id\n      if local_hardware_id is None:\n        raise BufferError(\"Couldn't get local_hardware_id for __dlpack__\")\n\n      return dl_device_type, local_hardware_id\n\n    elif self.platform() == \"tpu\":\n      if self.sharding.memory_kind == \"pinned_host\":\n        dl_device_type = DLDeviceType.kDLTPUHost\n      else:\n        raise BufferError(\n            \"__dlpack__ device only supported for TPU pinned host memory\"\n        )\n\n      local_hardware_id = _get_device(self).local_hardware_id\n      if local_hardware_id is None:\n        raise BufferError(\"Couldn't get local_hardware_id for __dlpack__\")\n\n      return dl_device_type, local_hardware_id\n\n    else:","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/array.py#L447-L483","documentation":"During DLPack export of a GPU array, JAX needs the device's local_hardware_id (the physical device index) to fill the DLPack device tuple. If the backend device object returns None for local_hardware_id, the export cannot proceed and BufferError is raised.","triggerScenarios":"Calling __dlpack__/__dlpack_device__ on a CUDA/ROCm/OneAPI array where _get_device(self).local_hardware_id is None — typically a mis-initialized or partially initialized backend, or an unusual device abstraction from plugins.","commonSituations":"Custom XLA backend plugins or device proxies that don't populate local_hardware_id; jaxlib/device driver version mismatch; GPU visible-device configurations that strip hardware IDs (e.g. cgroup/device filtering in containers).","solutions":["Verify devices initialize correctly: print(jax.devices()) and check local_hardware_id on each","Upgrade/downgrade jaxlib to match the installed JAX and CUDA/ROCm stack","Avoid device filtering (CUDA_VISIBLE_DEVICES quirks) or container device cgroup restrictions and retry","Fall back to host transfer: np.asarray(x)"],"exampleFix":"// before\nt = torch.from_dlpack(x)  # BufferError: Couldn't get local_hardware_id\n// after\nfor d in jax.devices():\n    assert d.local_hardware_id is not None, d\n# if that fails, fix backend init; otherwise transfer via host:\nt = torch.as_tensor(np.asarray(x)).to('cuda')","handlingStrategy":"validation","validationCode":"devices_ok = all(d.local_hardware_id is not None for d in jax.devices())\nif not devices_ok:\n    raise RuntimeError('GPU backend not fully initialized; fix before DLPack use')","typeGuard":null,"tryCatchPattern":"try:\n    t = torch.from_dlpack(x)\nexcept BufferError:\n    t = torch.as_tensor(np.asarray(x)).to('cuda')","preventionTips":["Sanity-check jax.devices() output at program start","Keep driver, CUDA/ROCm, and jaxlib versions aligned","Avoid container device cgroup filters that hide hardware IDs"],"tags":["jax","dlpack","gpu","device-init","environment"],"backgroundTag":"dlpack-missing-device-id","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}