Add gdn_qkv whole-block recompute for GatedDeltaNet - #9
Merged
wplf merged 2 commits intoJun 3, 2026
Merged
Conversation
Reviewer's GuideAdds a new selective-recompute option Sequence diagram for new gdn_qkv selective recompute pathsequenceDiagram
participant GatedDeltaNet as GatedDeltaNetLayer
participant Checkpoint as tensor_parallel.checkpoint
participant TECheckpoint as te_checkpoint
participant GDRule as gated_delta_rule
GatedDeltaNet->>GatedDeltaNet: forward(hidden_states)
alt recompute_qkv and training
alt fp8 or fp4
GatedDeltaNet->>TECheckpoint: te_checkpoint(_qkv_proj_and_prepare, False, get_cuda_rng_tracker, tp_group, hidden_states)
TECheckpoint->>GatedDeltaNet: query,key,value,g,beta,gate
else non_fp8_fp4
GatedDeltaNet->>Checkpoint: checkpoint(_qkv_proj_and_prepare, False, hidden_states)
Checkpoint->>GatedDeltaNet: query,key,value,g,beta,gate
end
else no_qkv_recompute
GatedDeltaNet->>GatedDeltaNet: _compute_qkv_for_gated_delta_rule(hidden_states, batch, seq_len, cu_seqlens_q, packed_seq_params)
GatedDeltaNet-->>GatedDeltaNet: query,key,value,g,beta,gate
end
GatedDeltaNet->>GatedDeltaNet: seq_len = value.shape[1]
GatedDeltaNet->>GDRule: gated_delta_rule(query,key,value,g,g,beta,cu_seqlens_q)
GDRule-->>GatedDeltaNet: core_attn_out,last_recurrent_state
GatedDeltaNet->>GatedDeltaNet: _gated_norm_and_a2a(core_attn_out,gate)
GatedDeltaNet-->>GatedDeltaNet: norm_out
GatedDeltaNet->>GatedDeltaNet: out_proj(norm_out)
GatedDeltaNet-->>GatedDeltaNet: out,out_bias
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
wplf
marked this pull request as ready for review
June 2, 2026 08:54
wplf
force-pushed
the
jinliangl/gdn-qkv-recompute-clean
branch
2 times, most recently
from
June 3, 2026 09:03
7d132d7 to
04a4a57
Compare
Recompute the GatedDeltaNet QKV projection + preparation block (in_proj -> CP all-to-all -> conv1d -> _prepare_qkv -> g/beta) as a discard-output checkpoint, selected via recompute_modules="gdn_qkv". The block outputs (query/key/value/ g/beta/gate) are discarded in the forward and regenerated from a grad hook in the backward, freeing the large GDN QKV-prep activations. When gdn_norm_out recompute is also enabled, the two discard-output checkpoints have a forward-order data dependency (the QKV block output `gate` feeds the gated-norm block), so both are registered to a single CheckpointManager that replays their recompute in forward order (qkv -> norm_out) from one unified grad hook on the layer output. Adds "gdn_qkv" to the selective-recompute allowed_modules in TransformerConfig.
wplf
force-pushed
the
jinliangl/gdn-qkv-recompute-clean
branch
from
June 3, 2026 09:09
04a4a57 to
03d0ed3
Compare
Adds test_selective_recompute_gdn_qkv (mirrors test_selective_recompute_norm_out) to TestGatedDeltaNet: builds a no-recompute baseline GatedDeltaNet and one with recompute_modules=["gdn_qkv"], runs forward+backward, and asserts the output, all parameter grads and the input grad match bit-for-bit. Verifies the QKV projection+prep discard-output recompute is numerically exact.
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.
What
Adds a new selective-recompute module
gdn_qkvthat wraps the entire GatedDeltaNet QKV projection + preparation block (in_proj→ CP all-to-all →conv1d→_prepare_qkv→g/beta) in a single activation checkpoint, analogous torecompute_modules="moe"wrapping the whole MoE forward.gated_delta_net.py: extract the QKV-proj+prep span into_compute_qkv_for_gated_delta_rule(...)returning(query, key, value, g, beta, gate); inforward, run it directly or viatensor_parallel.checkpoint/te_checkpoint(fp8) when"gdn_qkv"is inrecompute_modules.seq_len(reassigned to the post-CP-a2a length inside the block) is recovered fromvalue.shape[1]after the call.transformer_config.py: registergdn_qkvin the allowedrecompute_modulesset and guard that it requiresexperimental_attention_variant="gated_delta_net"(mirrorsgdn_norm_out).Why
The GDN QKV-prep activations previously had no recompute/offload knob and were a large share of per-layer activation memory.
Validation
Qwen3.5-VL 397B proxy, 8×GB200 (EP=8, mbs=4, multimodal entry), 20 iters, stable loss (no NaN/skips):
gdn_qkv)gdn_qkv493–498 TFLOP/s (−3%)🤖 Generated with Claude Code
Summary by Sourcery
Add a selective activation recompute option for the GatedDeltaNet QKV projection and preparation block and wire it into the transformer configuration.
Enhancements: