PyTorch中to()和cuda()的区别

46 阅读1分钟

没有区别。

早期(张量和模型都要):

x = x.cuda()
model.cuda()

后来:

device = torch.device('cuda') if cuda_available else torch.device('cpu')
x = x.to(device)
model = model.to(device)