Repository navigation
Revert "[perf][spec decoding] Skip full-vocab softmax in EAGLE draft when topk == 1 (#26235)" - #26358
Conversation
…when topk == 1 (sgl-project#26235)" This reverts commit a77449f. ## Why After sgl-project#26235 landed (2026-05-25 09:06 UTC), nightly DeepSeek-V3.2 + MTP GSM8K accuracy collapsed to ~0.04 with ~96% invalid output, breaking both the rocm720 nightly and the manual scout run on this same SHA with a known-good aiter pin (so the regression is sglang-side, not aiter). Signature observed (verbatim from logs): metrics={'accuracy': 0.035, 'invalid': 0.96, 'latency': 43.7, 'output_throughput': 2283} AssertionError: 0.035 not greater than 0.94 ## Evidence | Run | sglang | aiter | DSv3.2-MTP gsm8k | |---|---|---|---:| | Last green 2026-05-24 | 7f45bcd (before sgl-project#26235) | 32e1e6d7 (default) | PASS | | nightly 2026-05-25 (rocm720) | b13d3d1 (contains sgl-project#26235) | 32e1e6d7 (default) | 0.035 / invalid=0.96 FAIL | | manual scout 2026-05-25 (this commit + good aiter) | a77449f (= sgl-project#26235) | d7caa3d2 (good baseline) | 0.035 / invalid=0.96 FAIL | The manual scout proves the failure reproduces on a77449f even with the previously-known-good aiter override, so the cause is sglang-side within the 7f45bcd..a77449f window. sgl-project#26235 is the only EAGLE-draft- touching commit in that window, and the failure mode (correct accept- length, invalid text) matches a draft-token-selection bug. References: - nightly job: https://github.com/sgl-project/sglang/actions/runs/26413553204/job/77753010360 - manual scout: https://github.com/sgl-project/sglang/actions/runs/26392698141/job/77803129088 - last green: https://github.com/sgl-project/sglang/actions/runs/26368356160 (2026-05-24) ## Path forward The perf optimization in sgl-project#26235 is valid for non-MTP EAGLE paths. Re-land with an additional guard (e.g. \`topk == 1 AND not is_mtp_path\`) so it skips the MTP path, which appears to depend on the full-vocab softmax that was dropped for downstream draft selection. cc @Qiaolin-Yu (author) — happy to coordinate on the re-land patch.
There was a problem hiding this comment.
Code Review
This pull request simplifies the draft extend and forward logic by removing the special-case handling for self.topk == 1 and instead applying a full-vocab softmax and fast_topk across all cases. The reviewer suggests optimizing the self.topk == 1 case using a mathematical identity to compute the top-1 probability directly, which avoids the memory bandwidth overhead of a full-vocab softmax and fast_topk without sacrificing accuracy.
| probs = torch.softmax(ret.next_token_logits, dim=-1) | ||
| ret.topk_p, ret.topk_index = fast_topk(probs, self.topk, dim=-1) |
There was a problem hiding this comment.
Instead of reverting completely to the full-vocab softmax when self.topk == 1, we can mathematically optimize the top-1 probability computation. By using the identity topk_p and topk_index without materializing the full softmax tensor in HBM. This avoids the accuracy collapse caused by hardcoding topk_p = 1.0 while retaining the performance benefits of skipping the full-vocab softmax.
| probs = torch.softmax(ret.next_token_logits, dim=-1) | |
| ret.topk_p, ret.topk_index = fast_topk(probs, self.topk, dim=-1) | |
| if self.topk == 1: | |
| max_logits, ret.topk_index = torch.max(ret.next_token_logits, dim=-1, keepdim=True) | |
| ret.topk_p = 1.0 / torch.exp(ret.next_token_logits - max_logits).sum(dim=-1, keepdim=True) | |
| else: | |
| probs = torch.softmax(ret.next_token_logits, dim=-1) | |
| ret.topk_p, ret.topk_index = fast_topk(probs, self.topk, dim=-1) |
| probs = torch.softmax(logits_output.next_token_logits, dim=-1) | ||
| topk_p, topk_index = fast_topk(probs, self.topk, dim=-1) |
There was a problem hiding this comment.
We can optimize the top-1 probability computation here as well when self.topk == 1 by using the mathematical identity fast_topk without causing any accuracy degradation.
if self.topk == 1:
max_logits, topk_index = torch.max(logits_output.next_token_logits, dim=-1, keepdim=True)
topk_p = 1.0 / torch.exp(logits_output.next_token_logits - max_logits).sum(dim=-1, keepdim=True)
else:
probs = torch.softmax(logits_output.next_token_logits, dim=-1)
topk_p, topk_index = fast_topk(probs, self.topk, dim=-1)| probs = torch.softmax(draft_logits_output.next_token_logits, dim=-1) | ||
| ret_topk_p, ret_topk_index = fast_topk(probs, self.topk, dim=-1) |
There was a problem hiding this comment.
Apply the same top-1 softmax optimization here to avoid full-vocab softmax and fast_topk overhead when self.topk == 1.
| probs = torch.softmax(draft_logits_output.next_token_logits, dim=-1) | |
| ret_topk_p, ret_topk_index = fast_topk(probs, self.topk, dim=-1) | |
| if self.topk == 1: | |
| max_logits, ret_topk_index = torch.max(draft_logits_output.next_token_logits, dim=-1, keepdim=True) | |
| ret_topk_p = 1.0 / torch.exp(draft_logits_output.next_token_logits - max_logits).sum(dim=-1, keepdim=True) | |
| else: | |
| probs = torch.softmax(draft_logits_output.next_token_logits, dim=-1) | |
| ret_topk_p, ret_topk_index = fast_topk(probs, self.topk, dim=-1) |
|
/tag-and-rerun-ci |
4 new patches enabling prefill CUDA graph (breakable) and deterministic MTP on AMD ROCm for GLM-5.2-FP8 (GlmMoeDsaForCausalLM): 1. patch_dsa_draft_extend.py — Fix 3 assert-is-not-None in draft-extend CUDA graph capture path (extend_prefix_lens_cpu/seq_lens_cpu are None during graph capture). Replace with safe defaults. 2. patch_dsa_indexer_graph.py — Enable HIP support for DSA indexer graph functions (7 sub-patches): is_cuda -> is_cuda or is_hip, FP8 dtype cast fix, aiter tuple extraction, split-op dispatch HIP support. 3. patch_disable_mha_swap.py — Root cause fix: disable incorrect attn_mqa -> attn_mha swap in BCG (breakable CUDA graph) path. In absorbed MLA fused rope path, save_kv_cache=False does NOT mean MHA is active, so the swap gives wrong v_head_dim (256 vs 512). 4. patch_deterministic_argmax.py — Enable deterministic torch.argmax on ROCm for MTP draft selection (topk=1). Original code gated argmax to CUDA only (sgl-project#26358), forcing ROCm to use non-deterministic fast_topk. Fix: cast logits to float32 before argmax for deterministic tie-breaking. Verified on 8x AMD MI355X (gfx950): - HumanEval: 68% (vs 58% baseline, +10%) - GSM8K: 81% (vs 81% baseline, 0% regression) - Decode: +15-20% at 4-8 concurrency from prefill CG - Zero accuracy regression confirmed with MTP disabled (exact match) Includes detailed verification report documenting 10-issue debugging process, root cause analysis, and token-level comparison.
At topk=1 the draft picks the argmax, and softmax cannot move it: it is monotonic. The probability it produces is dead too -- every consumer of topk_p on this path (_select_top_k_tokens_first, _select_top_k_tokens_later) either ignores it or folds it into scores that the topk1 chain's early return discards, and the chain always fits because the parents buffer is sized to max(decode_max_bs, max_running_requests). What it costs is a pass over 154880 logits per draft step. From a kernel trace of one step at CONC 1: cunn_SoftMaxForwardGmem 5 x 49.79 us = 0.249 ms at::native::reduce_kernel 6 x 18.55 us = 0.111 ms ROCm was excluded because torch.argmax breaks ties inconsistently there and corrupts the draft chain on fp8 logits (sgl-project#26358). That is an argmax property, not a reason to keep the softmax: * The draft loop now takes draft_topk1_postprocess, a Triton split reduction that always keeps the lowest index. It never calls torch.argmax. * draft_extend ranks the raw logits instead. It cannot use the same helper because that also advances positions, which is wrong there. Ranking logits directly also has fewer ties to break than ranking their softmax, whose fp32 rounding can map two distinct logits onto one probability. NOT MEASURED END TO END YET. The trace above says what the removed kernels cost; whether the step drops by that much is still being swept.
At topk=1 the draft picks the argmax, and softmax cannot move it: it is monotonic. The probability it produces is dead too -- every consumer of topk_p on this path (_select_top_k_tokens_first, _select_top_k_tokens_later) either ignores it or folds it into scores that the topk1 chain's early return discards, and the chain always fits because the parents buffer is sized to max(decode_max_bs, max_running_requests). What it costs is a pass over 154880 logits per draft step. From a kernel trace of one step at CONC 1: cunn_SoftMaxForwardGmem 5 x 49.79 us = 0.249 ms at::native::reduce_kernel 6 x 18.55 us = 0.111 ms ROCm was excluded because torch.argmax breaks ties inconsistently there and corrupts the draft chain on fp8 logits (sgl-project#26358). That is an argmax property, not a reason to keep the softmax: * The draft loop now takes draft_topk1_postprocess, a Triton split reduction that always keeps the lowest index. It never calls torch.argmax. * draft_extend ranks the raw logits instead. It cannot use the same helper because that also advances positions, which is wrong there. Ranking logits directly also has fewer ties to break than ranking their softmax, whose fp32 rounding can map two distinct logits onto one probability. NOT MEASURED END TO END YET. The trace above says what the removed kernels cost; whether the step drops by that much is still being swept.
…fusion Two upstream fixes that our decode path provably hits: 1. sgl-project#35872 (790551c) - skip the full-vocab softmax in the EAGLE topk==1 draft on ROCm. Live decode runs speculative_algorithm=EAGLE with eagle_topk=1 and steps=2 on EAGLEWorkerV2, so every draft step went through renorm_draft_probs + fast_topk over the whole vocabulary. The decode profile measures that softmax at 3.4% and the argmax reduce at 2.9% of decode kernel time. ROCm previously fell through to the generic topk path because of sgl-project#26358 (torch.argmax tie-break on FP8 logits). This uses the triton draft_topk1_postprocess kernel instead of torch.argmax, so the tie-break concern does not apply. A scratch positions buffer absorbs the position advance that draft-extend has already consumed. 2. sgl-project#41258 (db32673) - let the GLM DSA NextN draft declare its own shared-expert fusion architecture. ModelConfig rewrites a GLM draft's architecture to GlmMoeDsaForCausalLMNextN, so the inherited DeepSeek name never matched the gate and the draft's shared expert was never fused into fMoE, costing an extra GEMM per draft step. Measured at 1.1% of decode kernel time (_fused_append_shared_experts_kernel). Only the architecture declaration is ported. The upstream commit's second hunk depends on should_apply_glm_nextn_moe_ptpc, which this tree does not have. Deliberately not included: sgl-project#42982 (FP8 KV saturation). It has no throughput benefit, it changes the values written into the KV cache, and therefore forces the whole rollout into the "changes KV encoding" risk class. It should ship on its own with its own correctness run. Assisted-by: Hy4 preview via CodeBuddy Code
Motivation
Reverts #26235 (commit a77449f, merged 2026-05-25 09:06 UTC) because it caused DeepSeek-V3.2 + MTP GSM8K accuracy to collapse to ~0.04 with ~96% invalid output on the very next nightly run.
Verification on the revert branch — CONFIRMED FIX on ROCm 7.2
Re-ran
nightly-accuracy-8-gpu-mi35x-deepseek-v32-mtp-rocm720against this PR's revert branch (run 26438872740):This is a clean 3.5 pp above threshold — a full recovery of MTP GSM8K accuracy on ROCm 7.2 mi35x. Compare to the failing pre-revert score: 0.035 / invalid=0.96 on the same hardware and same Dockerfile-default aiter (
32e1e6d7).Evidence (verified verbatim from logs)
Failure signature on the rocm720 nightly:
Cross-run comparison:
7f45bcdd2a(before #26235)32e1e6d7(default)b13d3d18c(contains #26235)32e1e6d7(default)a77449f86(= #26235)d7caa3d2(good baseline)9a7258680(this PR HEAD)32e1e6d7(default)The combination of (a) the manual scout reproducing R108 on
a77449f86with known-good aiter and (b) the revert-branch verify scoring 0.975 on rocm720 with default aiter proves the cause is on the sglang side, specifically #26235.References
Modifications
This is a clean
git revertofa77449f86.Files reverted:
python/sglang/srt/speculative/eagle_draft_extend_cuda_graph_runner.py(+10/-2 → 0)python/sglang/srt/speculative/eagle_worker_v2.py(+22/-4 → 0)Path forward
The perf optimization in #26235 is valid for the non-MTP EAGLE path. Suggest re-landing with an additional guard such as
topk == 1 AND not is_mtp_path(or equivalent) so it skips the MTP path, which appears to depend on the full-vocab softmax for downstream draft selection.cc @Qiaolin-Yu (author of #26235) — happy to coordinate on the re-land patch once a guard is identified.
Checklist
CI States
Latest PR Test (Base): ⏳ Run #26443970447
Latest PR Test (Extra): ❌ Run #26443970366