pytorch多卡分布式训练torch.distributed问题集锦

1. RuntimeError: all tensors must be on devices[0]

该问题由于PyTorch程序设置的gpu_id编号未从0开始导致的。

解决方案:使用动态GPU序号。注意别漏写device_id参数中的中括号[]。

2. UserWarning: Single-Process Multi-GPU is not the recommended mode for DDP. In this mode, each DDP instance operates on multiple devices and creates multiple module replicas within one process. The overhead of scatter/gather and GIL contention in every forward pass can slow down training. Please consider using one DDP instance per device or per module replica by explicitly setting device_ids or CUDA_VISIBLE_DEVICES

问题描述:UserWarning:单进程多 GPU 不是 DDP 的推荐模式。在这种模式下,每个 DDP 实例在多个设备上运行,并在一个进程中创建多个模块副本。每次前向传球中分散/聚集和 GIL 争用的开销都会减慢训练速度。请考虑通过显式设置device_ids或CUDA_VISIBLE_DEVICES,为每个设备或每个模块副本使用一个 DDP 实例。

该问题是由于我的world_size写为2导致,world_size应该是gpu数量的n倍。修改为何gpu相同数量成功运行。(可能报错:RuntimeError: Connection reset by peer)

3. RuntimeError: Address already in use

问题描述:设置的端口号被占用,重新设置一个端口号,而且要注意,这里的端口号要和初始化中是用的端口号是相同的。

4. RuntimeError: NCCL error in: /pytorch/torch/lib/c10d/../c10d/NCCLUtils.hpp:94, invalid argument, NCCL version 2.7.8

pytorch与nccl版本不匹配,可以降低pytorch版本

Previous PyTorch Versions | PyTorch 在这里下载1.6.0, linux+cuda版本

5. torch.distributed.init_process_group卡死

可能会遇到分布式训练卡死问题。

可能原因:Pytorch 如何解决dist.init_process_group卡死(或死锁)问题|极客教程 (geek-docs.com)

我遇到的问题,端口问题。解决如下:

在main文件中添加命令:对应init_process_group中如下书写。

6. RuntimeError: CUDA error: invalid device ordinal

报错原因:只有7张卡,gpu_num 设置为8,报错。

7. RuntimeError: Invalid device string: '0,1,2,3,4,5,6,7'

device_id需要是int类型。

  • 22
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值