[dev] Refactor: extract and split common logic between GDN & GDN2 (cherry-pick #5843) - #6088
Conversation
a6f8be7 to
746624c
Compare
35bd2ee to
922aa25
Compare
|
/claude strict-review |
There was a problem hiding this comment.
Strict Review Summary
Findings by severity — CRITICAL: 0, IMPORTANT: 0, SUGGESTION: 1
This PR is a cherry-pick of #5843 that splits the 1453-line megatron/core/ssm/gated_delta_net.py into a package (__init__.py, common.py, gdn.py, gdn2.py), extracting a shared _GDNBase for GDN and the new GDN2 variant.
Verification performed
I diffed the new package against the deleted original (origin/dev) along the correctness-sensitive paths:
- Public import surface preserved.
__init__.pyre-exportsGatedDeltaNet,GatedDeltaNetSubmodules,torch_chunk_gated_delta_rule,_build_head_perm_for_split_sections,_build_thd_cp_a2a_perm,tensor_a2a_cp2hp/hp2cp,_split_tensor_factory, etc. All existing importers (hybrid_layer_specs,experimental_attention_variant_module_specs, modelopt specs, tests) resolve unchanged.get_parameter_local_cp_headwisewas renamed toget_parameter_local_cpbut it is a private helper with no external callers. - Compute paths are behavior-preserving.
torch_chunk_gated_delta_rule, the conv1d/deterministic branch,_prepare_input_for_gated_delta_rule(formerly_prepare_qkv_*+_compute_g_and_beta), the g/beta math (-A_log.exp() * softplus(alpha.float()+dt_bias), fp32), the L2-norm/GQA repeat_interleave, and the CP a2a + zigzag reshuffle all match the original line-for-line. - Checkpoint compatibility.
sharded_state_dictsplits (in_proj.weight→ query/key/value/z/beta/alpha; conv1d → query/key/value) and TP axis maps are identical, and gate parameters (dt_bias,A_log) are still registered afterconv1d, preserving parameter order for existing checkpoints. - Process-group usage. No new direct
parallel_state.get_*_group()reads in library code — groups flow throughpg_collection/ProcessGroupCollection, consistent with the CLAUDE.md guidance. - No unused new identifiers.
feat_dim_split,in_proj_extra_dim,dt_bias_dim,a_log_dimall have real read paths (validated by theattrs_to_checkassert loop and consumed in split/reset logic). GDN2 (GatedDeltaNet2,chunk_gdn2,torch_chunk_gdn2) is not yet wired into any model spec, but it is a deliberately-introduced public API for a follow-up, exported from__init__.py.
Only finding
One stale-docstring nit: _setup_variant_attrs's docstring lists in_proj_dim as an attribute the variant must set, but the base class derives it and variants set in_proj_extra_dim instead.
Risk: Low. Mechanically faithful refactor with preserved public API, checkpoint layout, and numerics; the added test_deterministic_mode/test_module_construction coverage is a plus.
e461276 to
28a2106
Compare
|
/claude strict-review |
|
/ok to test 28a2106 |
Strict Review Summary — PR #6088 (cherry-pick #5843)Findings by severity: CRITICAL: 0 · IMPORTANT: 3 · SUGGESTION: 1 This is a large, mostly-mechanical refactor that splits the monolithic The new surface (the Most impactful
Note
Overall risk: Low–ModerateThe GDN v1 refactor is behavior-preserving and low-risk. The moderate items are all confined to newly-added, currently-inactive code paths (norm recompute is unreachable; GDN2 is unwired). None blocks the refactor's core intent, but the |
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Restore the public tuple return contract for unfused pre-GDR and rebuild kernel inputs in the caller. Drop unrelated MTP construction coverage and update lint-required headers. Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
e678aac to
1aa8afe
Compare
|
/ok to test 1aa8afe |
What does this PR do?
Cherry-pick #5843 and part of #5765 into dev.
Issue tracking
For PRs from open-source community contributors:
Linked issue:
Contribution process
Pre-checks
Code review
Feel free to message or comment @NVIDIA/mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!
All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.
Step 1: Mark PR as "Ready for Review"
.github/CODEOWNERS.Final Review might get declined if these requirements are not fulfilled.
Step 2: Final Review
For PRs that change
megatron/core, once all expert reviewers have approved, theFinal Reviewlabel is applied automatically and final reviewers are assigned.For PRs outside
megatron/core, this step is skipped.Step 3: Approved
Once all required reviewers have approved, the
Approvedlabel is applied automatically.Merge
Any member of mcore-engineers will be able to merge your PR.