簡體   English   中英

Pytorch 3-GPU,只能使用其中兩個進行訓練

[英]Pytorch 3-GPUs, just can only use 2 of them to train

我有3個1080TI,但是在火車上我只能使用2個。

碼:

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.cuda()

criterion = nn.CrossEntropyLoss().cuda()
optimizer_conv = optim.SGD(model.classifier.parameters(), lr=0.0001, momentum=0.9)
exp_lr_scheduler = lr_scheduler.StepLR(optimizer_conv, step_size=7, gamma=0.1)

訓練部分:

outputs = nn.parallel.data_parallel(model,inputs,device_ids=[0,1,2])

使用“ CUDA_VISIBLE_DEVICES =“ 1,2,3” python train.py“可以做到這一點:

| 22%   35C    P8    10W / 250W |     12MiB / 11178MiB |      0%  
| 43%   59C    P2    92W / 250W |   1169MiB / 11178MiB |     49%   
| 44%   60C    P2    91W / 250W |   1045MiB / 11175MiB |     54% 

使用“ CUDA_VISIBLE_DEVICES =” 0,1,2“ python train.py”可以做到這一點:

| 21%   38C    P2    95W / 250W |   1169MiB / 11178MiB |     78%      Default |  
| 42%   63C    P2    93W / 250W |    777MiB / 11178MiB |     76%      Default |  
| 43%   64C    P0    85W / 250W |    282MiB / 11175MiB |      0%      Default |

我發現原因:
當有三個GPU時,我的batchsize = 4
因此,將batchsize更改為更大可以解決此“怪異”問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM