`tensor`'s `device` parameter not working when using NumPy array?

The device parameter of torch.tensor seems to be ignored when the value passed is a NumPy array:

import torch
import numpy as np

x = torch.tensor(np.array(1), device='cuda:0')
print(x.device)  # Prints `cpu`
x = torch.tensor(1, device='cuda:0')
print(x.device)  # Prints `cuda:0`

The tensor is created with the appropriate values, only the device is different. Is this the expected behavior? If so, could someone explain why?

1 Like

It looks like it’s related to this issue.

1 Like