Skip to content

[Dev] Enable selective recompute for norm_out in GDN layers - #5443

Open
wplf wants to merge 1 commit into
NVIDIA:devfrom
wplf:jinliangl/gdn-norm-out-recompute
Open

[Dev] Enable selective recompute for norm_out in GDN layers#5443
wplf wants to merge 1 commit into
NVIDIA:devfrom
wplf:jinliangl/gdn-norm-out-recompute

Conversation

@wplf

@wplf wplf commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Port the gdn_norm_out selective recompute (#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:

model.recompute_granularity=selective
model.recompute_modules=[gdn_norm_out]

The block output (norm_out) is discarded in the forward once out_proj consumes 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)

  • 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.
  • The discard-output checkpoint is gated on self.training (matching dev's whole-module gdn recompute convention) so eval/inference runs the block normally.
  • Added a validation guard that gdn and gdn_norm_out cannot be combined: the whole-module gdn recompute (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 with recompute_modules=["gdn_norm_out"], runs forward + backward, and asserts the output, all parameter grads and the input grad match bit-for-bit.

pytest tests/unit_tests/ssm/test_gated_delta_net.py -k test_selective_recompute_norm_out

🤖 Generated with Claude Code

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>
@copy-pr-bot

copy-pr-bot Bot commented Jun 23, 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.

@wplf
wplf marked this pull request as ready for review June 23, 2026 05:58
@wplf
wplf requested review from a team as code owners June 23, 2026 05:58
@wplf

wplf commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test de151f5

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.

2 participants