-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Labels
Description
Dear all,
I run the following command when xp is cupy
# cupy
x = cupy.asarray([1.0] * 3)
xp = array_api_compat.array_namespace(x)
E = xp.eye(3, 3, k=0, dtype='float64', device=1)
print(E.device)
with xp.cuda.Device(1):
E = xp.eye(3, 3, k=0, dtype='float64', device=1)
print(E.device)
# torch
x = torch.as_tensor([1.0] * 3)
xp = array_api_compat.array_namespace(x)
E = xp.eye(3, 3, k=0, dtype=torch.float64, device='cuda:1')
print(E.device)
and I get the result:
<CUDA Device 0>
<CUDA Device 1>
cuda:1
It seems that device argument of xp.eye has no effect here when xp is cupy.
It seems to work well when xp is torch.
Did I miss something?
Thank you.
array-api-compat 1.12.0
cupy-cuda12x 13.4.1
Activity
ev-br commentedon Jun 16, 2025
Yes, this is unfortunately a known issue with CuPy that it requires a context manager. NOt sure if there are plans to change that, maybe @leofang could weight in?
betatim commentedon Jun 17, 2025
Naively I'd have thought that array-api-compat is the place where we should be inserting that context manager for users when they pass
device=
as argument. Basically, to smooth out the differences between the different libraries. A bit like what is done inasarray
array-api-compat/array_api_compat/cupy/_aliases.py
Lines 65 to 87 in 6c708d1
ev-br commentedon Jun 17, 2025
Potentially, yes. The key question ATM is what's the cupy team plan. If this is something they plan to fix, we can either wait or potentially help materializing for cupy 14.x.