[Dev] Support delayed wgrad compute overlap with P2P backward#4268
Draft
Wohox wants to merge 4 commits intoNVIDIA:devfrom
Draft
[Dev] Support delayed wgrad compute overlap with P2P backward#4268Wohox wants to merge 4 commits intoNVIDIA:devfrom
Wohox wants to merge 4 commits intoNVIDIA:devfrom
Conversation
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.
What does this PR do ?
Improve P2P Communication Overlap in Fine-Grained 1F1B Schedule
Problem
In the interleaved 1F1B pipeline schedule with fine-grained layer scheduling (
model_chunk_schedule_plan.py), P2P communication latency is exposed due to two issues:Backward P2P runs on the computation stream. Unlike forward P2P (
post_forward), which is placed on the communication stream, backward P2P (post_backward) runs on the computation stream. This prevents backward P2P from overlapping with the next VPP stage's forward compute.Insufficient wgrad compute to hide P2P latency. Only the last backward layer's attention wgrad is deferred after P2P. When this single GEMM is not long enough to cover the P2P communication time, the remaining P2P latency is exposed.
Solution
Three independently controllable flags are introduced, all orthogonal and composable:
--overlap-p2p-backward-on-comm-stream(bool, defaultFalse): Placespost_backwardon the communication stream (mirroringpost_forward), so backward P2P and computation can run in parallel on separate CUDA streams.--overlap-p2p-wgrad-delayed-layer-number N(int, default1): Controls how many of the last backward layers defer their weight gradient computation to afterpost_backward. Increasing N accumulates more wgrad GEMMs to overlap with P2P. Default of 1 preserves the original behavior.--overlap-p2p-with-transformer-layer-wgrad(bool, defaultFalse): When enabled, deferred layers delay both attention and MLP weight gradients (instead of attention only), providing more compute to hide P2P latency.Usage
Flags can be combined freely. Examples:
Contribution process
Pre-checks
Code review
Feel free to message or comment the @mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!
All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.
Step 1: Mark PR as "Ready for Review"
.github/CODEOWNERS.Final Review might get declined if these requirements are not fulfilled.
Step 2: Final Review
For PRs that change
megatron/core, once all expert reviewers have approved, theFinal Reviewlabel is applied automatically and final reviewers are assigned.For PRs outside
megatron/core, this step is skipped.Step 3: Approved
Once all required reviewers have approved, the
Approvedlabel is applied automatically.Merge
Any member of mcore-engineers will be able to merge your PR.
For MRs into `dev` branch
The proposed review process for `dev` branch is under active discussion.MRs are mergable after one approval by either
eharper@nvidia.comorzijiey@nvidia.com.