Why does `torch.Tensor` not have a `device` argument

This fails:

>>> torch.Tensor(2,3, device="cuda")
RuntimeError: legacy constructor expects device type: cpu but device type: cuda was passed

A solution, I can find, but it is not elegant and creates the tensor on CPU then moves it to GPU

>>> torch.tensor(torch.Tensor(2,3), device="cuda")
tensor([[-7.6854e-18,  3.0808e-41, -1.5538e-01],
        [ 4.5572e-41,  8.9683e-44,  0.0000e+00]], device='cuda:0')

Is there a way to create a tensor on cuda inplace?


It looks like you are specifying a shape and not providing data for initialization, so what you are doing would be equivalent to

torch.empty(2, 3, device='cuda')