Skip to content

[AMD] Skip full-vocab softmax in EAGLE topk==1 draft on ROCm - #35872

Merged
HaiShaw merged 16 commits into
sgl-project:mainfrom
yichiche:amd/spec-topk1-argmax-rocm
Sep 22, 2026
Merged

HaiShaw merged 16 commits into
sgl-project:mainfrom
yichiche:amd/spec-topk1-argmax-rocm

Conversation

@yichiche

@yichiche yichiche commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

EAGLE topk=1 only needs the largest-logit token. For finite logits, a full-vocabulary softmax cannot change the argmax and is redundant. AITER greedy_sample has an unmasked vector-tail correctness issue; on MI355X it returned an out-of-vocabulary index for vocabulary size 151,666. SGLang’s existing Triton split-argmax masks offsets >= vocab_size and safely handles NaNs.

Changes

  • Use the existing masked Triton split-argmax for ROCm EAGLE topk=1 in both draft-decode and draft-extend.
  • Make position advancement optional so the implementation can be reused in draft-extend.
  • Add AMD coverage for aligned and misaligned vocabularies, NaN, -inf, and all-negative logits.
  • Keep rejection sampling, topk > 1, and all non-ROCm paths unchanged.
  • Apply the optimization generically to supported ROCm EAGLE, EAGLE3, and MTP models without model-name gating.

Correctness

  • test_spec_topk1.py: 6 passed, 12 subtests passed
  • test_eagle_worker_v2_topk1_fastpath.py: 9 passed, 7 subtests passed
  • Triton outputs remained within [0, vocab_size) for vocabulary sizes 151,666 and 248,320.

Performance

All deltas compare Triton against the same baseline, the existing full-softmax selector.

Qwen3.5-397B-A17B-MXFP4

2× MI355X per arm, TP2, rocm/sgl-dev:v0.5.18-rocm724-mi35x-20260825, ISL 8192 / OSL 1024, random-range ratio 0.8, EAGLE 3/1/4, AITER unified attention, FP8 E4M3 KV.

Concurrency Baseline total tok/s Triton total tok/s Δ throughput Baseline TPOT (ms) Triton TPOT (ms) Δ TPOT Δ median E2E
C4 2,557.64 2,630.22 +2.84% 13.433 13.062 −2.76% −2.68%
C8 3,819.53 3,894.64 +1.97% 17.701 17.387 −1.78% −1.15%
C16 5,611.22 5,669.94 +1.05% 24.402 24.197 −0.84% −0.83%
C32 7,517.83 7,600.93 +1.11% 37.026 36.576 −1.22% −0.85%
C64 9,286.48 9,352.09 +0.71% 61.377 60.958 −0.68% −0.60%
C128 19,133.56 19,195.95 +0.33% 59.189 59.320 +0.22% +0.20%

Six-point medians: throughput +1.08%, TPOT −1.03%. Qwen provides measurable end-to-end evidence, with lower median E2E at five of six points.

TP4 Follow-up: C4/C8/C16

Hardware: 4× MI355X, TP4. Image: rocm/sgl-dev:v0.5.18-rocm724-mi35x-20260825.

Qwen3.5-397B-A17B-MXFP4

ISL 8192 / OSL 1024, EAGLE 3/1/4, AITER unified attention, and FP8 E4M3 KV.

Concurrency Baseline total tok/s Candidate total tok/s Δ throughput Baseline TPOT (ms) Candidate TPOT (ms) Δ TPOT Δ median E2E
C4 6,558.78 6,548.00 −0.16% 5.236 5.174 −1.18% −0.26%
C8 10,157.94 10,136.65 −0.21% 6.696 6.517 −2.67% −3.21%
C16 14,586.85 14,779.42 +1.32% 9.392 9.229 −1.74% −1.01%

Three-point medians: throughput −0.16%, TPOT −1.74%, median E2E −1.01%. Throughput is neutral while decode latency improves consistently.

MiniMax-M3 428B MXFP8

ISL 8192 / OSL 1024, EAGLE3 3/1/4, Triton target/draft attention, and FP8 E4M3 KV.

Both arms include compatibility commit 2e3ee8aa8 from draft #35889; only the full-softmax versus current #35872 scratch-wrapper selector differs.

Concurrency Baseline total tok/s Candidate total tok/s Δ throughput Baseline TPOT (ms) Candidate TPOT (ms) Δ TPOT Δ median E2E
C4 2,041.65 2,061.95 +0.99% 15.347 15.002 −2.24% +0.46%
C8 3,425.70 3,444.32 +0.54% 18.399 18.273 −0.69% +0.08%
C16 3,188.35 3,206.67 +0.57% 40.524 40.975 +1.11% +2.11%

Three-point medians: throughput +0.57%, TPOT −0.69%, median E2E +0.46%. Throughput improves at every point; C16 retains a localized latency regression.

MiniMax-M3 428B MXFP8

2× MI355X, TP2, rocm/sgl-dev:v0.5.18-rocm724-mi35x-20260825, ISL 8192 / OSL 1024, random-range ratio 0.8, EAGLE3 3/1/4, Triton target/draft attention, and FP8 E4M3 KV.

Both arms used compatibility commit 2e3ee8aa8 from draft #35889, because current upstream is blocked by #33383. Only the full-softmax versus Triton selector differed.

Concurrency Baseline total tok/s Triton total tok/s Δ throughput Baseline TPOT (ms) Triton TPOT (ms) Δ TPOT Δ median E2E
C4 1,781.30 1,792.81 +0.65% 16.614 16.362 −1.52% −0.84%
C8 2,818.22 2,834.08 +0.56% 22.052 22.057 +0.02% +0.68%
C16 2,943.96 2,894.53 −1.68% 43.781 44.433 +1.49% +1.43%
C32 4,550.05 4,723.46 +3.81% 55.769 53.628 −3.84% −2.77%
C64 6,424.19 6,429.42 +0.08% 77.038 76.664 −0.49% −0.88%
C128 7,103.67 7,120.93 +0.24% 106.726 106.029 −0.65% −0.44%

Six-point medians: throughput +0.40%, TPOT −0.57%, median E2E −0.64%. Overall performance is neutral to slightly positive, although C16 retains a localized regression.

Conclusion

This removes a redundant full-vocabulary softmax from ROCm EAGLE topk=1 while using a vocabulary-masked selector with generic correctness and safety benefits. Qwen shows a measurable improvement, while MiniMax confirms no regression within variance. The optimization applies to supported ROCm EAGLE/MTP models without introducing model-specific behavior.

Checklist

  • Code formatted according to project conventions.
  • AMD correctness tests added and passing.
  • Aligned and misaligned vocabularies validated.
  • NaN, -inf, and all-negative logits covered.
  • Qwen3.5 C4–C128 tested against full softmax.
  • MiniMax-M3 C4–C128 tested against full softmax.
  • Rejection sampling, topk > 1, and non-ROCm behavior unchanged.

CI States

Latest PR Test (Base): ✅ Run #35552861209
Latest PR Test (Extra): ❌ Run #35552861101
Latest PR Test (AMD ROCm 10): ❌ Run #35552861347

@yichiche yichiche added the run-ci CI: run the baseline test suite on this PR label Aug 21, 2026
@yichiche
yichiche force-pushed the amd/spec-topk1-argmax-rocm branch 4 times, most recently from aefd4de to 814df22 Compare August 21, 2026 16:21
@yichiche yichiche added run-ci CI: run the baseline test suite on this PR and removed run-ci CI: run the baseline test suite on this PR labels Aug 21, 2026
@yichiche
yichiche force-pushed the amd/spec-topk1-argmax-rocm branch 2 times, most recently from 1f8c707 to 443fb7f Compare August 24, 2026 07:08
@yichiche
yichiche force-pushed the amd/spec-topk1-argmax-rocm branch from 443fb7f to abfb11a Compare August 25, 2026 03:20
Avoid AITER's unmasked vector tail while keeping ROCm draft selection softmax-free and fusing position and token updates.

Co-authored-by: Cursor <[email protected]>
chuyeh added a commit to chuyeh/sglang that referenced this pull request Aug 28, 2026
Move the independent ROCm top-k1 selector work to sgl-project#35872 so this PR only projects selected draft-extend rows through the LM head.

Co-authored-by: Cursor <[email protected]>
chuyeh and others added 3 commits August 28, 2026 10:21
Share the draft-forward Triton branch across CUDA and HIP while documenting why draft-extend requires optional position advancement and separate platform routing.

Co-authored-by: Cursor <[email protected]>
chuyeh and others added 4 commits September 2, 2026 00:57
Use a draft-extend-only wrapper with discarded scratch positions instead of making the upstream position parameter optional.

Co-authored-by: Cursor <[email protected]>
Resolve the EAGLE worker import conflict while retaining both the new pipeline-parallel helper and the draft-extend top-k1 wrapper.

Co-authored-by: Cursor <[email protected]>
…ax-rocm

Keep both the ROCm top-k1 argmax import and the GLM-5.3 DSA topk-width helper.

Co-authored-by: Cursor <[email protected]>
@chuyeh

chuyeh commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

/rerun-failed-ci

chuyeh and others added 5 commits September 7, 2026 02:56
The test is a CUDA wall-clock check, not a kernel unit test. kernel-unit's fork-worker batch leaves CUDA initialized across forks, so StageProfiler sync flakes and fails required pr-test-finish on unrelated PRs.

Co-authored-by: Cursor <[email protected]>
@1am9trash 1am9trash added the amd label Sep 11, 2026

@1am9trash 1am9trash left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A clean softmax skip on amd side.
Impact on all topk==1 mtp cases.

@HaiShaw
HaiShaw merged commit 790551c into sgl-project:main Sep 22, 2026
288 of 318 checks passed
tanguofu pushed a commit to tanguofu/sglang that referenced this pull request Oct 12, 2026
…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
tanguofu pushed a commit to tanguofu/sglang that referenced this pull request Oct 15, 2026
…ect#43640)

Follow-up to sgl-project#35872, which we already ported. Once the HIP draft path uses the
triton topk-1 kernel, the preallocated parent chain can be materialised directly
by that kernel instead of assembling the draft tokens with a final cat per step.

Two lines: widen the `_is_cuda` gate to `_is_cuda or _is_hip`. Upstream spells the
last condition `needs_draft_probs`; this tree uses
`get_spec().speculative_use_rejection_sampling`, which is the same check under a
different name, so only the platform gate is changed.

Not yet built or rolled out.

Assisted-by: Hy4 preview via CodeBuddy Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd jit-kernel run-ci CI: run the baseline test suite on this PR speculative-decoding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants