[Dev] Enable selective recompute for norm_out in GDN layers - #5443
Open
wplf wants to merge 1 commit into
Open
Conversation
Port the gdn_norm_out selective recompute (NVIDIA#4715, merged to main) onto the dev branch, adapting it to dev's GatedDeltaNet structure. Recompute only the gated output norm + HP-to-CP all-to-all block as a discard-output checkpoint, selected via recompute_modules=["gdn_norm_out"]. The block output (norm_out) is discarded in the forward after out_proj consumes it and regenerated from a grad hook on the layer output in the backward, freeing the gated-norm activations (~2-3% per-layer activation memory, <=2% iter-time cost). Adaptations vs the main-branch PR: - The gated norm + all-to-all span lives in dev's _forward_compute helper and uses the dynamic cp_size/cp_group plus the _a2a_hp_to_cp() helper and the thd_cp_a2a_inv permutation, so the extracted _gated_norm_and_a2a closure captures those locals. - Gate the discard-output checkpoint on self.training (matches dev's whole-module "gdn" recompute convention) so eval/inference runs the block normally. - Add a validation guard that "gdn" and "gdn_norm_out" cannot be combined: the whole-module "gdn" recompute already wraps this block, so combining them would nest checkpoints. Adds test_selective_recompute_norm_out asserting the output, all parameter grads and the input grad match the no-recompute baseline bit-for-bit. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: jinliangl <975761915@qq.com>
wplf
marked this pull request as ready for review
June 23, 2026 05:58
Contributor
Author
|
/ok to test de151f5 |
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 the
gdn_norm_outselective recompute (#4715, merged tomain) onto thedevbranch, adapting it to dev'sGatedDeltaNetstructure.Recompute only the gated output norm + HP-to-CP all-to-all block as a discard-output checkpoint, selected via:
The block output (
norm_out) is discarded in the forward onceout_projconsumes it, and regenerated from a grad hook on the layer output in the backward, freeing the gated-norm activations. Per #4715 this saves ~2–3% per-layer activation memory at ≤2% iteration-time cost.Adaptations vs the main-branch PR (#4715)
_forward_computehelper and uses the dynamiccp_size/cp_groupplus the_a2a_hp_to_cp()helper and thethd_cp_a2a_invpermutation, so the extracted_gated_norm_and_a2aclosure captures those locals.self.training(matching dev's whole-modulegdnrecompute convention) so eval/inference runs the block normally.gdnandgdn_norm_outcannot be combined: the whole-modulegdnrecompute (dev-only) already wraps this block, so combining them would nest checkpoints.Test plan
Adds
tests/unit_tests/ssm/test_gated_delta_net.py::TestGatedDeltaNet::test_selective_recompute_norm_out, which builds a no-recompute baseline GDN and one withrecompute_modules=["gdn_norm_out"], runs forward + backward, and asserts the output, all parameter grads and the input grad match bit-for-bit.🤖 Generated with Claude Code