Skip to content

BUG: Should np.from_dlpack raise BufferError instead of ValueError on unsupported dl_device values? #30937

Closed

Description

@lucyleeow

Describe the issue:

Relates to #30341 and #30936

In the from_dlpack docs it says:

BufferError – The dlpack and dlpack_device methods on the input array may raise BufferError when the data cannot be exported as DLPack (e.g., incompatible dtype, strides, or device).

I read the meaning as: incompatible dtype, incompatible strides, or incompatible device - which would suggest a BufferError should be raised when device is incompatible?

I understand BufferError may seem like an odd choice (#30341 (comment)) but just raising the question from my interpretation of the docs.

Reproduce the code example:

x_torch = torch.arange(5, device='cuda')
np.from_dlpack(x_torch)

Error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: Unsupported device in DLTensor.

Python and NumPy Versions:

2.4.2
3.14.2 | packaged by conda-forge | (main, Feb 4 2026, 15:49:49) [GCC 14.3.0]

Runtime Environment:

No response

How does this issue affect you or how did you find it:

scikit-learn/scikit-learn#32755 (comment)

Activity

  1. added
    sprintableIssue fits the time-frame and setting of a sprint
    on Mar 5, 2026
  2. seberg commented on Mar 5, 2026

    @seberg
    Member

    Yeah, I agree, would be better/correct to raise a BufferError here, seems there is always one more path...

  3. seberg commented on Mar 11, 2026

    @seberg
    Member

    Ah, now that I see the code change, I realize why it wasn't the case. BufferError is vital for the exporter, but this is on the consumer side it is a bit less clear cut (and not actually specified at all, I think).
    But it sounds like it helps you, so happy to change it.

  4. lucyleeow commented on Mar 11, 2026

    @lucyleeow
    Author

    Now that I read the docs more carefully it does talk about exporting: "data cannot be exported as DLPack" - but doing some digging, the spec also says:

    If an array that is accessed via the interchange protocol lives on a device that the requesting (consumer) library does not support, it is recommended to raise a BufferError, unless an explicit copy is requested (see below) and the producer can support the request.

  5. seberg commented on Mar 11, 2026

    @seberg
    Member

    Ah, you are right, so that hints to it, good to know. And it makes sense anyway, I think. (Sorry for the noise, I think it mostly explains why we missed it, fixing it for the export part at some point, but not here.)

  6. lucyleeow commented on Mar 11, 2026

    @lucyleeow
    Author

    And it makes sense anyway, I think.

    Honestly, I am always confused with DLPack 🤔 (I also do not have a good sense if it makes sense... 😅 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - BugsprintableIssue fits the time-frame and setting of a sprint

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions