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类型。