{"record":{"id":"5bf5e4827bbb42fb","repo":"jax-ml/jax","slug":"array-passed-to-from-dlpack-is-on-unsupported-devi","errorCode":null,"errorMessage":"Array passed to from_dlpack is on unsupported device type (DLDeviceType: {dl_device_type}, array: {external_array}","messagePattern":"Array passed to from_dlpack is on unsupported device type \\(DLDeviceType: (.+?), array: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/dlpack.py","lineNumber":250,"sourceCode":"  \"\"\"\n  if isinstance(device, Sharding):\n    device_set = device.device_set\n    if len(device_set) > 1:\n      raise ValueError(\n        \"from_dlpack can only unpack a dlpack tensor onto a singular device, but \"\n        f\"a Sharding with {len(device_set)} devices was provided.\"\n      )\n    device, = device_set\n  if not hasattr(external_array, \"__dlpack__\") or not hasattr(external_array, \"__dlpack_device__\"):\n    raise TypeError(\n        \"The array passed to from_dlpack must have __dlpack__ and __dlpack_device__ methods.\"\n    )\n\n  dl_device_type, device_id = external_array.__dlpack_device__()\n  try:\n    dl_device_platform = _DL_DEVICE_TO_PLATFORM[dl_device_type]\n  except KeyError:\n    raise TypeError(\n        \"Array passed to from_dlpack is on unsupported device type \"\n        f\"(DLDeviceType: {dl_device_type}, array: {external_array}\"\n    ) from None\n\n  backend = xla_bridge.get_backend(dl_device_platform)\n  dlpack_device = backend.device_from_local_hardware_id(device_id)\n  _check_device(device, dlpack_device, copy)\n  if _is_tensorflow_tensor(external_array):\n    # TensorFlow does not support stream=.\n    stream = None\n  elif dl_device_type in (\n      DLDeviceType.kDLCUDAHost,\n      DLDeviceType.kDLROCMHost,\n      DLDeviceType.kDLTPUHost,\n  ):\n    # Some producers (e.g. torch.Tensor with is_pinned()) route pinned tensors\n    # through their CPU __dlpack__, which rejects a non-None stream argument.\n    stream = None","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/dlpack.py#L232-L268","documentation":"from_dlpack queries the producer's __dlpack_device__ and only knows how to map known DLDeviceType values (CPU, CUDA) onto JAX devices. It fires when the external array reports an unsupported device type, so JAX cannot place the imported buffer.","triggerScenarios":"from_dlpack on tensors living on devices like kDLOpenCL, kDLVulkan, kDLMetal (on unsupported builds), or any enum absent from JAX's _DL_DEVICE_TO_PLATFORM.","commonSituations":"Interop with Vulkan/OpenCL-backed arrays, or a JAX build lacking the matching accelerator backend (e.g. ROCm tensor with CUDA-only jax).","solutions":["Move the source tensor to CPU or a supported device in the source framework before from_dlpack","Install the JAX build matching the accelerator (jax-rocm vs jax-cuda)","Fall back to jax.numpy.asarray(t) which copies through the host"],"exampleFix":"# before\njax.dlpack.from_dlpack(vulkan_tensor)\n\n# after\njax.dlpack.from_dlpack(vulkan_tensor.cpu())  # or asarray fallback","handlingStrategy":"fallback","validationCode":"from jax._src.dlpack import _DL_DEVICE_TO_PLATFORM\nif external.__dlpack_device__()[0] not in _DL_DEVICE_TO_PLATFORM:\n    external = external.cpu() if hasattr(external, 'cpu') else None\nassert external is not None","typeGuard":null,"tryCatchPattern":"try:\n    jax.dlpack.from_dlpack(t)\nexcept TypeError:\n    jax.dlpack.from_dlpack(t.cpu())","preventionTips":["Move exotic-device tensors to CPU before interop","Match jax build (cuda/rocm) to your accelerator"],"tags":["jax","dlpack","device-type","interop"],"backgroundTag":"unsupported-device-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}