os.environ["CUDA_VISIBLE_DEVICES"] 决定了Pytorch能看到的GPU device
然后Pytorch会对这些GPU重新编号
比如:os.environ["CUDA_VISIBLE_DEVICES"]="3,5"
则重新编号后GPU3位device:0,GPU5位device:1
所以如果没有在os.environ指定device,只在 torch.nn.DataParallel(model, device_ids=[1])指定使用第二块GPU可能会报错的
model可以放到GPU1上,但是因为对Pytorch来说0,1都是可见的,数据默认放到GPU0上,这是可能会报一下错误
Expected tensor for argument #1 'input' to have the same device as tensor for argument #2 'weight'; but device 1 does not equal 0
所以最好还是用os.environ指定Pytorch框架能看到的GPU device