BUG: test_dunder_dlpack: accept spec-mandated BufferError for a no-copy cross-device export - #457
Conversation
test_dunder_dlpack pins the requested dl_device to kDLCPU while drawing copy
from {True, False, None}. For a library whose array is not already on kDLCPU
(e.g. a SYCL/GPU device reported as kDLOneAPI), the copy=False case forces a
cross-device transfer. The __dlpack__ specification requires that a no-copy
cross-device transfer be refused with a BufferError, so the test was failing
on spec-compliant behavior.
Compare the requested dl_device against x.__dlpack_device__() and accept a
BufferError when copy is False and the devices differ; all other exceptions
(and the copy=None/True paths, which must copy and succeed) are still treated
as failures.
Fixes data-apis#456
|
Thanks @antonwolfy. From the test output, the failure is To make sure I understand it right. So what it says is that torch is not compliant: it emits a |
|
Yes, per my understanding. Every spec version mandates
|
|
Thanks for confirming. I opened pytorch/pytorch#194267 |
|
Let's give it a go. I'll follow up on adding an xfail in the array-api-compat CI. |
The array API conformance job skipped `test_dlpack.py::test_dunder_dlpack` as a workaround for a bug in the test itself (tracked in [array-api-tests#457](data-apis/array-api-tests#457)): the test pinned the requested `dl_device` to `kDLCPU` while drawing `copy` from `{True, False, None}`, so on a SYCL device (reported as `kDLOneAPI`) the `copy=False` case forced a cross-device transfer and the spec-mandated `BufferError` was counted as a failure. The upstream test has since been fixed to tolerate `BufferError` only when `copy is False` and the requested device differs from the array's own `__dlpack_device__()` — behavior dpnp already implements correctly by delegating to dpctl. The conformance job checks out the array-api-tests default branch without pinning a ref, so the fix is already picked up on new runs and the skip is now dead weight. This change removes only that entry. The remaining `tanh` special-case skip is unrelated (an open array-api spec issue) and is left in place.
The array API conformance job skipped `test_dlpack.py::test_dunder_dlpack` as a workaround for a bug in the test itself (tracked in [array-api-tests#457](data-apis/array-api-tests#457)): the test pinned the requested `dl_device` to `kDLCPU` while drawing `copy` from `{True, False, None}`, so on a SYCL device (reported as `kDLOneAPI`) the `copy=False` case forced a cross-device transfer and the spec-mandated `BufferError` was counted as a failure. The upstream test has since been fixed to tolerate `BufferError` only when `copy is False` and the requested device differs from the array's own `__dlpack_device__()` — behavior dpnp already implements correctly by delegating to dpctl. The conformance job checks out the array-api-tests default branch without pinning a ref, so the fix is already picked up on new runs and the skip is now dead weight. This change removes only that entry. The remaining `tanh` special-case skip is unrelated (an open array-api spec issue) and is left in place. 2000d87
Closes #456.
This PR proposes to tolerate
BufferErroronly whencopy is Falseand the requesteddl_devicediffers from the array's own__dlpack_device__().CPU-native backends are unaffected (
cross_deviceisFalse). Thecopy=None/Truepaths must still copy and succeed, and non-BufferErrorexceptions still propagate.The change is verified and passed with dpnp.