【分布式训练中 各种并行方案 分别用什么通信 为什么?比如DP会用到 ALL reduce】
并行方式切分对象主要通信为什么需要
DPBatchAllReduce每张卡算出的梯度不同,需要同步梯度
TPWeight(权重)AllReduce / AllGather / ReduceScatter每张卡只有部分权重或部分输出,需要恢复完整计算
PPLayerSend / Recv (P2P)下一层在另一张 GPU,需要传递激活值和梯度
ZeRO-1Optimizer StateAllReduce参数完整,只同步梯度
ZeRO-2Optimizer + GradientReduceScatter + AllGather(或 AllReduce 的等价实现)梯度分片存储,需要分发和聚合
ZeRO-3 / FSDPParameter + Gradient + OptimizerAllGather + ReduceScatter参数也是分片的,每层计算前需要恢复完整参数
Sequence ParallelSequenceAllGather + ReduceScatterAttention 等算子需要完整 Sequence
Context ParallelContextAllGather / AllToAll(实现相关)长上下文 Attention 需要跨 GPU 的 KV
Expert Parallel(MoE)ExpertAllToAllToken 要发送到负责该 Expert 的 GPU