Torch.tensor does not return a tensor with device type cuda

In [1]: import torch

In [2]: device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

In [3]: rand_input = torch.tensor(data=torch.Tensor(1, 3, 80, 170), device=device, requires_grad=True)

In [4]: rand_input.device
Out[4]: device(type='cpu')

In [5]: device
Out[5]: device(type='cuda')

As can be seen when trying to create a tensor using the above way, even after specifying the device to be CUDA the returned tensor device type is CPU.

Am I missing something here? This does not seem like expected behaviour.

This is a bug. Opened an issue at

Thank you for opening an issue. I was unsure of whether this actually is a bug or just me doing things wrong. I think it’ll be better if the further conversation on this topic is carried out on github