1. 程式人生 > >關於系統的GPU編號與Pytorch框架下的GPU編號

關於系統的GPU編號與Pytorch框架下的GPU編號

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