Repository navigation
[main] moe(fix): Avoid TE cuda graph dummy attention masks - #5173
Open
yuzhongw-nvidia wants to merge 1 commit into
Open
yuzhongw-nvidia wants to merge 1 commit into
yuzhongw-nvidia wants to merge 1 commit into
Conversation
svcnvidia-nemo-ci
marked this pull request as draft
June 5, 2026 02:00
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. |
1 of 6 tasks
yuzhongw-nvidia
force-pushed
the
yuzhongw/cg-longseq-memory-debug-official-dev
branch
from
June 5, 2026 07:54
3671459 to
382cfec
Compare
yuzhongw-nvidia
marked this pull request as ready for review
June 5, 2026 07:56
14 of 21 tasks
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.
What does this PR do ?
PR for dev: #5131
Summary
This PR avoids allocating dummy attention masks for TransformerEngine CUDA graph attention when attention masks are intentionally omitted by the dataloader.
When
--no-create-attention-mask-in-dataloaderis used, the eager forward path passesattention_mask=None. The TE CUDA graph path, however, was still creating synthetic all-zero masks for capture/replay with shape[micro_batch, 1, local_seq_len, global_seq_len]. With context parallelism, scalingseq_lenand CP together keeps local sequence length constant, but the dummy mask still scaled with globalseq_len, causing unnecessary CUDA graph memory growth.Changes
create_attention_mask_in_dataloaderintoTransformerConfig.create_attention_mask_in_dataloader=False, omitattention_maskfrom both static capture inputs and replay kwargs instead of allocating a dummy mask.Validation
Validated on a Blackwell platform using a 4-layer Qwen3-30B debug recipe with partial CUDA graph enabled.
The key comparison is the same sequence-length / CP cases before vs. after the fix:
For the long-sequence cases, the fix removes the CUDA-graph-specific dummy-mask memory:
The growth from
16k-CP1 -> 64k-CP4is also reduced:5,382 MB.2,162 MB.The remaining delta matches the no-CG / MoE-only CP baseline. This confirms that the attention CUDA graph path was retaining synthetic
[local_seq_len, global_seq_len]attention masks, and that omitting those masks when--no-create-attention-mask-in-dataloaderis set removes the long-sequence CP memory regression.Issue tracking
For PRs from open-source community contributors:
Linked issue:
Contribution process
Pre-checks
Code review
Feel free to message or comment @NVIDIA/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.