When call to("cuda"), which one should be called

We have to.dtype_layout, to.device, to.dtype, to.other. I use gdb to trace and find that it calls to.dtype_layout instead of to.device.

import torch

a = torch.Tensor([1,2,3]).to("cuda")

The to() method check for all input options. What kind of issue are you seeing?

If I want to call to.dtype instead of to.dtype_layout, how to code?

If you want to change the dtype, you can directly pass the wanted dtype to the to() call:

x = x.to(torch.float32)
x = x.to(torch.long)

or call the “dtype method” on the tensor:

x = x.float()
x = x.long()

Sorry, I’m wrong. When I use tensor.to(torch.long) it will call to.dtype. But When I call tensor.to("cuda") it will call to.dtype_layout instead of to.device.