jax-ml/jax · error · nb::value_error

Buffer.__array__ with copy=True is not supported.

Error message

Buffer.__array__ with copy=True is not supported.

What it means

The FFI Buffer's __array__ returns a zero-copy view of device/host memory; copy=True requests a copy which the implementation does not provide, so it is rejected rather than silently returning an aliased array.

Source

Thrown at jaxlib/ffi.cc:447

void RegisterFfiApis(nb::module_& m) {
  nb::module_ ffi_module =
      m.def_submodule("ffi", "Python bindings for the XLA FFI.");

  nb::class_<PyFfiAnyBuffer> buffer(ffi_module, "Buffer");
  buffer.def_prop_ro("dtype", xla::ValueOrThrowWrapper(&PyFfiAnyBuffer::dtype));
  buffer.def_prop_ro("ndim", &PyFfiAnyBuffer::ndim);
  buffer.def_prop_ro("shape", &PyFfiAnyBuffer::shape);
  buffer.def_prop_ro("writeable", &PyFfiAnyBuffer::writeable);
  buffer.def(
      "__array__",
      [](PyFfiAnyBuffer self, nb::object dtype, nb::object copy) {
        if (!dtype.is_none()) {
          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

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Accept the zero-copy view; if you need a copy, do arr.copy() on the returned array
  2. Update code not to pass copy to Buffer.__array__

Example fix

# before
np.asarray(buf, copy=True)
# after
np.asarray(buf).copy()
Defensive patterns

Strategy: validation

Validate before calling

arr = buf.__array__()
need_copy = arr.copy()

Prevention

When it happens

Trigger: np.asarray(ffi_buffer, copy=True) or numpy 2.x code paths (e.g. np.array(..., copy=None) semantics) that request copies on FFI buffers.

Common situations: Libraries written for NumPy 2's copy protocol calling arrays with copy=True on xla.ffi Buffer objects.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/eb6408b374fa9c82. Report an issue: GitHub.