Default process group has not been initialized, please make sure to call init_process_group.

在查看SlowFastNet源代码https://github.com/facebookresearch/SlowFast中的model_builder时,想要采用多GPU训练;GPU大于1的话,代码自动调用torch.nn.parallel.DistributedDataParallel套在model外面。

torch.nn.parallel.DistributedDataParallel和torch.nn.parallel.DataParallel作用相似,都是pytorch调用多GPU训练;但torch.nn.parallel.DistributedDataParallel需有个初始化

在torch.nn.parallel.DistributedDataParallel前加入

torch.distributed.init_process_group('nccl',init_method='file:///home/.../my_file',world_size=1,rank=0)

这里是在单个机器上调用多张GPU,简称单机多卡,所以world_size=1;具体参考
https://github.com/pytorch/examples/tree/master/imagenet

下列代码构造了仅使用index为1,2共计两个GPU同时训练模型

os.environ['CUDA_VISIBLE_DEVICES']='1,2'
device=torch.device('cuda:0')
model=ConvNet(num_classes)
torch.distributed.init_process_group('nccl',init_method='file:///home/.../my_file',world_size=1,rank=0)
model=torch.nn.parallel.DistributedDataParallel(model.to(device)

关于pytorch多GPU训练,下面这篇文章写得有点乱,看了下就是把他放在最后的几篇文章给结合了一下
https://blog.csdn.net/m0_38008956/article/details/86559432

  • 11
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值