pytorch中.cuda()和.to(device)有区别吗

参考官方文档https://pytorch.org/docs/stable/notes/cuda.html

在如下的示例代码中:

with torch.cuda.device(1):
    # allocates a tensor on GPU 1
    a = torch.tensor([1., 2.], device=cuda)

    # transfers a tensor from CPU to GPU 1
    b = torch.tensor([1., 2.]).cuda()
    # a.device and b.device are device(type='cuda', index=1)

    # You can also use ``Tensor.to`` to transfer a tensor:
    b2 = torch.tensor([1., 2.]).to(device=cuda)
    # b.device and b2.device are device(type='cuda', index=1)

.cuda() 与 .to(device)没有区别。

你可能感兴趣的:(torch)