jax-ml/jax · error · ValueError
Specified input which requires a copy since the source data
Error message
Specified input which requires a copy since the source data buffer {se[i:]} However copy=False. Set copy=True or copy=None to perform the requested operation. What it means
from_dlpack with copy=False attempted zero-copy import of a buffer whose data pointer is not aligned as required by XLA; a copy is required to fix alignment, but the user forbade it. The XlaRuntimeError is re-raised as a ValueError with the alignment detail.
Source
Thrown at jax/_src/dlpack.py:286
stream = None
else:
try:
stream = dlpack_device.get_stream_for_external_ready_events()
except _jax.JaxRuntimeError as err:
if "UNIMPLEMENTED" in str(err):
stream = None
else:
raise
dlpack = external_array.__dlpack__(stream=stream)
try:
arr = _jax.dlpack_managed_tensor_to_buffer(
dlpack, dlpack_device, stream, copy, int(dl_device_type))
except xla_client.XlaRuntimeError as e:
se = str(e)
if "is not aligned to" in se:
i = se.index("is not aligned to")
raise ValueError(
"Specified input which requires a copy since the source data "
f"buffer {se[i:]} However copy=False. Set copy=True or "
"copy=None to perform the requested operation."
)
else:
raise
# TODO(phawkins): when we are ready to support x64 arrays in
# non-x64 mode, change the semantics to not canonicalize here.
arr = jnp.asarray(arr, dtype=dtypes.canonicalize_dtype(arr.dtype))
if copy:
# copy was already handled by dlpack_managed_tensor_to_buffer.
copy = None
return _place_array(arr, device, dlpack_device, copy)
View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Use copy=True or copy=None (default) to let JAX realign
- Copy/clone the tensor in the source framework to get an aligned base buffer
- Avoid byte-offset views when passing buffers to JAX
Example fix
# before jax.dlpack.from_dlpack(t[3:], copy=False) # after jax.dlpack.from_dlpack(t[3:].clone(), copy=False) # or copy=True
Defensive patterns
Strategy: try-catch
Validate before calling
# avoid byte-offset views destined for zero-copy interop t = t if t.data_ptr() % 64 == 0 else t.clone() # torch example
Try / catch
try:
jax.dlpack.from_dlpack(t, copy=False)
except ValueError as e:
if 'not aligned' not in str(e) and 'copy=False' not in str(e): raise
jax.dlpack.from_dlpack(t, copy=True) Prevention
- Use copy=None by default
- Clone sliced tensors before zero-copy interop
When it happens
Trigger: jax.dlpack.from_dlpack(t, copy=False) where the producer's underlying buffer is misaligned (e.g. a torch tensor slice offset by a non-aligned number of bytes, or custom C-allocated buffers).
Common situations: Slicing tensors then interopping with JAX; producers that allocate unaligned storage; views with odd byte offsets (e.g. uint8 views into larger buffers).
Related errors
- to_dlpack can only pack a dlpack tensor from an array on a s
- __dlpack__ only supported for unsharded arrays.
- Unknown GPU platform for __dlpack__: {platform_version}
- Couldn't get local_hardware_id for __dlpack__
- __dlpack__ device only supported for TPU pinned host memory
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/43681e5f7d0b4370.
Report an issue: GitHub.