美文网首页
Pytorch单机多卡分布式训练 数据并行

Pytorch单机多卡分布式训练 数据并行

作者: 归海云鹤 | 来源:发表于2019-12-30 16:54 被阅读0次

Pytorch单机多卡训练(数据并行训练)

Pytorch的数据并行训练,已经被封装的十分完善。全程只需两步:

1.将模型送入多GPU

2.将训练数据送入多GPU

0.判断GPU是否可用

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

1.把模型送入多GPU

if torch.cuda.device_count() > 1:

  print("Let's use", torch.cuda.device_count(), "GPUs!")

  model = nn.DataParallel(model)

model.to(device)

2.将训练数据送入多GPU

for data in rand_loader:

    input = data.to(device)

    output = model(input)

相关文章

网友评论

      本文标题:Pytorch单机多卡分布式训练 数据并行

      本文链接:https://www.haomeiwen.com/subject/mmpmoctx.html