Skip to content

[AMD] Use the preallocated EAGLE topk=1 draft chain on HIP - #43640

Merged
BBuf merged 4 commits into
sgl-project:mainfrom
xiaofei-zheng:feature/xiaofei/eagle-topk1-chain-hip
Oct 14, 2026
Merged

BBuf merged 4 commits into
sgl-project:mainfrom
xiaofei-zheng:feature/xiaofei/eagle-topk1-chain-hip

Conversation

@xiaofei-zheng

@xiaofei-zheng xiaofei-zheng commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

EagleDraftWorker.draft_forward writes the topk=1 draft chain straight into the preallocated parents/indices buffers only when _is_cuda. HIP already runs the Triton draft_topk1_postprocess kernel that fills those columns (#35872), but the gate still sends it through the token-list path: the eager _select_top_k_tokens_first (with repeat_interleave) on step 0, the compiled _select_top_k_tokens_later on each later step, and a final cat.

Modifications

  • Take the preallocated chain on _is_cuda or _is_hip. The other conditions (topk 1, batch fits the buffers, no hot_token_id, no draft probs) are unchanged, so EAGLE3 token maps and non-greedy batches under rejection sampling keep the token-list path.

Accuracy Tests

Bit-exact: the same Triton argmax runs per step and the chain buffers hold what the cat path builds. On MI355X, test_eagle_worker_v2_topk1_fastpath.py passes 11 tests and 7 subtests, and test_spec_topk1.py passes 6 tests and 12 subtests. A draft-forward probe at GLM-5.3 shapes (vocab 154880, hidden 6144, 5 steps) gives torch.equal outputs at bs 1-64.

Speed Tests and Profiling

Same probe with the draft model stubbed out, so only the draft glue is measured. Kernels per draft cycle drop from 27 to 9 at every batch size. HIP-graph replay per cycle (min of 5 x 200 replays):

bs main (us) this PR (us)
1 53.4 24.5
4 58.2 23.5
8 57.8 26.0
32 72.5 36.9
64 86.5 47.7

That is about 0.25-0.3% of a GLM-5.3 TP4 decode cycle (~12 ms), too small to resolve end to end.

Checklist

  • Format code with pre-commit.
  • Provide accuracy and speed results.

CI States

Latest PR Test (Base): ⏳ Run #38503216059
Latest PR Test (Extra): ❌ Run #38503216047
Latest PR Test (AMD ROCm 10): ⏳ Run #38503216074

@xiaofei-zheng

Copy link
Copy Markdown
Contributor Author

@hnyls2002 @Qiaolin-Yu @merrymercy could you add run-ci and review this? It is a one-line gate change that lets HIP take the preallocated EAGLE topk=1 chain, which the Triton kernel already supports. Outputs are bit-exact, and the draft glue drops from 27 to 9 kernels per cycle. Thanks!

self.assertTrue(fast_parent.is_contiguous())
self.assertTrue(fast_index.is_contiguous())

@unittest.skipUnless(

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.

The pr's change is small and safe, we don't need to add this test. Can you delete it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for removing it in 5021a17. The PR is now just the gate change, and I updated the description to match. That push needs one more approval under the repo rules. Could you re-approve and merge once CI is green? Thanks!

@BBuf BBuf added the run-ci CI: run the baseline test suite on this PR label Oct 13, 2026
@BBuf
BBuf merged commit 7e226b1 into sgl-project:main Oct 14, 2026
96 of 118 checks passed
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
tanguofu pushed a commit to tanguofu/sglang that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants