[Main] fix(absorbed-mla): handle delayed weight gradients - #6145
Draft
Wohox wants to merge 2 commits into
Draft
Conversation
AbsorbedMLASelfAttention consumes the K/V up-projection weight directly, so that module never executes a forward that can enqueue Transformer Engine's delayed-wgrad closure. Under delay_wgrad_compute, backward_dw() therefore popped a closure that was never queued. Build linear_kv_up_proj with a private config copy that disables delayed wgrad, leave its gradient on the plain autograd path, and drop it from _backward_kv_proj(). Every projection that executes a GEMM continues to defer its weight gradient. Signed-off-by: Pingtian Li <pingtianl@nvidia.com> (cherry picked from commit 99008e2) The core_attention backward_dw() forwarding from that commit is omitted: DSAttention does not define backward_dw() on main, so the call would be a no-op here.
Add a delayed-wgrad unit test for AbsorbedMLASelfAttention. Under delay_wgrad_compute the MLA linears that execute a forward must stay deferred until backward_dw(), while linear_kv_up_proj receives its gradient through plain autograd and is left untouched by the flush. An eager reference run pins that the deferred path does not change the gradient values. Ported from the dev-side test_attention_delay_wgrad.py, restricted to the absorbed-MLA coverage that applies on main. Signed-off-by: Pingtian Li <pingtianl@nvidia.com> Co-authored-by: Robin Zhang <robinz@nvidia.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Pingtian Li <pingtianl@nvidia.com>
Wohox
force-pushed
the
wohox/fix-absorbed-mla-delay-wgrad-main
branch
from
July 30, 2026 09:29
e3a15fd to
0d433aa
Compare
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.
Summary
Port of 99008e2 (landed on
devvia #6020) tomain, reduced to the part that actually takes effect onmain, plus the corresponding unit test.AbsorbedMLASelfAttentionconsumeslinear_kv_up_proj.weightdirectly (_get_kv_up_weights) instead of running a GEMM through the module, so that module never executes a forward that can enqueue Transformer Engine's delayed-wgrad closure. Under--delay-wgrad-compute,backward_dw()then popped a closure that was never queued.Changes
linear_kv_up_projwith a shallow config copy that setsdelay_wgrad_compute = False, leaving its gradient on the plain autograd path.linear_kv_up_proj.backward_dw()from_backward_kv_proj()accordingly.tests/unit_tests/transformer/experimental_attention_variant/test_attention_delay_wgrad.py: underdelay_wgrad_compute=Truethe forward-executing MLA linears (linear_q_down_proj,linear_q_up_proj,linear_kv_down_proj,linear_proj) stay deferred untilbackward_dw(), whilelinear_kv_up_proj.weight.gradis already present afterloss.backward()and is left bit-identical by the flush. An eager (delay_wgrad_compute=False) reference run pins that deferring changes only when the wgrad GEMM runs, never the gradient values.Every projection that executes a GEMM continues to defer its weight gradient.
Deltas versus the
devcommitdevcommit also forwards the flush tocore_attentionfromAbsorbedMLASelfAttention.backward_dw(). That is omitted here:DSAttentiondoes not definebackward_dw()onmain, so the call would be a guarded no-op.devhunk also covers the split K/V up-projection variant (linear_k_up_proj/linear_v_up_proj), which does not exist onmain. Only the combined path is carried over.devfile of the same name, restricted to the absorbed-MLA coverage that applies onmain(the CSA/dsv4_hybridclass and the DSA indexer-flush assertions are dev-only).Known gap, not addressed here
On
main,DSAIndexer'slinear_wq_b/linear_wk/linear_weights_projare built from the shared config, so they defer their wgrads underdelay_wgrad_compute— and nothing flushes them, sinceDSAttentionhas nobackward_dw()andMLASelfAttention.backward_dw()does not traversecore_attention. That is pre-existing onmainand orthogonal to this fix; portingDSAttention.backward_dw()fromdevis a separate change.