{"record":{"id":"9292c6cbddf0a60e","repo":"jax-ml/jax","slug":"dlpack-is-supported-for-pjrt-compatible-backends-o","errorCode":null,"errorMessage":"DLPack is supported for PjRt-compatible backends only.","messagePattern":"DLPack is supported for PjRt-compatible backends only\\.","errorType":"exception","errorClass":"xla::XlaRuntimeError","httpStatus":null,"severity":"error","filePath":"jaxlib/dlpack.cc","lineNumber":364,"sourceCode":"                      }\n                      // PyCapsule_GetPointer may have raised. Restore the\n                      // previous exception if there was one.\n                      PyErr_SetRaisedException(exc);\n                    }));\n  if (!capsule.ptr()) {\n    throw nb::python_error();\n  }\n  return capsule;\n}\n\nabsl::StatusOr<nb::object> DLPackManagedTensorToBuffer(\n    const nb::capsule& tensor, ifrt::Device* ifrt_device,\n    nb_class_ptr<PyClient> client, std::optional<std::intptr_t> stream,\n    std::optional<bool> copy, std::optional<DLDeviceType> dl_device_type) {\n  ifrt::PjRtDevice* device =\n      xla::ifrt::dyn_cast_or_null<ifrt::PjRtDevice>(ifrt_device);\n  if (device == nullptr) {\n    throw xla::XlaRuntimeError(\n        \"DLPack is supported for PjRt-compatible backends only.\");\n  }\n  if (!device->IsAddressable()) {\n    throw xla::XlaRuntimeError(\n        \"DLPack is only supported for devices addressable by the current \"\n        \"process.\");\n  }\n  if (std::string_view(tensor.name()) != kDlTensorCapsuleName) {\n    return xla::InvalidArgument(\n        \"DLPack tensor must be a capsule with name \\\"dltensor\\\", got \\\"%s\\\". \"\n        \"Note that a DLPack tensor may be consumed at most once.\",\n        std::string_view(tensor.name()));\n  }\n  DLManagedTensor* dlmt = static_cast<DLManagedTensor*>(tensor.data());\n  if (dlmt->dl_tensor.ndim < 0) {\n    return xla::InvalidArgument(\n        \"Number of dimensions in DLManagedTensor must be nonnegative, got %d\",\n        dlmt->dl_tensor.ndim);","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jaxlib/dlpack.cc#L346-L382","documentation":"Importing a DLPack tensor into jax requires creating a PjRt buffer on the target device; if the IFRT device is not a PjRtDevice, jaxlib cannot construct a buffer and throws.","triggerScenarios":"Calling dlpack.from_dlpack(tensor, device=non_pjrt_ifrt_device) or jax.dlpack.from_dlpack with a device from a non-PjRt-compatible backend.","commonSituations":"torch/cupy -> jax interop targeting an experimental IFRT-native backend device.","solutions":["Pass a device from a PjRt-compatible backend (default cpu/gpu devices)","Omit the device argument and let jax place the buffer on its default device"],"exampleFix":"# before\njax.dlpack.from_dlpack(t, device=ifrt_device)\n# after\njax.dlpack.from_dlpack(t)  # or device=jax.devices('gpu')[0]","handlingStrategy":"validation","validationCode":"assert device.platform in ('cpu','gpu','cuda','rocm','tpu')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use jax.devices('cpu'/'gpu') devices for DLPack imports","Omit device argument to use the default device"],"tags":["jax","dlpack","ifrt","pjrt","interop"],"backgroundTag":"incompatible-backend","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}