Skip to content

Add support for fused Q Up-Proj GEMM/RoPE/Quant - #6213

Open
chaseblock wants to merge 15 commits into
NVIDIA:mainfrom
chaseblock:qrope_fusion
Open

Add support for fused Q Up-Proj GEMM/RoPE/Quant#6213
chaseblock wants to merge 15 commits into
NVIDIA:mainfrom
chaseblock:qrope_fusion

Conversation

@chaseblock

Copy link
Copy Markdown

This commit adds support for fusing the q up proj gemm with the following rope and mxfp8 quantization operations. Relies on the TE functionality from here.

  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do?

Allows us to fuse the DeepseekV3 Q up proj gemm with the succeeding rope and mxfp8 quantization operations, improving training performance.

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

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"

  1. When your PR is ready, click Ready for Review.
  2. An oncall reviewer is auto-assigned and expert reviewers are notified based on your changes.
    • Some PRs may jump straight to step 2. This is determined by .github/CODEOWNERS.

⚠️ Only mark as ready once merge-conflicts are resolved and the CI is passing.
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, the Final Review label 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 Approved label is applied automatically.

Merge

Any member of mcore-engineers will be able to merge your PR.

@chaseblock
chaseblock requested review from a team as code owners August 3, 2026 15:46
@copy-pr-bot

copy-pr-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci
svcnvidia-nemo-ci marked this pull request as draft August 3, 2026 15:47
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
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:

  1. Add the oncall reviewer (optional reviewer)
  2. Add required review teams based on your changes

See the contribution guide for more details.

@chaseblock
chaseblock marked this pull request as ready for review August 3, 2026 16:47
Comment thread megatron/core/transformer/multi_latent_attention.py Outdated
This commit adds support for fusing the q up proj gemm with the
following rope and mxfp8 quantization operations. Relies on the
TE functionality from
NVIDIA/TransformerEngine#3303

Signed-off-by: Chase Block <cblock@nvidia.com>
Signed-off-by: Chase Block <cblock@nvidia.com>
@sraman-rgb

Copy link
Copy Markdown
Contributor

/ok to test d76dee1

Signed-off-by: Chase Block <cblock@nvidia.com>
auto-merge was automatically disabled August 5, 2026 19:01

Head branch was pushed to by a user without write access

@sraman-rgb

Copy link
Copy Markdown
Contributor

/ok to test c262d0a

sraman-rgb and others added 3 commits August 5, 2026 15:33
Signed-off-by: Chase Block <cblock@nvidia.com>
Signed-off-by: Chase Block <cblock@nvidia.com>
Comment thread megatron/core/transformer/multi_latent_attention.py Outdated
Comment thread megatron/core/transformer/multi_latent_attention.py
Comment thread megatron/core/transformer/multi_latent_attention.py Outdated
# --- RoPE backward (unchanged: bf16, same rotary_bwd_q_kernel as the unfused path) ---
dq3 = dq.reshape(tokens, nh, q_head_dim).contiguous()
grid = lambda META: (tokens, triton.cdiv(nh, META["BLOCK_H"]))
rotary_bwd_q_kernel[grid](

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there plans to add a backward fusion? If not is there a way to avoid duplicating the backward pass that done here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't been considering a backwards fusion as far as I know, but I don't know that there's a better way to deduplicate this code at the moment.

I think this would require heavier changes to TE fully deduplicate this, and I'm not sure that this is worth it at this point.

chaseblock and others added 3 commits August 6, 2026 05:12
Enabling this in the future will require either further modifications
to the attention interface or reworking how the P2P communication
works for CP.

Signed-off-by: Chase Block <cblock@nvidia.com>
Signed-off-by: Chase Block <cblock@nvidia.com>
@sraman-rgb
sraman-rgb enabled auto-merge August 7, 2026 14:56
@sraman-rgb

Copy link
Copy Markdown
Contributor

/ok to test 7822da3

Requires TE PR: NVIDIA/TransformerEngine#3330

Signed-off-by: Chase Block <cblock@nvidia.com>
auto-merge was automatically disabled August 7, 2026 21:15

Head branch was pushed to by a user without write access

@sraman-rgb

Copy link
Copy Markdown
Contributor

/ok to test 9527108

chaseblock and others added 2 commits August 10, 2026 13:04
Signed-off-by: Chase Block <cblock@nvidia.com>
Remove the duplicated Megatron autograd and RoPE-backward implementation because Transformer Engine now owns that operation. Keep Megatron responsible for routing and integration, enforce the MXFP8 DPA and zero-dropout contract found during B200 validation, and test the full Megatron-to-TE backward path.

Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Final Review PR is in the "final review" stage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants