{"record":{"id":"eae0f1b7a22d6520","repo":"jax-ml/jax","slug":"the-device-specification-passed-to-to-dlpack-conta","errorCode":null,"errorMessage":"The device specification passed to to_dlpack contains an unsupported device type (DLDeviceType: {dl_device_type})","messagePattern":"The device specification passed to to_dlpack contains an unsupported device type \\(DLDeviceType: (.+?)\\)","errorType":"exception","errorClass":"BufferError","httpStatus":null,"severity":"error","filePath":"jax/_src/dlpack.py","lineNumber":145,"sourceCode":"    is mutated, it may lead to undefined behavior when using the associated JAX\n    array. When JAX eventually supports ``DLManagedTensorVersioned``\n    (DLPack 1.0), it will be possible to specify that a buffer is read-only.\n  \"\"\"\n  if not isinstance(x, array.ArrayImpl):\n    raise TypeError(\"Argument to to_dlpack must be a jax.Array, \"\n                    f\"got {type(x)}\")\n\n  device = None\n  dl_device_type, local_hardware_id = dl_device if dl_device else (None, None)\n  if dl_device_type:\n    try:\n      dl_device_platform = _DL_DEVICE_TO_PLATFORM[dl_device_type]\n      backend = xla_bridge.get_backend(dl_device_platform)\n      device = backend.device_from_local_hardware_id(local_hardware_id)\n    except KeyError:\n      # https://data-apis.org/array-api/latest/API_specification/generated/array_api.array.__dlpack__.html\n      # recommends using BufferError.\n      raise BufferError(\n          \"The device specification passed to to_dlpack contains an\"\n          f\" unsupported device type (DLDeviceType: {dl_device_type})\"\n      ) from None\n\n  # As new versions are adopted over time, we can maintain some legacy paths\n  # for compatibility mediated through the max_version parameter.\n  # TODO(micky774): Deprecate default usage of DLPackManagedTensor when XLA\n  # supports DLManagedTensorVersioned (DLPack version 1.0) and repurpose the\n  # current _to_dlpack as a legacy path for (0,5) <= max_version < (1,0).\n  if max_version is None or max_version >= DLPACK_VERSION:\n    # Latest\n    return _to_dlpack(\n      x, stream=stream,\n      src_device=src_device,\n      device=device,\n      copy=copy\n    )\n  elif max_version >= MIN_DLPACK_VERSION:","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/dlpack.py#L127-L163","documentation":"The dl_device tuple passed to __dlpack__/to_dlpack names a DLPack device type (e.g. kDLCUDA, kDLCPU, kDLMetal) that JAX does not map to any supported backend platform. Per the array API spec, unsupported producers raise BufferError.","triggerScenarios":"Calling x.__dlpack__(dl_device=(t, id)) with a DLDeviceType enum value not in JAX's _DL_DEVICE_TO_PLATFORM mapping (e.g. kDLROCM on a build without ROCm, kDLOpenCL, kDLVulkan).","commonSituations":"PyTorch requesting an OpenCL/Vulkan/Metal device buffer; consumers hard-coding a device enum not supported by the installed JAX backends.","solutions":["Request a supported device type: CPU or the GPU type JAX was built for (kDLCUDA, or kDLCUDAManaged where supported)","Pass dl_device=None to let JAX choose the array's native device","Verify the target platform backend is installed (jax.cuda / jax.rocm)"],"exampleFix":"# before\njax_arr.__dlpack__(dl_device=(DLDeviceType.kDLOpenCL, 0))\n\n# after\njax_arr.__dlpack__()  # or dl_device=(DLDeviceType.kDLCUDA, 0)","handlingStrategy":"fallback","validationCode":"from jax._src.dlpack import _DL_DEVICE_TO_PLATFORM\nif dl_device and dl_device[0] not in _DL_DEVICE_TO_PLATFORM:\n    dl_device = None  # fall back to native device","typeGuard":null,"tryCatchPattern":"try:\n    x.__dlpack__(dl_device=dl_device)\nexcept BufferError:\n    x.__dlpack__()","preventionTips":["Request only kDLCPU/kDLCUDA (or your installed backend's type)","Omit dl_device when the consumer can accept the native device"],"tags":["jax","dlpack","device-type","buffer-protocol"],"backgroundTag":"unsupported-device-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}