Megatron-LM icon indicating copy to clipboard operation
Megatron-LM copied to clipboard

feat(ssm): whole-module 'gdn' selective recompute for GatedDeltaNet

Open wplf opened this issue 5 months ago • 1 comments

Summary

Adds a whole-module gdn entry to recompute_modules (selective granularity) that recomputes the entire GatedDeltaNet module — in_proj, CP all-to-all, conv1d, the gated delta rule, the gated norm, and out_proj — via normal checkpointing. This mirrors how core_attn recomputes the attention core, and trades the GDN activation memory for a backward-pass recompute.

Changes

  • transformer_config: add "gdn" to the recompute_modules choices + allowed set, document it as a normal-checkpointing module, and guard that it requires experimental_attention_variant="gated_delta_net".
  • GatedDeltaNet: extract the forward compute body into _forward_compute and wrap it in tensor_parallel.checkpoint when recompute_gdn is set and the module is training. Non-tensor arguments are bound via a closure (only the input tensor is passed to checkpoint, matching the MLP-recompute pattern, since save_for_backward accepts tensors only).
  • test: test_selective_recompute_gdn parity check — same module/input run with recompute off vs on; forward output and all input/parameter gradients must match within bf16 tolerance.

Test / accuracy

Ran on GB200 (oci-hsg) via the CI-faithful flow (mcore-ci-dev container + run_ci_test.sh + torch.distributed.run):

tests/unit_tests/ssm/test_gated_delta_net.py
=========== 42 passed, 4 skipped, 265 warnings in 854.97s (0:14:14) ============

test_selective_recompute_gdn passes for all parametrized combos (tp∈{1,2}, sp∈{F,T}, cp∈{1,2}): output and gradients are bit-for-bit consistent with the non-recompute path within bf16 tolerance.

Draft pending review.

wplf avatar Jun 11 '26 15:06 wplf

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.

copy-pr-bot[bot] avatar Jun 11 '26 15:06 copy-pr-bot[bot]

/ok to test a010f83

wplf avatar Jun 15 '26 06:06 wplf

/ok to test 2cd9c12

wplf avatar Jun 15 '26 06:06 wplf

/ok to test 1674328

yaox12 avatar Jun 16 '26 03:06 yaox12

/ok to test 5251bfd

wplf avatar Jun 16 '26 03:06 wplf

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/27594703209

svcnvidia-nemo-ci avatar Jun 16 '26 04:06 svcnvidia-nemo-ci

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/27595256854

svcnvidia-nemo-ci avatar Jun 16 '26 04:06 svcnvidia-nemo-ci