[dev] feat(moe): Support packed sequence for gated delta net (GDN) - #2644
Conversation
2575c6d to
4f8888d
Compare
4f8888d to
9ccf5a4
Compare
73d512d to
ae8806c
Compare
|
/ok to test ae8806c |
83a8607 to
545a2a5
Compare
|
/ok to test 545a2a5 |
545a2a5 to
befbcd2
Compare
|
Also need to update this line https://github.com/yuzhongw-nvidia/Megatron-LM/blob/befbcd2a10b60deb4edbd0f758275b26a6df83c7/megatron/core/ssm/gated_delta_net.py#L741 to |
Thanks. Resolved. |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/24067151491 |
Hi @Zhikaiiii @Code4Graph , We have already merged this PR, but there are still some numerical issues for fused attention + Qwen3-Next / Qwen3.5 + THD format. Before the fix, we recommend you to use flash attention ( |
Thanks for the great work! Just one more question: It seems that this feature has been merged into the |
No. We will move forward with the review process for the main PR, but we do not have an ETA for now. |
Thanks for the great work! |
### What does this PR do? Support CP for bshd format, since mcore is still not support thd format for GDN NVIDIA/Megatron-LM#2644 ```bash pip install transformers==5.3.0 pip install flash-linear-attention # bshd relies on mcore dev branch pip install --no-deps git+https://github.com/NVIDIA/Megatron-LM.git@dev pip install --force-reinstall git+https://github.com/ISEEKYAN/mbridge.git ``` - model: Qwen3.5-0.8B - dataset: gsm8k - red: TP=2,CP=1; gray: TP=2,CP=2 <img width="320" height="280" alt="image" src="https://github.com/user-attachments/assets/63621abd-bdd7-4fae-8746-40573931b232" />
…VIDIA#2644) Signed-off-by: yuzhongw <yuzhongw@nvidia.com> Co-authored-by: kunlunl <kunlunl@nvidia.com>
…VIDIA#2644) Signed-off-by: yuzhongw <yuzhongw@nvidia.com> Co-authored-by: kunlunl <kunlunl@nvidia.com>
…VIDIA#2644) Signed-off-by: yuzhongw <yuzhongw@nvidia.com> Co-authored-by: kunlunl <kunlunl@nvidia.com>
### What does this PR do? Support CP for bshd format, since mcore is still not support thd format for GDN NVIDIA/Megatron-LM#2644 ```bash pip install transformers==5.3.0 pip install flash-linear-attention # bshd relies on mcore dev branch pip install --no-deps git+https://github.com/NVIDIA/Megatron-LM.git@dev pip install --force-reinstall git+https://github.com/ISEEKYAN/mbridge.git ``` - model: Qwen3.5-0.8B - dataset: gsm8k - red: TP=2,CP=1; gray: TP=2,CP=2 <img width="320" height="280" alt="image" src="https://github.com/user-attachments/assets/63621abd-bdd7-4fae-8746-40573931b232" />
…VIDIA#2644) Signed-off-by: yuzhongw <yuzhongw@nvidia.com> Co-authored-by: kunlunl <kunlunl@nvidia.com>
…VIDIA#2644) Signed-off-by: yuzhongw <yuzhongw@nvidia.com> Co-authored-by: kunlunl <kunlunl@nvidia.com>
### What does this PR do? Support CP for bshd format, since mcore is still not support thd format for GDN NVIDIA/Megatron-LM#2644 ```bash pip install transformers==5.3.0 pip install flash-linear-attention # bshd relies on mcore dev branch pip install --no-deps git+https://github.com/NVIDIA/Megatron-LM.git@dev pip install --force-reinstall git+https://github.com/ISEEKYAN/mbridge.git ``` - model: Qwen3.5-0.8B - dataset: gsm8k - red: TP=2,CP=1; gray: TP=2,CP=2 <img width="320" height="280" alt="image" src="https://github.com/user-attachments/assets/63621abd-bdd7-4fae-8746-40573931b232" />
### What does this PR do? Support CP for bshd format, since mcore is still not support thd format for GDN NVIDIA/Megatron-LM#2644 ```bash pip install transformers==5.3.0 pip install flash-linear-attention # bshd relies on mcore dev branch pip install --no-deps git+https://github.com/NVIDIA/Megatron-LM.git@dev pip install --force-reinstall git+https://github.com/ISEEKYAN/mbridge.git ``` - model: Qwen3.5-0.8B - dataset: gsm8k - red: TP=2,CP=1; gray: TP=2,CP=2 <img width="320" height="280" alt="image" src="https://github.com/user-attachments/assets/63621abd-bdd7-4fae-8746-40573931b232" />
### What does this PR do? Support CP for bshd format, since mcore is still not support thd format for GDN NVIDIA/Megatron-LM#2644 ```bash pip install transformers==5.3.0 pip install flash-linear-attention # bshd relies on mcore dev branch pip install --no-deps git+https://github.com/NVIDIA/Megatron-LM.git@dev pip install --force-reinstall git+https://github.com/ISEEKYAN/mbridge.git ``` - model: Qwen3.5-0.8B - dataset: gsm8k - red: TP=2,CP=1; gray: TP=2,CP=2 <img width="320" height="280" alt="image" src="https://github.com/user-attachments/assets/63621abd-bdd7-4fae-8746-40573931b232" />
…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>
What does this PR do ?
Support packed sequence for gated delta net (GDN).
Requires cudnn>=9.19.0 for Qwen3.5 or Qwen3-Next-80B-A3B THD format training on Hopper. cudnn<=9.18.0 have some numerical issues, leading to grad NaN.
PR for main: #2645
Contribution process
flowchart LR A[Pre-checks] --> B[PR Tests] subgraph Code Review/Approval C1[Expert Review] --> C2[Final Review] end B --> C1 C2 --> D[Merge]Pre-checks
Core 0.8)Code review
The following process is enforced via the CODEOWNERS file for changes into
megatron/core. For changes outside ofmegatron/core, it is up to the PR author whether or not to tag the Final Reviewer team.For MRs into `main` branch
(Step 1): Add PR label
Expert Review(Step 2): Collect the expert reviewers reviews
Expert Reviewlabel when your PR is ready for review.Final Review might get declined if these requirements are not fulfilled.
(Step 3): Final Review
Final Reviewlabel(Optional Step 4): Cherry-pick into release branch
If this PR also needs to be merged into
core_r*release branches, after this PR has been merged, selectCherry-pickto open a new PR into the release branch.For MRs into `dev` branch
The proposed review process for `dev` branch is under active discussion.MRs are mergable after one approval by either
eharper@nvidia.comorzijiey@nvidia.com.Merging your PR
Any member of core-adlr and
core-nemowill be able to merge your PR.