Repository navigation
fix: preserve dtype across pipeline parallel communication - #255
Conversation
7e159f2 to
8f81875
Compare
fa16795 to
6cf4962
Compare
6cf4962 to
6acd897
Compare
6acd897 to
be3e354
Compare
be3e354 to
fdaa719
Compare
| // precision | ||
| DEFINE_string(dtype, "float32", | ||
| "precision used in training (float32/bfloat16)"); | ||
| DEFINE_string(pipeline_dtype, "float32", |
There was a problem hiding this comment.
现在写死了 --pipeline_dtype=fp32,有没有验证过--pipeline_dtype=bf16 的正确性?test_config 里可以配一个测例。
There was a problem hiding this comment.
在dtype = bf16 场景下,设置 pipeline_dtype=bf16,会在stage之间进行 fp32 到 bf16、bf16 到 fp32 的两次转换,这会导致精度下降,在LLaMA3、Qwen3 都会因为误差累积出现异常,所以现在 pipeline_dtype 默认用 fp32
There was a problem hiding this comment.
确实。看了一下 Megatron的 params_dtype 和 pipeline_dtype 逻辑,是训练精度指定的 dtype 可以直接控制权重和激活的精度(params_dtype)、op 计算精度 、pp边界精度(pipeline_dtype 默认跟随该 params_dtype);但也同样支持在自定义 transformer_config 的时候传入。但 InfiniTrain 目前只有 op 级 autocast,--dtype 不改激活精度,没有 params_dtype 这一参数,PP 边界始终是 fp32,所以设置 --pipeline_dtype bf16 会有问题。
可以加个 TODO 来描述这个问题。以后如果需要进一步优化,需要把现在的 --dtype=bf16 从”只控制 op 级 autocast”扩展到“完整的“bf16 栈”,统一控制 params/计算精度/wire。
668f0a9 to
011e382
Compare


背景
Pipeline Parallel 在 stage 间接收 activation 和 gradient 时,此前固定使用
float32创建接收张量。当训练启用bfloat16等非 FP32 dtype 时,通信两端的 buffer dtype 可能不一致,导致 PP 通信失败或程序崩溃。修改内容
ModelParallelConfig中引入pipeline_dtype,作为 PP stage 间统一的通信 dtype,语义对齐 Megatron。--pipeline_dtype配置,默认float32,可显式选择bfloat16以降低通信带宽。pipeline_dtype;接收端使用pipeline_dtype创建 buffer,接收后交给当前 stage,由既有 autocast 机制处理算子级 dtype。pipeline_dtype;上游使用pipeline_dtype创建接收 buffer,并在接收后恢复为前向原始 input dtype。master并解决冲突。验证
clang++ 18 -fsyntax-only覆盖send_recv.cc、pipeline_schedule.cc、datatype.cc以及 GPT-2 / LLaMA3 / Mixtral / Qwen3 示例。clang-format --dry-run --Werror覆盖全部改动源文件。