Repository navigation
[Bugfix] FlashInfer autotune cache dropped every startup under expert parallelism - #40420
zhang-keliang wants to merge 1 commit into
Conversation
… the load decision _autotune_cache_digest hashed each rank's whole cache file to decide whether the caches agree. Under expert parallelism each rank tunes a disjoint subset of MoE shapes, so the digests never matched and the cache was unlinked every boot; tactics were re-drawn from timing noise on every start. load_configs is all-or-nothing on _metadata, so the consistency requirement is that every rank would make the same load decision under the current environment -- not that their tactic entries agree. Digest the (loadable, stamp, env) triple instead. Signed-off-by: summer <[email protected]>
…/deferred/avoid map - 3A [24-35]: NVFP4 MoE boot sgl-project#39807/sgl-project#40173, block-FP8 TP refine sgl-project#42566, k-pool indexer split sgl-project#43619, SM120 skinny GEMM sgl-project#42865/sgl-project#42867, DeepGEMM warmup guards sgl-project#32686/sgl-project#43712, autotune sgl-project#43363/sgl-project#40420, mHC overlap sgl-project#42985, FP8-einsum precompile sgl-project#42821. - 3B [36-43]: PCIe CustomAllreduce VMM sgl-project#44448, EP local expert ids sgl-project#44480, shm TP broadcast sgl-project#44202, PCIe-IPC all-gather sgl-project#42863 + multicast guard sgl-project#41888, TP-sampling consistency sgl-project#41916/sgl-project#38565, draft embed/lm_head VRAM sgl-project#37155. - sgl-project#39807 toolchain commit verified safe against our CUDA_HOME=12.9 pin (cu13 fallback needs CUDA_HOME unset AND glibc>=2.41; we are 2.39). - stack_want.txt: execution-status banner. Branch tip 5dd6ec7.
… the load decision _autotune_cache_digest hashed each rank's whole cache file to decide whether the caches agree. Under expert parallelism each rank tunes a disjoint subset of MoE shapes, so the digests never matched and the cache was unlinked every boot; tactics were re-drawn from timing noise on every start. load_configs is all-or-nothing on _metadata, so the consistency requirement is that every rank would make the same load decision under the current environment -- not that their tactic entries agree. Digest the (loadable, stamp, env) triple instead. Signed-off-by: summer <[email protected]> (cherry picked from commit 10c6feb) PR: sgl-project#40420 (open, ported) (cherry picked from commit 763e886d45cb4b605597479e4d9d554c26d673ce)
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)
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.
…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)
|
I tested this on 2x RTX PRO 6000 Blackwell (sm_120), main at
One note on the docstring: at TP2/EP2 the ranks tuned the same shapes, and the files differed only by the rank fields in the key (with those taken out, the two files were identical). So "each rank tunes a disjoint subset of MoE shapes" does not match what I saw on this runner; the rank fields in the key are why the files differ. Full table and the open GB10 question: #40320 (comment) |
|
Thanks for the fix and the clear root-cause write-up. I measured this on current main (FlashInfer Why that is safe. Since FlashInfer 0.7.3, SGLang sets the TP CPU group via Experiment. B100,
Without the gate, rank-local entries, as in the GB10 TP4/EP2 report that opened #40320, should also Would you like to update this PR to remove the gate and the digest? The digest and drop-gate tests |
|
Hi @zhang-keliang, following up on my comment above: are you still planning to work on this PR? If you're busy, I'm happy to take it over. I'd open a follow-up PR that deletes Either way works. If I don't hear back in a week or so, I'll go ahead with the follow-up PR so the cache stops being discarded on EP startups. |
|
@zhang-keliang I've opened #54439, which deletes the gate and the digest as described above, and credits you as co-author. Thanks again for finding the root cause. If you'd rather land it here instead, let me know and I'll close mine. |
Motivation
Fixes #40320.
_autotune_cache_digesthashes each rank's whole cache file to decide whether the ranks agree. Under expert parallelism each rank tunes a disjoint subset of MoE shapes, so the per-rank tactics legitimately differ —len(set(digests)) == 1cannot hold, and the cache is unlinked on every boot. Tactics are then re-drawn from timing noise on each start, so the same configuration gives different throughput across boots.Modifications
load_configsin flashinfer is all-or-nothing: it accepts a per-rank cache file only when its_metadatamatches the current environment, otherwise it skips the whole file. The cross-rank agreement the entry gate needs is that every rank makes the same load decision under the current environment — not that tactic entries agree. Digest the(loadable, stamp, env)triple instead of the file bytes. +7/-3 inflashinfer_autotune.py.Two regression tests, both fail before / pass after:
TestAutotuneCacheDigest::test_disjoint_shape_sets_digest_alike_when_env_matches— unit-level: two rank caches with the same_metadatabut disjoint per-shape entries must digest alike.TestDropDivergedAutotuneCache::test_disjoint_shape_sets_with_matching_env_are_kept— integration over a real gloo group and real files: both ranks' caches must survive the gate.Two tests were removed:
test_diverged_caches_are_dropped_on_every_rankenforced the byte-equality contract this fix disproves.test_key_order_does_not_matterdegrades to a mirror under the new digest and is subsumed by the new disjoint-content test above.The two negative-branch tests remain:
test_matching_caches_are_kept(positive) andtest_caches_diverging_only_in_metadata_are_dropped(the real desync we still want to catch).Accuracy Tests
Not applicable — this changes the cache-entry gate, not the tuning path itself. Full
test_flashinfer_autotune_sync.py: 11 pass, 1 CUDA-only skip.Speed Tests and Profiling
Not applicable directly. The intended effect is that under EP the tuned tactics are reused across boots instead of being re-drawn from timing noise; on the reporter's 4x GB10 DGX Spark setup the whole cache was being deleted on every start.
Checklist
CI States
Latest PR Test (Base): ❌ Run #35494840938
Latest PR Test (Extra): ❌ Run #35494840832
Latest PR Test (AMD ROCm 10): ❌ Run #35494841106