Add a backwards linear function to be used with the fused mla q up-proj - #3330
Add a backwards linear function to be used with the fused mla q up-proj#3330chaseblock wants to merge 7 commits into
Conversation
Signed-off-by: Chase Block <cblock@nvidia.com>
Requires TE PR: NVIDIA/TransformerEngine#3330 Signed-off-by: Chase Block <cblock@nvidia.com>
for more information, see https://pre-commit.ci
Greptile SummaryThe PR adds autograd support for the fused MLA query up-projection by applying the inverse RoPE transformation and delegating projection gradients to TE’s linear backward implementation.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Sequence DiagramsequenceDiagram
participant A as PyTorch autograd
participant R as RoPE backward kernel
participant L as TE linear backward
A->>R: Query output gradient
R-->>A: Pre-RoPE projection gradient
A->>L: Gradient, saved input, weight
L-->>A: Input and weight gradients
Reviews (5): Last reviewed commit: "Add fused MLA Q up-projection backward" | Re-trigger Greptile |
Signed-off-by: Chase Block <cblock@nvidia.com>
Signed-off-by: Chase Block <cblock@nvidia.com>
| inputmat=x_saved, | ||
| weight_fp8=w_q, | ||
| saved_weight=w_q, | ||
| bias=None, |
There was a problem hiding this comment.
BF16 bias gradient remains missing
When a BF16 fused MLA backward call sets use_bias=True, this wrapper still passes bias=None; the non-FP8 path delegates bgrad to the weight-gradient GEMM, which does not allocate db without a bias tensor, causing backward_linear to return grad_bias=None and preventing the projection bias from being updated.
Knowledge Base Used: PyTorch Fused Modules (transformer_engine/pytorch/module)
| return (saved_inputmat, wt_save, saved_weight, saved_bias) | ||
|
|
||
|
|
||
| def backward_linear( |
There was a problem hiding this comment.
Do we really need this function as we could directly call _linear_backward? If we absolutely need it, could we move it to fused_mla_q_uproj.py instead then?
Signed-off-by: Chase Block <cblock@nvidia.com>
for more information, see https://pre-commit.ci
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>
Description
Please include a brief summary of the changes, relevant motivation and context.
Fixes # (issue)
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: