-
Notifications
You must be signed in to change notification settings - Fork 27.4k
asarray: device does not propagate from input to output after set_default_deviceΒ #150199
Description
π Describe the bug
The documentation of asarray states:
device (torch.device, optional) β the device of the returned tensor. Default: None, which causes the device of obj to be used. Or, if obj is a Python sequence, the current default device will be used.
The described behaviour is coherent with the specification of the Array API standard.
This works as expected in practice: asarray(x, device=None), propagates the device of x to the output - unless the user sets the default device (even if just to explicitly state the current value). After that, asarray(x, device=None) disregards the device of x and converts everything to the default device.
In [1]: import torch
In [2]: torch.get_default_device()
Out[2]: device(type='cpu')
In [3]: x = torch.asarray(0, device=torch.device('cuda'))
In [4]: torch.asarray(x).get_device()
Out[4]: 0 # OK
In [5]: torch.set_default_device('cpu')
In [6]: torch.asarray(x).get_device()
Out[6]: -1 # KOVersions
pytorch 2.6.0 conda-forge linux intel
cc @mruberry @rgommers @asmeurer @leofang @AnirudhDagar @asi1024 @emcastillo @kmaehashi @albanD