解决Pytorch 分布式并行DDP卡死挂起的问题

AIGC gpu  收藏
0 / 123

问题描述:

使用 A30 显卡,使用分布式并行 Distributed Data Parallel,运行程序时显卡显存充满,卡在设置 local_rank 处,并未启动进程组。

解决方案:

方案1、更换后端为“Gloo”,正常执行shell命令运行程序。

torch.distributed.init_process_group(backend="Gloo")
python -m torch.distributed.launch --nproc_per_node=7 --master_port 8888 main.py

方案2、仍旧使用“NCCL”后端,但需要更改环境变量,在shell命令前加入禁用P2P。

torch.distributed.init_process_group(backend="NCCL")
NCCL_P2P_DISABLE=1 python -m torch.distributed.launch --nproc_per_node=7 --master_port 8888 main.py

方案3、仍旧使用“NCCL”后端,但需要更改环境变量,永久更改环境设置,正常执行shell命令运行程序。

torch.distributed.init_process_group(backend="NCCL")

vim ~/.bashrc
export NCCL_P2P_DISABLE=1
source ~/.bashrc.
python -m torch.distributed.launch --nproc_per_node=7 --master_port 8888 main.py

分析:
建议使用第3个方案,Gloo后端没有NCCL后端通信速度快,程序运行速度NCCL较快。另外,每次加上修改环境变量的命令也挺烦的,修改bash环境变量一劳永逸。NCCL_P2P_DISABLE=1将禁用GPU之间直接通信(如使用NVlink或者PCIe),鉴于NVDIA官网显示A30支持NVlink或者PCIe,因此判断可能是硬件故障或者是软件版本不匹配导致P2P通信受阻,使得进程阻塞,程序挂起。