{"record":{"id":"e523e000192f9caf","repo":"jax-ml/jax","slug":"this-operation-is-implemented-for-a-pjrt-compatibl-e523e0","errorCode":null,"errorMessage":"This operation is implemented for a PjRt-compatible backend only.","messagePattern":"This operation is implemented for a PjRt-compatible backend only\\.","errorType":"exception","errorClass":"xla::XlaRuntimeError","httpStatus":null,"severity":"error","filePath":"jaxlib/dlpack.cc","lineNumber":283,"sourceCode":"          data, element_type, dimensions, byte_strides,\n          xla::PjRtClient::HostBufferSemantics::kMutableZeroCopy,\n          on_delete_callback, memory_space, /*device_layout=*/nullptr));\n  return std::make_pair(std::move(buffer), true);\n}\n\n}  // namespace\n\nabsl::StatusOr<nb::capsule> BufferToDLPackManagedTensor(\n    nb::handle py_buffer, std::optional<std::intptr_t> stream) {\n  ifrt::Array* ifrt_array = nb::cast<PyArray>(py_buffer).ifrt_array();\n  if (ifrt_array == nullptr) {\n    return xla::Unimplemented(\n        \"BufferToDLPackManagedTensor called on deleted array.\");\n  }\n  auto* arr =\n      xla::ifrt::dyn_cast_or_null<ifrt::PjRtCompatibleArray>(ifrt_array);\n  if (arr == nullptr) {\n    throw xla::XlaRuntimeError(\n        \"This operation is implemented for a PjRt-compatible backend only.\");\n  }\n  xla::PjRtBuffer* pjrt_buffer = arr->pjrt_buffers().front().get();\n\n  if (pjrt_buffer->IsTuple()) {\n    return xla::Unimplemented(\n        \"BufferToDLPackManagedTensor is not implemented for tuple \"\n        \"buffers.\");\n  }\n  if (pjrt_buffer->has_dynamic_dimensions()) {\n    return xla::Unimplemented(\"DynamicShape is not implemented in DLPack.\");\n  }\n\n  auto pack = std::make_unique<DLPackTensor>();\n  DLTensor& dt = pack->tensor.dl_tensor;\n  {\n    // AcquireExternalReference may block; there are no API guarantees.\n    GlobalPyRefManager()->CollectGarbage();","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jaxlib/dlpack.cc#L265-L301","documentation":"Exporting an array to DLPack requires reaching the underlying PjRtBuffer; if the IFRT array does not implement PjRtCompatibleArray, jaxlib cannot get a device pointer for the tensor and throws.","triggerScenarios":"Calling dlpack.to_dlpack(device_array) / array.__dlpack__() on an array living on a non-PjRt-compatible IFRT backend.","commonSituations":"Interop (torch, cupy) with arrays on experimental IFRT-native backends.","solutions":["Copy the array to a PjRt-compatible backend device (e.g. jax.device_put(arr, jax.devices('cpu')[0])) before exporting","Avoid DLPack interop on non-PjRt IFRT backends; use numpy round-trip as a fallback"],"exampleFix":"# before\ntorch.from_dlpack(ifrt_array)\n# after\nimport jax\na = jax.device_put(ifrt_array, jax.devices('cpu')[0])\ntorch.from_dlpack(a)","handlingStrategy":"fallback","validationCode":"from jax.extend import backend as jeb\nassert jeb.get_backend_c_api() is not None, 'backend not PjRt-compatible; DLPack export unsupported'","typeGuard":null,"tryCatchPattern":"try:\n    capsule = arr.__dlpack__()\nexcept Exception:\n    capsule = None\n    np_arr = np.asarray(arr)","preventionTips":["device_put arrays onto a standard backend before interop","Prefer numpy round-trip for exotic backends"],"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"}