Repository navigation
[Perf] runtime: Tune FlashInfer MoE tactics on distinct dummy tokens - #45543
Open
Venkat2811 wants to merge 1 commit into
Open
Venkat2811 wants to merge 1 commit into
Venkat2811 wants to merge 1 commit into
Conversation
The decode-shaped autotune forward ran on zero-filled static buffers, so every row embedded token 0, the MoE router sent all rows to the same experts and FlashInfer ranked its MoE tactics on that pattern. Give the decode dummy forward seeded distinct token ids and zero the buffer after. Kimi-K3 MXFP4 on 8x B300 (TP8 DCP8 EP8, FlashInfer 0.7.2): tactics tuned on realistic routes are 13-16 % faster per MoE layer at 24-32 rows. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-Authored-By: Claude Fable 5.1 <[email protected]>
Venkat2811
requested review from
Fridge003,
Ying1123,
hnyls2002,
ispobock and
merrymercy
as code owners
October 21, 2026 07:34
4 of 5 tasks
detain
pushed a commit
to detain/sglang
that referenced
this pull request
Oct 29, 2026
The decode-shaped autotune forward ran on zero-filled static buffers, so every row embedded token 0, the MoE router sent all rows to the same experts and FlashInfer ranked its MoE tactics on that pattern. Give the decode dummy forward seeded distinct token ids and zero the buffer after. Kimi-K3 MXFP4 on 8x B300 (TP8 DCP8 EP8, FlashInfer 0.7.2): tactics tuned on realistic routes are 13-16 % faster per MoE layer at 24-32 rows. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-Authored-By: Claude Fable 5.1 <[email protected]> (cherry picked from commit 44b7dfd) PR: sgl-project#45543 (open, ported; conflict in test_flashinfer_autotune_sync.py resolved as local union: sgl-project#40420's disjoint-shape tests kept alongside the new dummy-token tests; upstream-only context class TestModelPrefillAutotune (API absent from this stack) not carried in). (cherry picked from commit 677a076a2b318007764744894819b1abe9d91b6c)
detain
added a commit
to detain/sglang
that referenced
this pull request
Oct 29, 2026
sgl-project#44514 from port-autotune (entries 257-260) Batch 2 of the 2026-10-28 second wave. Four picks landed CLEAN in strict order onto the comm docs tip -- code tip 2705ebb: f46e547 sgl-project#40420 (open port, EP autotune-cache digest: per-rank caches no longer dropped every startup; worker RED-proof 2F->2P), 894d4a7 sgl-project#45543 (open port, seeded distinct dummy token ids for the decode MoE autotune; base_runner union preserves the entry-176 EXTEND call site; upstream-only TestModelPrefillAutotune NOT carried in -- autotune_prefill_kernels absent, grep-verified), 6c866f3 sgl-project#43927 (merged pick 33618d4, default tactic joins tuning -- PARTIALLY SATISFIES the C0a sweep-gap record; entry-243/246 'no tactic=-1' PASS-needles STALE, CAVEATS bullet added), 2705ebb sgl-project#44514 (merged pick 1897575, cache-key bump -> exactly ONE cold autotune boot, entry-228 boot-cost practice). Header bookkeeping for BOTH batches: STACK bumped to qwennext-stack-260-2026-10-28 with the comm + autotune wave lines, entries 1-260, tip 2705ebb, updated: 2026-10-28 (entries 255-260) block. FAM-A1 LANDED + NEW TODO S-EXT1 (stack-owned: EXTEND autotune still tunes on zero-filled dummies -- the bug sgl-project#45543 fixed for decode). Verified at landed tips (prod venv, CVD=9), all EXACT vs predictions: sync+gate 22P/1S/5sub, runner dir 89P/1S/47sub, MoE set 139P/22S/141sub, qwen4_exp_ple_staging 37P; comm named set 114P/1S/30sub, dir 120P/1S/35sub 0F, new comm files collect 18. In-flight workers NOT landed -- no drift attributable. NOTHING PUSHED.
detain
added a commit
to detain/sglang
that referenced
this pull request
Oct 29, 2026
…kens (stack-owned, follows sgl-project#45543) Rationale: our entry-176 EXTEND pass (maybe_flashinfer_autotune_extend) allocates fresh ZERO-FILLED dummy buffers via _alloc_dummy_decode_buffers and ran its prefill-sized tuning forward on them -- every row embedded token 0, the MoE router sent all rows to the same experts, and FlashInfer ranked the extend-bucket tactics on a routing pattern no real prefill produces. That is the exact lie sgl-project#45543 fixed for the decode pass (claimed 13-16%/layer MoE gains, measured on different hardware: direction, not measurement), and since sgl-project#44514 these picks persist under the v2_default cache key, so the zero-tuned extend records were being reused boot after boot. Fix: wrap the single extend-pass dummy forward in the SAME seeded autotune_dummy_input_ids helper sgl-project#45543 landed -- reuse, no forked second implementation. One wrap point covers every extend-pass dummy forward: both base_runner call sites (~:295 target, ~:299 draft) route through this function. Buffer lifecycle verified at the site before choosing (S-EXT1's open check): the helper fills ids BEFORE the tuning context and zeroes AFTER it, exactly like the decode wrap; the extend buffers are function- local and released in the finally, which the zeroed re-check preserves. Default-on semantics and the entry-176 size/shape logic are UNCHANGED -- this is a dummy-INPUT fix, not a scope expansion. Skipped (input-dependent, already covered): the MegaMoE prefill profile inside flashinfer_autotune_context profiles topk_ids/topk_weights captured from the DECODE-shaped dummy forward -- distinct since sgl-project#45543 -- and builds its capacity profiles independently of buffers.input_ids; wrapping it too would retune nothing. eager_runner/prefill_cuda_graph_runner EXTEND sites are runtime/capture paths, not autotune, and take real batch tokens. Cache-key finding (checked, not changed): neither the v2_default cache path nor the sgl-project#40420 sync digest hashes anything about dummy tokens, so this patch does NOT cold-boot the cache. Consequence: extend-bucket records tuned on zeros under an existing v2_default key stay VALID and keep hitting. Entry 260's scheduled cold boot has not happened yet (the 2026-10-28 batch is live-only-after-restart), so landing S-EXT1 before the next restart folds the forced retune into that boot at zero extra cost. If any prod boot with a warm cache happens FIRST, a forced-retune needle is required: delete the per-rank rank_tpX_ppY_dpZ.json files -- note SGLANG_FLASHINFER_AUTOTUNE_CACHE=0 does NOT refresh the canonical file (the cache-disabled path writes a timestamped runs/ copy only) -- or add a one-time dummy_tokens=seeded key part mirroring sgl-project#44514's precedent, deliberately left out of this patch's scope. Tests: test_flashinfer_autotune_sync.py gains TestExtendAutotuneDummy- InputIds (4 CPU tests mirroring the sgl-project#45543 class): extend forward sees seeded distinct in-vocab ids and releases buffers zeroed; ids equal the helper's own output (guards against a divergent second implementation); equal across runs (rank determinism); zeroed after a failing forward. Teeth: production hunk reverted -> 3 failed / 1 passed ("1 != 16384"); restored -> 4 passed. Battery at tip vs after, CVD=9 CPU mode: sync+gate 22P/1S/5sub -> 26P/1S/5sub; runner dir 89P/1S/47sub -> 93P/1S/47sub; qwen4_exp_ple_staging 37P -> 37P; MoE set 139P/22S/141sub -> identical. ruff 0.15.1 (F401,F821,F823,UP037) + format clean on both files. (no upstream PR; fork debt S-EXT1)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
(
base_runner.py).and the pick changes from launch to launch.
Modifications
flashinfer_autotune.py:autotune_dummy_input_ids()fills the staticinput_idswith seeded, distinct token idsfor the tuning forward and zeroes them afterwards.
base_runner.py: the decode tuning forward runs inside it.until it is retuned).
Tested configurations
--tp-size 8 --dcp-size 8 --ep-size 8--tp 8flashinfer_mxfp4flashinfer_mxfp4bench_one_batch_server, input 8192, output 512The PR is rebased onto current main; the unit tests pass there.
Results
Kimi-K3, aggregated (decode output tok/s, mean of 2 launches)
gpt-oss-120b, aggregated (decode output tok/s, mean of 2 launches)
Accuracy, Kimi-K3 (sgl-eval gsm8k, model preset, max_tokens 32768)
Tests
Four CPU tests in
test/registered/unit/model_executor/runner/test_flashinfer_autotune_sync.py:1 != 56);pre-commit passes on the changed files.
Reproduce
Checklist
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ❌ Run #39562909397
Latest PR Test (Extra): ❌ Run #39562909380
Latest PR Test (AMD ROCm 10): ❌ Run #39562909370