Skip to content

[Fix] Stop deferring the last layer's FFN all-reduce in five models - #40868

Merged
ch-wan merged 1 commit into
mainfrom
cheng/hot-fix/qwen3-next-last-layer-allreduce
Sep 23, 2026
Merged

ch-wan merged 1 commit into
mainfrom
cheng/hot-fix/qwen3-next-last-layer-allreduce

Conversation

@ch-wan

@ch-wan ch-wan commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

This PR is part of a stack (oldest at bottom):

Motivation

With FlashInfer all-reduce fusion enabled, LayerCommunicator leaves a layer's FFN all-reduce to be fused into the next layer's residual add + RMSNorm, unless the layer is marked as the model's last one (is_last_layer). Five decoder layers were not marked, so their last layer handed its reduction to a layer that does not exist, and the final norm ran on TP-partial sums.

Qwen3-Next is on the list of architectures that auto-enable this fusion (SM90 / SM100, TP > 1, no DP attention), so its default configuration is affected. Outputs stay fluent, which hides the problem; the error only shows up numerically (see Accuracy Tests).

Modifications

  • qwen3_next.py: both decoder layer types pass is_last_layer. The MTP draft model builds a single layer with num_hidden_layers = 1, so it is covered by the same expression.
  • minimax_m3.py: passes is_last_layer.
  • bailing_moe_linear.py: passes is_last_layer=(is_nextn or layer_id == num_hidden_layers - 1), which also covers the hybrid NextN draft layer (built with layer_id=0).
  • bailing_moe.py / bailing_moe_nextn.py and step3p5.py / step3p5_mtp.py: the draft layers are built with layer_id 0 and num_hidden_layers respectively, so the existing layer_id == num_hidden_layers - 1 check marked them as not last. Both decoder layers now take is_nextn, as the DeepSeek, GLM and Dots3 layers already do, and their NextN / MTP models pass it.
  • New test/registered/unit/models/test_last_layer_communicator.py: builds each affected decoder layer class through its real __init__ (submodules stubbed) and checks the is_last_layer handed to LayerCommunicator, for every layer id and for the draft layer. On current main, exactly the 9 affected cases fail (last layer of Qwen3-Next ×2, Bailing-MoE-linear, MiniMax-M3; draft layer of Qwen3-Next ×2, Bailing-MoE-linear, Bailing-MoE, Step-3.5); all 29 pass with this change.

is_last_layer also keeps the last layer from reduce-scattering in input-scattered mode, so that path is corrected for these models as well.

Accuracy Tests

Qwen3-Next-80B-A3B-Instruct-FP8, TP2 on H200, default fusion (auto-enabled). Four greedy prompts, 32 new tokens, top-5 logprobs, requests submitted one at a time. Reference: the same model at TP1. SGLANG_ENABLE_JIT_DEEPGEMM=0 for every arm, because DeepGEMM's FP8 GEMM hits an unrelated CUDA-graph-capture assert in this environment on both main and this branch.

TP2 configuration First token diverging from TP1 (4 prompts) Step-0 max |Δlogp| over top-5 Decode steps with |Δlogp| < 0.05 before divergence
Fusion disabled (--enforce-disable-flashinfer-allreduce-fusion) 32 / 11 / 32 / 32 0.24 / 0.43 / 0.24 / 0.65 94 / 103
Fusion on, main 26 / 5 / 17 / 32 0.42 / 0.93 / 2.20 / 1.19 62 / 76
Fusion on, this PR 32 / 11 / 32 / 32 0.24 / 0.18 / 0.23 / 0.89 94 / 103

Step 0 depends on prefill only. With this change, fusion-on accuracy matches fusion-off. A per-rank decision log shows the last layer now decides not to fuse, which it never did on main.

The other four models are not on the fusion auto-enable list, so their default outputs are unchanged; the fix matters only when fusion is enabled explicitly.

Speed Tests and Profiling

No kernel change. The last layer now completes the all-reduce it used to drop.

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): 🚫 Run #35923940045
Latest PR Test (Extra): 🚫 Run #35923939765
Latest PR Test (AMD ROCm 10): ❌ Run #35923940048

@ch-wan
ch-wan marked this pull request as ready for review September 23, 2026 07:28
@ch-wan
ch-wan force-pushed the cheng/refactor/nemotron-dp-attn-communicator branch from 4e928dd to 199cc84 Compare September 23, 2026 09:32
@ch-wan
ch-wan force-pushed the cheng/hot-fix/qwen3-next-last-layer-allreduce branch from 4f446bf to 713aa75 Compare September 23, 2026 09:32
@ch-wan
ch-wan force-pushed the cheng/refactor/nemotron-dp-attn-communicator branch from 199cc84 to 90c040e Compare September 23, 2026 21:40
Base automatically changed from cheng/refactor/nemotron-dp-attn-communicator to main September 23, 2026 21:40
With FlashInfer all-reduce fusion enabled, LayerCommunicator leaves a layer's
FFN all-reduce to be fused into the next layer's residual add + norm unless
the layer is marked as the model's last one. Five decoder layers did not mark
it, so their final norm ran on TP-partial sums:

- Qwen3-Next (both decoder layer types) and MiniMax-M3 never passed
  is_last_layer. Qwen3-Next is on the auto-enable list for this fusion (SM90 /
  SM100, TP > 1, no DP attention), so the default configuration is affected;
  its MTP draft model is covered by the same change.
- Bailing-MoE-linear never passed it either, including for its hybrid NextN
  draft layer.
- Bailing-MoE's and Step-3.5's draft layers are built with a layer id that is
  not num_hidden_layers - 1 (0 and num_hidden_layers respectively), so the
  existing check marked them as not last. Both decoder layers now take
  is_nextn, as the DeepSeek, GLM and Dots3 ones already do, and their NextN /
  MTP models pass it.
@ch-wan
ch-wan force-pushed the cheng/hot-fix/qwen3-next-last-layer-allreduce branch from 713aa75 to 2b45b0e Compare September 23, 2026 21:40
@ch-wan
ch-wan merged commit e31cbc0 into main Sep 23, 2026
26 of 34 checks passed
@ch-wan
ch-wan deleted the cheng/hot-fix/qwen3-next-last-layer-allreduce branch September 23, 2026 21:41
ch-wan added a commit that referenced this pull request Sep 25, 2026
MiniMax-M3's decoder layers decided by hand whether to leave their FFN
all-reduce to the next layer, passed the decisions to the MLP, and then
wrapped the output or ran postprocess. For sparse layers at TP > 1 they
also forced the all-reduce to run in the layer, to avoid a runaway without
EOS once the sum was deferred. That came from the last layer's deferred
sum reaching the final norm unreduced: the layer was not marked as the
last one, which #40868 fixed, and the layer-stack exit now completes any
sum the last layer leaves.

Use ffn_exit instead, like the other layer-communicator models, and pass
its decisions to the MLP. Sparse layers now leave the sum to the next
layer's input as the dense ones do, wherever the next layer runs the same
all-reduce (fused or not, and under attention DP with the scatter back to
this rank's tokens).
ch-wan added a commit that referenced this pull request Sep 25, 2026
MiniMax-M3's decoder layers decided by hand whether to leave their FFN
all-reduce to the next layer, passed the decisions to the MLP, and then
wrapped the output or ran postprocess. For sparse layers at TP > 1 they
also forced the all-reduce to run in the layer, to avoid a runaway without
EOS once the sum was deferred. That came from the last layer's deferred
sum reaching the final norm unreduced: the layer was not marked as the
last one, which #40868 fixed, and the layer-stack exit now completes any
sum the last layer leaves.

Use ffn_exit instead, like the other layer-communicator models, and pass
its decisions to the MLP. Sparse layers now leave the sum to the next
layer's input as the dense ones do, wherever the next layer runs the same
all-reduce (fused or not, and under attention DP with the scatter back to
this rank's tokens).
kevin-mii pushed a commit to zcnrex/sglang that referenced this pull request Sep 25, 2026
main moved MiniMax-M3 onto LayerCommunicator.ffn_exit (sgl-project#41198) and takes a
layer's last-layer fact from its scatter-mode plan (sgl-project#41199). Resolution in
minimax_m3.py:

- forward: take main's ffn_exit block. It drops the ROCm-only gate this branch
  kept on the sparse-MoE all-reduce deferral: sgl-project#41198 removes the forced in-layer
  all-reduce on every platform, since sgl-project#40868 fixed the no-EOS runaway it guarded.
- LayerCommunicator: drop is_last_layer, keep enable_fused_ar_quant_per_token.

The per-token fused AR + RMSNorm + quant branch in
_reduce_output_and_update_and_read_residual merged cleanly: prepare_attn hands
it the UnreducedOutput's partial tensor, as for the per-group path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant