Repository navigation
fix(MTP's memory): Reuse the GTP wgrad send buffer across a weight's repeated backwards - #7470
Merged
fanshiqing merged 1 commit intoSep 22, 2026
Conversation
… backwards Signed-off-by: Shiqing Fan <shiqingf@nvidia.com>
svcnvidia-nemo-ci
marked this pull request as draft
September 18, 2026 04:59
Contributor
|
This PR has been automatically converted to draft because all PRs must start as drafts. When you are ready for review, click Ready for Review to begin the review process. This will:
See the contribution guide for more details. |
fanshiqing
marked this pull request as ready for review
September 18, 2026 04:59
Member
Author
|
/claude reivew |
Member
Author
|
/ok to test 11fb9c2 |
kvareddy
approved these changes
Sep 19, 2026
Closed
Closed
Phlip79
approved these changes
Sep 21, 2026
Member
|
/review model=claude |
xuwchen
pushed a commit
to xuwchen/Megatron-LM
that referenced
this pull request
Sep 22, 2026
… backwards Signed-off-by: Shiqing Fan <shiqingf@nvidia.com> (cherry picked from PR NVIDIA#7470 @ 11fb9c2; not merged to main at pick time)
xuwchen
pushed a commit
to xuwchen/Megatron-LM
that referenced
this pull request
Sep 22, 2026
… backwards Signed-off-by: Shiqing Fan <shiqingf@nvidia.com> (cherry picked from PR NVIDIA#7470 @ 11fb9c2; not merged to main at pick time)
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/35703948556 |
fanshiqing
deleted the
memory_opt/reuse_gpt_wgrad_send_buf_across_repeated_bwds
branch
September 22, 2026 09:42
xuwchen
pushed a commit
to xuwchen/Megatron-LM
that referenced
this pull request
Oct 10, 2026
… backwards (NVIDIA#7470) Signed-off-by: Shiqing Fan <shiqingf@nvidia.com> (cherry picked from PR NVIDIA#7470 @ 11fb9c2; not merged to main at pick time) Signed-off-by: xuwenc <xuwenc@nvidia.com>
xuwchen
pushed a commit
to xuwchen/Megatron-LM
that referenced
this pull request
Oct 14, 2026
… backwards (NVIDIA#7470) Signed-off-by: Shiqing Fan <shiqingf@nvidia.com> (cherry picked from PR NVIDIA#7470 @ 11fb9c2; not merged to main at pick time) Signed-off-by: xuwenc <xuwenc@nvidia.com>
fanshiqing
added a commit
to fanshiqing/Megatron-LM
that referenced
this pull request
Oct 19, 2026
… backwards (NVIDIA#7470) Signed-off-by: Shiqing Fan <shiqingf@nvidia.com> (cherry picked from PR NVIDIA#7470 @ 11fb9c2; not merged to main at pick time) Signed-off-by: xuwenc <xuwenc@nvidia.com> (cherry picked from commit 0951cdc) Signed-off-by: Shiqing Fan <shiqingf@nvidia.com>
This branch was previously deployed
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.
TL;DR
This MR help reduce the MTP's output_layer's GTP_reduce_scatter input buffer memory cost:
saves 10GBe2esaves 5GBe2eProblem: The step up to 2 never comes back down, because the pool never shrinks.
Fix: When a weight gets several backwards per iteration (MTP's repeated block),
get_wgrad_tensornow drains that weight's own in-flight reduce-scatter and reuses its send buffer instead of allocating a second one, saving 10GB (vocab-256k) at no measurable throughput cost.What
The GTP symmetric reduce-scatter send pool never shrinks, so every buffer it
holds is live at the memory peak. A weight with more than one backward per
iteration reaches
get_wgrad_tensorwhile its previous send is still in flight,so the pool grows by one permanent buffer — 5 GiB for a vocab-sized fp32
wgrad.
Found via MTP's repeated block, but not specific to it.
How
Drain that weight's own reduce-scatter and reuse the buffer instead of
allocating, trading one overlap for the permanent bytes.
RegisteredLIFOPool.has_free()limits the drain to the case where thealternative is a new allocation — no overlap given up otherwise.
rs_event.wait()fences the compute-stream wgrad GEMM against thestill-reading send.
Measured (rank 0, 4x GB200, MTP on)
−5.39 GiB, three independent measures agreeing; exactly two buckets lose a
duplicate. Loss bit-identical on iterations 1–2.
Scope
No-op without
--gtp*-remat-nccl-ub, under CUDA-graph capture, or when a weighthas a single backward per iteration.
Tests
Two new
has_freecases intest_gtp_symmetric_memory.py.Convergence Test: passed on NT4 nano model