Skip to content

[Main] fix(absorbed-mla): handle delayed weight gradients - #6145

Draft
Wohox wants to merge 2 commits into
NVIDIA:mainfrom
Wohox:wohox/fix-absorbed-mla-delay-wgrad-main
Draft

[Main] fix(absorbed-mla): handle delayed weight gradients#6145
Wohox wants to merge 2 commits into
NVIDIA:mainfrom
Wohox:wohox/fix-absorbed-mla-delay-wgrad-main

Conversation

@Wohox

@Wohox Wohox commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Port of 99008e2 (landed on dev via #6020) to main, reduced to the part that actually takes effect on main, plus the corresponding unit test.

AbsorbedMLASelfAttention consumes linear_kv_up_proj.weight directly (_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

  • Build linear_kv_up_proj with a shallow config copy that sets delay_wgrad_compute = False, leaving its gradient on the plain autograd path.
  • Drop linear_kv_up_proj.backward_dw() from _backward_kv_proj() accordingly.
  • Add tests/unit_tests/transformer/experimental_attention_variant/test_attention_delay_wgrad.py: under delay_wgrad_compute=True the forward-executing MLA linears (linear_q_down_proj, linear_q_up_proj, linear_kv_down_proj, linear_proj) stay deferred until backward_dw(), while linear_kv_up_proj.weight.grad is already present after loss.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 dev commit

  • The dev commit also forwards the flush to core_attention from AbsorbedMLASelfAttention.backward_dw(). That is omitted here: DSAttention does not define backward_dw() on main, so the call would be a guarded no-op.
  • The dev hunk also covers the split K/V up-projection variant (linear_k_up_proj / linear_v_up_proj), which does not exist on main. Only the combined path is carried over.
  • The test is ported from the dev file of the same name, restricted to the absorbed-MLA coverage that applies on main (the CSA/dsv4_hybrid class and the DSA indexer-flush assertions are dev-only).

Known gap, not addressed here

On main, DSAIndexer's linear_wq_b / linear_wk / linear_weights_proj are built from the shared config, so they defer their wgrads under delay_wgrad_compute — and nothing flushes them, since DSAttention has no backward_dw() and MLASelfAttention.backward_dw() does not traverse core_attention. That is pre-existing on main and orthogonal to this fix; porting DSAttention.backward_dw() from dev is a separate change.

@copy-pr-bot

copy-pr-bot Bot commented Jul 30, 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.

Wohox and others added 2 commits July 30, 2026 17:28
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
Wohox force-pushed the wohox/fix-absorbed-mla-delay-wgrad-main branch from e3a15fd to 0d433aa Compare July 30, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant