torch.distributed的backend选择:nccl、gloo、mpi?torch.distributed的backend选择:nccl、gloo、mpi?
NCCL(NVIDIA Collective Communications Library):面向 GPU 集体通信(all-reduce、all-gather、broadcast 等),利用 NVLink、多 GPU、多机 IB/TCP,性能最优。限制:仅支持 GPU tensor;多机需 NCCL 与网络(IB 或 socket)正确配置。PyTorch 多卡/多机 GPU 训练默认推荐 nccl。
Gloo:PyTorch 自带的 CPU/GPU collective 实现,支持 CPU tensor、也支持 GPU(通过 CUDA)。优点:无需 NCCL、易调试、支持更多 reduce 类型与自定义 op。缺点:GPU 上性能通常不如 NCCL,多机用 TCP。适合 CPU 训练、或 GPU 上调试/小规模,或无 NCCL 环境。
MPI:使用系统 MPI 库(如 OpenMPI、MVAPICH)做 collective。优点:与现有 HPC 环境兼容、功能全。缺点:需单独安装 MPI、与 PyTorch 的集成不如 nccl/gloo 简单,调试与部署略重。适合 已有 MPI 的集群、或与其它 MPI 程序协同 时。
torch.distributed.init_process_group(backend='nccl', ...)。| 返回模块 | 返回总览 |