Their syntax varies slightly, but they are equivalent 8:




⠀
.to(name)
.to(device)
.cuda()




CPU
to('cpu')
to(torch.device('cpu'))
cpu()


Current GPU
to('cuda')
to(torch.device('cuda'))
cuda()


Specific GPU
to('cuda:1')
to(torch.device('cuda:1'))
cuda(device=1)



Note: the current cuda device is 0 by default, but this can be set with torch.cuda.set_device().