{"record":{"id":"43681e5f7d0b4370","repo":"jax-ml/jax","slug":"specified-input-which-requires-a-copy-since-the-so","errorCode":null,"errorMessage":"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.","messagePattern":"Specified input which requires a copy since the source data buffer (.+?) However copy=False\\. Set copy=True or copy=None to perform the requested operation\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/dlpack.py","lineNumber":286,"sourceCode":"    stream = None\n  else:\n    try:\n      stream = dlpack_device.get_stream_for_external_ready_events()\n    except _jax.JaxRuntimeError as err:\n      if \"UNIMPLEMENTED\" in str(err):\n        stream = None\n      else:\n        raise\n  dlpack = external_array.__dlpack__(stream=stream)\n\n  try:\n    arr = _jax.dlpack_managed_tensor_to_buffer(\n      dlpack, dlpack_device, stream, copy, int(dl_device_type))\n  except xla_client.XlaRuntimeError as e:\n    se = str(e)\n    if \"is not aligned to\" in se:\n      i = se.index(\"is not aligned to\")\n      raise ValueError(\n        \"Specified input which requires a copy since the source data \"\n        f\"buffer {se[i:]} However copy=False. Set copy=True or \"\n        \"copy=None to perform the requested operation.\"\n      )\n    else:\n      raise\n  # TODO(phawkins): when we are ready to support x64 arrays in\n  # non-x64 mode, change the semantics to not canonicalize here.\n  arr = jnp.asarray(arr, dtype=dtypes.canonicalize_dtype(arr.dtype))\n  if copy:\n    # copy was already handled by dlpack_managed_tensor_to_buffer.\n    copy = None\n  return _place_array(arr, device, dlpack_device, copy)\n","sourceCodeStart":268,"sourceCodeEnd":300,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/dlpack.py#L268-L300","documentation":"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.","triggerScenarios":"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).","commonSituations":"Slicing tensors then interopping with JAX; producers that allocate unaligned storage; views with odd byte offsets (e.g. uint8 views into larger buffers).","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"],"exampleFix":"# before\njax.dlpack.from_dlpack(t[3:], copy=False)\n\n# after\njax.dlpack.from_dlpack(t[3:].clone(), copy=False)  # or copy=True","handlingStrategy":"try-catch","validationCode":"# avoid byte-offset views destined for zero-copy interop\nt = t if t.data_ptr() % 64 == 0 else t.clone()  # torch example","typeGuard":null,"tryCatchPattern":"try:\n    jax.dlpack.from_dlpack(t, copy=False)\nexcept ValueError as e:\n    if 'not aligned' not in str(e) and 'copy=False' not in str(e): raise\n    jax.dlpack.from_dlpack(t, copy=True)","preventionTips":["Use copy=None by default","Clone sliced tensors before zero-copy interop"],"tags":["jax","dlpack","alignment","zero-copy"],"backgroundTag":"unaligned-buffer-copy","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}