Pytorch 3-GPU,只能使用其中两个进行训练

时间:2018-10-31 07:51:52

标签: python deep-learning pytorch multi-gpu

我有三个1080TI,但是在火车上我只能使用其中两个。

代码:

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 |

1 个答案:

答案 0 :(得分:0)

eeeee ..我发现原因:
当有三个GPU时,我的batchsize = 4
因此,将batchsize更改为更大可以解决此“怪异”问题

相关问题