What does model.to(torch.Tensor) do?

I read in PyTorch docs that .to(*args, **kwargs) can also take Pytorch tensors as inputs.

tensor = torch.tensor([[1, 2, 3], [4, 5, 6]], device='cuda:0', dtype=torch.float)
class MyModel(nn.Module):
model = MyModel()


I just would like to know what does this do?
Does this just moves the model to the device the tensor is on and set dtype to that of tensor

It does what the docs says:

Tensor whose dtype and device are the desired dtype and device for all parameters and buffers in this module

It allocates model in the given tensor’s device

so, it is the same as:


Thanks @JuanFMontesinos

In that context it’s equivalent to