Repository navigation
fix: preserve dtype across pipeline parallel communication - #255
Open
JYMiracle305 wants to merge 1 commit into
Open
JYMiracle305 wants to merge 1 commit into
JYMiracle305 wants to merge 1 commit into
Conversation
chen2021673
requested changes
Nov 4, 2026
| void ISend::SetupContext( | ||
| const std::vector<std::shared_ptr<Tensor>> &input_tensors, | ||
| const std::vector<std::shared_ptr<Tensor>> &output_tensors) { | ||
| CHECK_EQ(input_tensors.size(), shapes_.size()) |
Collaborator
There was a problem hiding this comment.
这个检查可以提前到 ISend::Forward() 的入口处,在forward 之前就先检查
Contributor
Author
There was a problem hiding this comment.
把这个检查提到了 ISend::Forward() 入口处
Collaborator
There was a problem hiding this comment.
这里潜在的默认行为是 IRecv::Backward send 的类型由 grad_outputs 中各个 Tensor 自身的 dtype 决定。但比如LinearBackwardInput 的 grad_outputs 可能为 FP32,但用 BF16 计算,就会变成
前向 activation:BF16
↓
下游 Linear backward 产生梯度:FP32
↓
IRecv::Backward 原样发送:FP32
↓
上游 ISend::Backward 按保存的前向类型接收:BF16
如果要解决这个问题就得在 IRecv::Backward 和 ISend::Backward 配套,都先发送梯度的类型,再发送梯度。但这样其实增加了通信成本。可以先这样过渡,留个 fixme 后续对照 Megatron 支持配置 pipeline_dtype 或类似的功能。
JYMiracle305
force-pushed
the
fix/pp-dtype-communication
branch
from
November 4, 2026 12:27
7e159f2 to
8f81875
Compare
Chamberlain0w0
approved these changes
Nov 5, 2026
JYMiracle305
force-pushed
the
fix/pp-dtype-communication
branch
from
November 5, 2026 10:09
8f81875 to
80f5c16
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
背景
Pipeline Parallel 在 stage 间接收 activation 和 gradient 时,会固定按照
float32创建接收张量。当训练启用
bfloat16等非 FP32 dtype 时,发送端和接收端的张量 dtype 不一致,可能导致 PP 通信失败或程序崩溃。修改内容
ISend的 autograd context 中保存输入张量 dtype。