Add support for custom all-reduce operators under SOT mode #4386
+5
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
本 PR 的主要操作是将SOT warmup的过程延后,在CUDAGraph的Capture阶段进行warmup
本PR的前置PR
这个PR终于跑通 SOT + CUDAGraph + 开启子图切分的整个流程,在这个PR中梳理一下整个过程:
单卡模型
以下是 @zyfncg 的前置PR,SOT下实现CudaGraph子图捕获功能,我们快速跑通了 ERNIE45T 0.3B✅
但是依旧存在显存拷贝的问题,如果输入的位置发生改变,则将新输入Copy到Capture的位置
为了解决这个问题,#3302 添加了 append_attention_with_output,在运行 append_attention 之前,优先创建一个 empty Tensor 作为 append_attention 的输出——在外部管理 append_attention 的显存
#3694 修复了 #3302 导致的打断,#4340(是 #3694 的一部分)移除了一些无用的输出,避免动静不统一导致的BUG
#3694 依赖 Paddle 主框架的两个PR:
memcpy
Paddle#75078到此为止,单卡的 ERNIE45T 21B和0.3B 都能跑通✅,且不存在 Copy,但是多卡运行会遇到CUDA700的问题
多卡模型
遇到到第一个CUDA700问题,不开CUDAGraph,只开SOT就能复现
用 cuda-gdb 分析这个CUDA700的问题,定位到是 Custom Allreduce 的问题,可暂时通过
--max-num-batched-tokens 2000
规避与 @zhink 沟通后,可通过调大 Custom Allreduce 的 Buffer 大小来规避,即:
此时SOT + Custom Allreduce 可以跑通推理流程 ✅
但开启 CUDAGraph 遇到 mp_allreduce_sum 对应的 DeviceContext 存在 cudagraph allocator 为空指针的问题
我把所有 Instruction 对应的 DeviceContext 指针打印了出来,统计了一下,共有1个
CPUContext
+2个GPUContext
出现次数分别是几十次、几千次和几万次,而动态图+CUDAGraph只有1个
CPUContext
+1个GPUContext
定位到是
phi::DeviceContext* ParseDeviceContext
这个函数将GPUContext
(有cudagraph allocator)转化成了另一个GPUContext
(无cudagraph allocator),这里为了先跑通,就先直接return origin_dev_ctx;
了,(后续PR: TBC)但依旧会有 CUDA700 的问题中间其实也尝试了很多其他方法,和老代码 battle 了好久,遇到了多 CUDA Stream 的问题,CUDA90X之类的,这时,@zyfncg 说:
好,那就先解这个CUDA700,悲催的是,用之前的方法:cuda-gdb 分析,会出现连环 core dump 的问题,在生成 coredump 文件中,又报一个 CUDA700 🤦♂️
@zyfncg 又问了一个关键的问题:目前的问题是 Capture 阶段还是 Replay 阶段?我们把 Capture 过程中的 Replay 全都注释掉看看
把 Capture 过程中的 Replay 全都注释掉后,服务就能启动了,这其实说明是Replay阶段报的错,Capture阶段没问题
TBC