1@https://blog.youkuaiyun.com/u010698086/article/details/80346177
方法一:改变系统变量使得仅目标显卡可见
export CUDA_VISIBLE_DEVICES=0 #这里是要使用的GPU编号,正常的话是从0开始
然后再运行pyTorch即可
方法二:使用torch.cuda接口
#在生成网络对象之前:
torch.cuda.set_device(0)
方法三:使用多pytorch的并行GPU接口
net = torch.nn.DataParallel(model, device_ids=[0])
方法四:初始化模型时
net = Net.cuda(0)