fix: resolve GPU memory leak in pipeline parallel training#148
Merged
kilinchange merged 1 commit intomasterfrom Apr 24, 2026
Merged
fix: resolve GPU memory leak in pipeline parallel training#148kilinchange merged 1 commit intomasterfrom
kilinchange merged 1 commit intomasterfrom
Conversation
Contributor
Author
cfcc049 to
96341ef
Compare
Contributor
Author
kilinchange
approved these changes
Apr 24, 2026
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.



原因:
ReceiveFromPrev 中创建的接收 tensor 形成了 autograd 引用环:
recv_tensors → grad_fn(IRecv) → IRecv.next_functions → AccumulateGrad.tensor_ → recv_tensors正常情况下 autograd graph 是 DAG,backward 完成后函数对象会级联销毁。但环的存在导致环中对象的 ref count 永远无法降到 0,整个 graph 无法释放,每一步都残留一个闭环,used 显存持续增长。
修复方案:
创建用于在PP chunk之间接收通信数据的 tensor 时将其标记为非 leaf,
set_is_leaf(false)。这样 IRecv::Apply 中不会创建AccumulateGrad,闭环在源头被切断,graph 可以正常销毁。