jax-ml/jax · error · nb::value_error
Buffer.__dlpack__ with copy=True is not supported.
Error message
Buffer.__dlpack__ with copy=True is not supported.
What it means
The FFI Buffer's __dlpack__ exports the buffer zero-copy; copy=True is not implemented and is explicitly rejected so callers don't assume a copied tensor.
Source
Thrown at jaxlib/ffi.cc:461
throw nb::value_error(
"dtype parameter is not supported by Buffer.__array__.");
}
if (!copy.is_none() && nb::cast<bool>(copy)) {
throw nb::value_error(
"Buffer.__array__ with copy=True is not supported.");
}
return xla::ValueOrThrow(self.NumpyArray());
},
nb::arg("dtype") = nb::none(), nb::arg("copy") = nb::none());
buffer.def_prop_ro(
"__cuda_array_interface__",
xla::ValueOrThrowWrapper(&PyFfiAnyBuffer::CudaArrayInterface));
buffer.def(
"__dlpack__",
[](PyFfiAnyBuffer self, nb::object stream, nb::object max_version,
nb::object dl_device, nb::object copy) {
if (!copy.is_none() && nb::cast<bool>(copy)) {
throw nb::value_error(
"Buffer.__dlpack__ with copy=True is not supported.");
}
// Fall back on the non-versioned API if unsupported by the requested
// max_version.
nb::tuple max_version_tuple;
int64_t max_version_major;
if (!nb::try_cast<nb::tuple>(max_version, max_version_tuple) ||
max_version_tuple.size() < 2 ||
!nb::try_cast<int64_t>(max_version_tuple[0], max_version_major) ||
max_version_major < 1) {
return xla::ValueOrThrow(self.DLPack());
}
// TODO(danfm): Handle other optional inputs.
return xla::ValueOrThrow(self.DLPackVersioned());
},
nb::arg("stream") = nb::none(), nb::arg("max_version") = nb::none(),View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Omit copy (get the zero-copy export) and let the consumer copy if needed
- Patch the consumer to pass copy=False/None
- Ensure the buffer outlives the consumer tensor to keep zero-copy safe
Example fix
# before consumer.from_dlpack(buf.__dlpack__(copy=True)) # after consumer.from_dlpack(buf.__dlpack__())
Defensive patterns
Strategy: validation
Validate before calling
capsule = buf.__dlpack__() # no copy kwarg
Prevention
- Keep the source buffer alive while the consumer tensor exists
- Never pass copy=True to FFI Buffer __dlpack__
When it happens
Trigger: buffer.__dlpack__(copy=True) on an xla.ffi Buffer, typically from torch.from_dlpack or generic dlpack consumers that pass copy under dlpack>=1.0 protocol.
Common situations: Interop code that unconditionally passes copy=True to __dlpack__ on NumPy 2 / DLPack 1.0 consumers.
Related errors
- Specified {device=} which requires a copy since the source d
- Specified {device=} which requires a copy since the source d
- Buffer.__array__ with copy=True is not supported.
- to_dlpack can only pack a dlpack tensor from an array on a s
- __dlpack__ only supported for unsharded arrays.
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/82e83ef83f9989aa.
Report an issue: GitHub.