Skip to content

torch asarray() from cupy 13.5 array "could not retrieve from buffer" #349

@gschramm

Description

@gschramm

With cupy 13.5, I get the following error when trying to convert a cupy GPU array into a pytorch tensor.

In [3]: import array_api_compat

In [4]: print(array_api_compat.__version__)
1.12.0

In [5]: import cupy as cp

In [6]: import torch as torch

In [7]: import array_api_compat.torch as xptorch

In [8]: import array_api_compat.cupy as xpcupy

In [9]: print(cp.__version__)
13.5.1

In [10]: print(torch.__version__)
2.7.1

In [11]: a = xptorch.asarray(xpcupy.ones(5))
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[11], line 1
----> 1 a = xptorch.asarray(xpcupy.ones(5))

File ~/.local/share/mamba/envs/test/lib/python3.13/site-packages/array_api_compat/torch/_aliases.py:214, in asarray(obj, dtype, device, copy, **kwargs)
    212 if device is None and isinstance(obj, torch.Tensor):
    213     device = obj.device
--> 214 return torch.asarray(obj, dtype=dtype, device=device, copy=copy, **kwargs)

RuntimeError: could not retrieve buffer from object

When I downgrade to cupy 13.4, the error disappears.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions