[dev] fix(ssm): handle alignment padding in GDN packed seq + CP - #4230
Merged
Conversation
yxs
force-pushed
the
fix/gdn-packed-cp-alignment
branch
from
April 9, 2026 11:31
45d1a49 to
7e32649
Compare
Contributor
Author
xiaoyao0115
reviewed
Apr 10, 2026
Contributor
|
/claude review |
Contributor
|
/ok to test 8a5cbc3 |
yuzhongw-nvidia
approved these changes
Apr 10, 2026
yuzhongw-nvidia
enabled auto-merge
April 10, 2026 11:15
Contributor
Author
|
@yuzhongw-nvidia is this PR ready to merge? |
When cu_seqlens_q_padded is not provided and alignment padding exists, GDN's packed all-to-all loses padding tokens, causing shape mismatch at the residual connection. Fix: - Extract cu_seqlens resolution into _resolve_cu_seqlens() method - Single-sequence case: auto-extend cu_seqlens to cover trailing padding - Multi-sequence case: raise clear error requesting cu_seqlens_padded - Add unit tests for cu_seqlens validation logic Validated on 2x H100 (CP=2): - Single seq with padding + no cu_seqlens_padded: output shape correct - Multi seq with padding + no cu_seqlens_padded: ValueError raised - With cu_seqlens_padded set: standard path works - No padding case: passes through unchanged Fixes: NVIDIA#4194 Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
yuzhongw-nvidia
force-pushed
the
fix/gdn-packed-cp-alignment
branch
from
April 13, 2026 00:52
8a5cbc3 to
a5b5110
Compare
Contributor
|
/ok to test a5b5110 |
Victarry
approved these changes
Apr 13, 2026
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/24326368290 |
Contributor
Merged. Many thanks for your contribution! |
Member
|
/claude copy |
svcnvidia-nemo-ci
added a commit
that referenced
this pull request
Apr 14, 2026
Contributor
|
🤖 This PR has been cherry-picked to main in #4289. |
yuzhongw-nvidia
added a commit
to yuzhongw-nvidia/Megatron-LM
that referenced
this pull request
Apr 14, 2026
…IA#4230) Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Yuzhong Wang <yuzhongw@nvidia.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
6 tasks
yuzhongw-nvidia
added a commit
to yuzhongw-nvidia/Megatron-LM
that referenced
this pull request
Apr 15, 2026
…IA#4230) Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Yuzhong Wang <yuzhongw@nvidia.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
yuzhongw-nvidia
added a commit
to yuzhongw-nvidia/Megatron-LM
that referenced
this pull request
Apr 15, 2026
…IA#4230) Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Yuzhong Wang <yuzhongw@nvidia.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
yuzhongw-nvidia
added a commit
that referenced
this pull request
Apr 16, 2026
Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Yuzhong Wang <yuzhongw@nvidia.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
yuzhongw-nvidia
added a commit
to yuzhongw-nvidia/Megatron-LM
that referenced
this pull request
Apr 28, 2026
…IA#4230) Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Yuzhong Wang <yuzhongw@nvidia.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
yuzhongw-nvidia
added a commit
to yuzhongw-nvidia/Megatron-LM
that referenced
this pull request
Apr 29, 2026
…IA#4230) Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Yuzhong Wang <yuzhongw@nvidia.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
6 tasks
dreamyang-liu
added a commit
to dreamyang-liu/Megatron-LM
that referenced
this pull request
Jun 26, 2026
…DeltaNet Port the packed-sequence support from upstream NVIDIA/Megatron-LM PRs NVIDIA#2644 and NVIDIA#4230 into the GatedDeltaNet forward (adapted to this fork's GDN code): - Gate packed handling on `packed_seq_params.qkv_format == 'thd'` (not just `is not None`), so the sbhd PackedSeqParams Megatron passes uniformly is ignored and only genuine THD packing is processed. - Resolve cu_seqlens via `_resolve_cu_seqlens`, preferring *_padded and validating cu_seqlens[-1] == total_seq_len (alignment-padding handling). - Unpack the packed stream per-sequence around both CP all-to-all calls (cp2hp / hp2cp) via `_unpack_sequence`, and pass cu_seqlens into the causal_conv1d and gated_delta_rule kernels. - Guard torch_chunk_gated_delta_rule against cu_seqlens (unsupported). - Assert batch == 1 and non-deterministic mode for packed sequences. Also keep the independent fp32 numerics fix: cast A_log and dt_bias to fp32 before exp/softplus when computing g, matching the "In fp32" intent. Verified the cu_seqlens[-1] == seq_len invariant holds for the target training config (TP=4, sequence-parallel, CP=1, THD): seq_len = (L/tp)*sp*cp = L and cu_seqlens[-1] = L*cp = L. Note CP>1 + GDN is a known unsupported edge that would trip the validation. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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 does this PR do ?
Fix shape mismatch in GDN packed sequence + CP > 1 when alignment padding is present.
Summary
When
cu_seqlens_q_paddedis not provided, GDN falls back tocu_seqlens_q(actual token boundaries) for the per-sequence all-to-all unpack. Alignment padding tokens are lost, making the output shorter thanhidden_states, crashing at the residual connection.Fix: Extract cu_seqlens resolution into
_resolve_cu_seqlens():cu_seqlens_paddedavailable → use it (unchanged behavior)ValueErrorrequestingcu_seqlens_paddedTest results
Unit tests: 5/5 passed
(2× H100, CP=2):
cu_seqlens_padded→ auto-extend, output shape correctcu_seqlens_padded→ValueErrorraised correctlycu_seqlens_paddedset → standard path worksFixes #4194
PR for main: #2645