import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0, 1, 2'
import torch  

#注意以上两行先后顺序不可弄错

 

device = torch.device('cuda')

model = DataParallel(model)
model.to(device)

 

这样模型就会在gpu 0, 1, 2 上进行训练