Skip to content

Add a backwards linear function to be used with the fused mla q up-proj - #3330

Open
chaseblock wants to merge 13 commits into
NVIDIA:mainfrom
chaseblock:lin_bwd
Open

Add a backwards linear function to be used with the fused mla q up-proj#3330
chaseblock wants to merge 13 commits into
NVIDIA:mainfrom
chaseblock:lin_bwd

Conversation

@chaseblock

Copy link
Copy Markdown
Contributor

Description

Please include a brief summary of the changes, relevant motivation and context.

Fixes # (issue)

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

Please list the changes introduced in this PR:

  • Change A
  • Change B

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

Signed-off-by: Chase Block <cblock@nvidia.com>
@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Aug 7, 2026
chaseblock added a commit to chaseblock/Megatron-LM that referenced this pull request Aug 7, 2026
Requires TE PR: NVIDIA/TransformerEngine#3330

Signed-off-by: Chase Block <cblock@nvidia.com>
@greptile-apps

greptile-apps Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds an autograd-enabled backward path for the fused MLA Q up-projection and exports the new function through the PyTorch attention APIs.

  • Implements RoPE and linear backward processing for input and weight gradients.
  • Adds FP8/BF16 forward coverage and an autograd gradient test.
  • Explicitly rejects unsupported tensor-parallel execution.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
transformer_engine/pytorch/attention/fused_mla_q_uproj.py Adds the custom autograd function, Triton RoPE backward kernel, and linear-backward delegation; the previously reported bias-gradient concern is inapplicable because this API has no bias.
tests/pytorch/attention/test_fused_mla_q_uproj.py Expands GB200-only forward coverage to FP8 and BF16 weights and validates input and weight gradients through the new autograd path.
transformer_engine/pytorch/attention/init.py Publicly exports FusedMLAQUpProjFunction from the attention package.
transformer_engine/pytorch/init.py Re-exports FusedMLAQUpProjFunction from the top-level PyTorch package.

Reviews (10): Last reviewed commit: "[pre-commit.ci] auto fixes from pre-comm..." | Re-trigger Greptile

Comment thread transformer_engine/pytorch/module/linear.py Outdated
Signed-off-by: Chase Block <cblock@nvidia.com>
Signed-off-by: Chase Block <cblock@nvidia.com>
Comment thread transformer_engine/pytorch/module/linear.py Outdated
@cyanguwa cyanguwa added the 2.19 label Aug 10, 2026
@cyanguwa
cyanguwa requested review from sudhakarsingh27 and removed request for cyanguwa and ksivaman August 10, 2026 21:58
Comment thread transformer_engine/pytorch/module/linear.py Outdated
sudhakarsingh27 and others added 2 commits August 11, 2026 15:15
Port the RoPE and projection backward needed by the fused Q up-projection path. Keep the one-use Triton kernel colocated and optional, and request both gradients because this temporary wrapper returns both. Cover the real MXFP8 autograd path so dgrad and wgrad are verified end to end.

Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
Signed-off-by: Chase Block <cblock@nvidia.com>
@sudhakarsingh27

Copy link
Copy Markdown
Member

/te-ci pytorch L0

sudhakarsingh27 and others added 5 commits August 12, 2026 15:21
Record the source of the copied Triton RoPE helpers in the module docstring so their Megatron-LM origin remains clear as the TE implementation evolves.

Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
This especially focuses on fixing up the backward correctness
test for the Q UpProj + Rope + Quant fusion path.

Signed-off-by: Chase Block <cblock@nvidia.com>
I don't think this test was actually flagging something that matters,
since it was comparing against a pytorch reference that does not
actually reflect the alternative, unfused path that we should be
comparing against.

Signed-off-by: Chase Block <cblock@nvidia.com>
@greptile-apps

greptile-apps Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants