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?