Skip to content

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

Merged
sudhakarsingh27 merged 16 commits into
NVIDIA:mainfrom
chaseblock:qrope_fusion
Aug 7, 2026
Merged

Add support for fused Q Up-Proj GEMM/RoPE/Quant.#3303
sudhakarsingh27 merged 16 commits into
NVIDIA:mainfrom
chaseblock:qrope_fusion

Conversation

@chaseblock

Copy link
Copy Markdown
Contributor

This PR adds support for fusing the GEMM in the Q Up Proj step of DeepseekV3 training with the following RoPE and MXFP8 quantization operations. This uses a custom kernel from cudnn_frontend, and supports both 16-bit projection and mxfp8 projection.

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@github-actionsgithub-actionsBot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Aug 3, 2026
@greptile-apps

greptile-appsBot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR introduces a Blackwell-targeted fused MLA Q up-projection, RoPE, and MXFP8 quantization path and integrates its pre-quantized output with fused attention.

  • Exposes FusedMLAQUpProjRopeQuant through the PyTorch attention API.
  • Adds MXFP8 layout preparation and optional BF16 attention-gradient handling.
  • Adds forward numerical coverage and registers the test in the L0 PyTorch job.

Confidence Score: 5/5

The PR appears safe to merge based on the eligible follow-up findings available in this review.

No blocking failure remains.

Important Files Changed

FilenameOverview
transformer_engine/pytorch/attention/fused_mla_q_uproj.pyAdds feature detection and the cuDNN frontend wrapper for fused Q projection, RoPE, and MXFP8 output construction.
transformer_engine/pytorch/attention/dot_product_attention/utils.pySplits MXFP8 preparation into quantization and scale transpose/swizzle phases to accommodate pre-quantized tensors.
transformer_engine/pytorch/attention/dot_product_attention/dot_product_attention.pyAdds pre-quantized MXFP8 layout detection and forwards the requested backward precision to fused attention.
transformer_engine/pytorch/attention/dot_product_attention/backends.pyIntegrates pre-quantized MXFP8 scale metadata and optional BF16 Q/K/V gradients into the fused-attention autograd path.
tests/pytorch/attention/test_fused_mla_q_uproj.pyAdds Blackwell-gated forward numerical and saved-activation checks for the new fused operation.
qa/L0_pytorch_unittest/test.shRegisters the new fused MLA test in the L0 PyTorch unit-test job.

Sequence Diagram

sequenceDiagram
participant Model
participant Fusion as Fused MLA Q Up-Proj
participant Quant as MXFP8 Layout Preparation
participant DPA as DotProductAttention
participant cuDNN as cuDNN Fused Attention
Model->>Fusion: Q-LORA activation, weight, cos, sin
Fusion->>Fusion: GEMM + per-head RoPE + MXFP8 quantization
Fusion-->>Quant: Quantized Q and saved activation
Model->>Quant: K and V
Quant->>Quant: Quantize and transpose/swizzle scales
Quant->>DPA: Pre-quantized Q, K, V
DPA->>cuDNN: MXFP8 fused-attention request
cuDNN-->>DPA: Attention output
DPA-->>Model: Output and backward gradients
Loading

Reviews (11): Last reviewed commit: "Merge branch 'main' into qrope_fusion" | Re-trigger Greptile

@sudhakarsingh27sudhakarsingh27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. Commented feedback inline
  2. Pls fix DCA here and in the other PR
  3. Also, I wonder if you've measured perf for mxfp8_quantize_only and its swizzle counterpart. I feel they could be further optimized as I see a lot of for loops.

Comment threadtransformer_engine/pytorch/attention/fused_mla_q_uproj.py Outdated
Comment threadtransformer_engine/pytorch/attention/fused_mla_q_uproj.py Outdated
Comment threadtransformer_engine/pytorch/attention/fused_mla_q_uproj.py
Comment threadtransformer_engine/pytorch/attention/fused_mla_q_uproj.py Outdated
Comment threadtransformer_engine/pytorch/attention/fused_mla_q_uproj.py
Comment threadtransformer_engine/pytorch/attention/dot_product_attention/utils.py Outdated
chaseblockand others added 5 commits August 5, 2026 08:32
This commit add support for fusing the GEMM in the Q Up Proj
step of DeepseekV3 training with the following RoPE and MXFP8
quantization operations. This uses a custom kernel from cudnn_frontend,
and supports both 16-bit projection and mxfp8 projection.
Signed-off-by: Chase Block <cblock@nvidia.com>
Signed-off-by: Chase Block <cblock@nvidia.com>
Signed-off-by: Chase Block <cblock@nvidia.com>
chaseblock added a commit to chaseblock/Megatron-LM that referenced this pull request Aug 5, 2026
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>
@chaseblock

Copy link
Copy Markdown
ContributorAuthor
  1. Commented feedback inline
  2. Pls fix DCA here and in the other PR
  3. Also, I wonder if you've measured perf for mxfp8_quantize_only and its swizzle counterpart. I feel they could be further optimized as I see a lot of for loops.

Addressed inline feedback.

DCA fixed.

I haven't explicitly modeled the perf of these two functions, but they were essentially extracted from the existing combine_and_quantize, which we needed to break apart since one of the tensors is now being quantized beforehand.

@sraman-rgb

Copy link
Copy Markdown
Collaborator

/te-ci pytorch

mxfp8_quantize_fast_path.
Signed-off-by: Chase Block <cblock@nvidia.com>
Signed-off-by: Chase Block <cblock@nvidia.com>
Signed-off-by: Chase Block <cblock@nvidia.com>
Comment threadtransformer_engine/pytorch/attention/fused_mla_q_uproj.py Outdated
Comment threadtests/pytorch/attention/test_fused_mla_q_uproj.py Outdated
These tests really belong in Megatron.
Signed-off-by: Chase Block <cblock@nvidia.com>

@sudhakarsingh27sudhakarsingh27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sudhakarsingh27
sudhakarsingh27 merged commit dd96595 into NVIDIA:mainAug 7, 2026
10 of 14 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.19community-contributionPRs from external contributor outside the core maintainers, representing community-driven work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@chaseblock@sraman-rgb@sudhakarsingh27@nvMelissa