Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu

device = torch.device('cuda')

torch.rand(8,1).to(device)

原因在于torch函数生成的tensor需要转到GPU上

你可能感兴趣的:(pytorch,pytorch)