jax-ml/jax · error · nb::value_error
dtype parameter is not supported by Buffer.__array__.
Error message
dtype parameter is not supported by Buffer.__array__.
What it means
The FFI Buffer.__array__ binding only returns the buffer's existing native dtype and cannot reinterpret it. It fires when a dtype argument is passed to numpy-array conversion.
Solutions
- Call __array__ without dtype and cast afterwards: arr.astype(np.float32)
- Do the conversion inside the kernel on the raw data pointer instead
Example fix
# before np.asarray(buf, dtype=np.float32) # after np.asarray(buf).astype(np.float32)
Defensive patterns
Strategy: validation
Validate before calling
arr = buf.__array__() # never pass dtype
Prevention
- Cast after conversion with ndarray.astype
- Don't write dtype-generic np.asarray(x, dtype=...) helpers that hit FFI buffers
When it happens
Trigger: np.asarray(ffi_buffer, dtype=some_dtype) or calling buffer.__array__(dtype=...) on an xla.ffi Buffer object.
Common situations: Code doing np.asarray(x, dtype=np.float32) generically on any array-like, hitting an FFI buffer during custom-call/ffi kernel testing.
Related errors
- `a` array must be integer typed
- Buffer.__array__ with copy=True is not supported.
- jax.numpy.var does not yet support real dtype parameters…
- Unsupported scalar attribute type
- a and b must have the same element type, but got
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/32d7fd78f49e7437.
Report an issue: GitHub.
Appendix: source
Thrown at jaxlib/ffi.cc:443
nb::tuple PyFfiAnyBuffer::DLPackDevice() const {
return nb::make_tuple(static_cast<int32_t>(device_type_), device_ordinal_);
}
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(View on GitHub (pinned to 1e1c6a8fc0)