在生成网络对象之前执行:torch.cuda.set_device(0)
torch.cuda.set_device(0)
net = torch.nn.DataParallel(model, device_ids=[0,1,2...])
net = Net.cuda(0)