Skip to content

[Perf] deepseek_v4: run FlashInfer autotune for block-FP8 models served as MXFP8 - #44842

Merged
kpham-sgl merged 1 commit into
sgl-project:mainfrom
kpham-sgl:kpham/dsv41-mxfp8-gemm-autotune
Oct 17, 2026
Merged

kpham-sgl merged 1 commit into
sgl-project:mainfrom
kpham-sgl:kpham/dsv41-mxfp8-gemm-autotune

Conversation

@kpham-sgl

@kpham-sgl kpham-sgl commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Torch-profiler trace of DeepSeek-V4.1-Flash DEP2 prefill on GB300 (MegaAttention, MegaMoE, DSpark, 16K-token prefill budget per rank), one 16K-token cold chunk per rank, rank 0:

Dense MXFP8 GEMM (flashinfer_mm_mxfp8 → CuTe-DSL dense_blockscaled_gemm_sm100)
Launches per step 210 (130 after #44837 removes the shared-expert MLP)
Per launch 221 µs
Total per step 46.5 ms of a 322 ms step
Shapes at M=16,384 fused wqkv_a N=1792 K=5120; wq_b N=32768 K=1280; wo_b N=5120 K=8192

Every one of these launches runs on FlashInfer's untuned fallback tactic: the server log has no autotune pass at all, and Fp8LinearMethod.apply keeps pin_tactic=True for block-FP8-as-MXFP8 layers until the prefill autotune hook sets mxfp8_prefill_autotune_min_tokens, which never happens.

Why

should_run_flashinfer_autotune treats FP8 dense GEMMs as tunable only for quantization == "mxfp8" (and modelopt per-tensor FP8). DeepSeek-V4.1 checkpoints are block-FP8 [32, 32] with ue8m0 scales, which Fp8LinearMethod serves through the MXFP8 view on FlashInfer CuTe-DSL, the same tunable mm_mxfp8 op. The model already has autotune_prefill_kernels / wants_prefill_autotune (from #38798) to tune exactly those GEMMs at the prefill token ceiling, but it is only reached from the gated autotune pass, so it never ran.

Modifications

  • should_run_flashinfer_autotune: also return True when a resident FP8 linear serves block-FP8 as MXFP8 on a FlashInfer CuTe-DSL/CUTLASS backend (_model_serves_block_fp8_as_mxfp8_on_flashinfer). The existing decode-shaped pass and the DeepSeek-V4.1 prefill hook then run and persist tactics under SGLANG_CACHE_DIR/flashinfer/autotune/... exactly as for mxfp8 models, so restarts stay fast.
  • Drops the stale "SGLang temporarily skips mxfp8_gemm by default due to an IMA" help text on --flashinfer-autotune-skip-ops; FLASHINFER_AUTOTUNE_WORKAROUND_SKIPS has been empty since enable TRT-LLM for MiniMax M3 by preserving SwiGLU params #33962.
  • Numerics: tuned tactics change only the GEMM tile/cluster schedule. Batch-invariant and deterministic modes keep the pinned tactic as before (pin_tactic override in Fp8LinearMethod.apply is unchanged).

Measured

GB300, DEP2 (TP2 + DP attention, EP2), DeepSeek-V4.1-Flash, MegaMoE, Mega-mHC, decoder bounded replay, eager prefill, 16K-token prefill budget per rank, rank 0. Main (job 3470, 2d3dd3168d) against this branch (job 3471). Startup log on the branch, both ranks: Running FlashInfer autotune with cache: .../flashinfer/autotune/0.7.1/sm103/.../rank_tp0_pp0_dp0.json.

Unprofiled, median of 3 main this PR
One 16K-token cold chunk per rank (ms) 247 235
128K-token prompt in eight 16K chunks (ms) 1,906 1,773
8 x 2K fresh tokens on 90K cached tokens per rank (ms) 672 669
Profiled 16K step main this PR
Dense MXFP8 GEMM launches per step 212 212
Dense MXFP8 GEMM time per step (ms) 46.5 29.9
Mean per launch (µs) 220 141
Layer 6, fused wqkv_a / wq_b / wo_b GEMM (µs) 160 / 563 / 721 88 / 449 / 369
Attention section, layer 6 (ms) 5.00 4.48

The step is dispatch-bound, so most of the 16.6 ms of removed GEMM time hides behind launch gaps on a single chunk; it shows fully on the 128K prompt.

Before: main, layer 6, 5.00 ms between the two mHC kernels.

main, layer 6 attention section

After: this branch, same layer, 4.48 ms; the three dense GEMMs are the shorter purple slices.

this PR, layer 6 attention section

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ❌ Run #39011298394
Latest PR Test (Extra): ❌ Run #39011298229
Latest PR Test (AMD ROCm 10): ❌ Run #39011298257

@kpham-sgl
kpham-sgl force-pushed the kpham/dsv41-mxfp8-gemm-autotune branch from e60e94e to bf8fec1 Compare October 17, 2026 03:00
@kpham-sgl
kpham-sgl marked this pull request as ready for review October 17, 2026 03:01
@github-actions

This comment has been minimized.

@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test registered/unit/model_executor/runner/test_flashinfer_autotune_sync.py registered/unit/server_args/test_server_args.py

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/model_executor/runner/test_flashinfer_autotune_sync.py

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/server_args/test_server_args.py

@kpham-sgl kpham-sgl changed the title [DeepSeek-V4.1] Run FlashInfer autotune for block-FP8 models served as MXFP8 [Perf] deepseek_v4: run FlashInfer autotune for block-FP8 models served as MXFP8 Oct 17, 2026
@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test registered/e2e/models/test_deepseek_v41_flash_gb300_tp4ep4.py registered/e2e/models/test_deepseek_v4_flash_fp4_megamoe_b200.py

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🚀 4-gpu-gb300 (1 test): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300_tp4ep4.py

🚀 4-gpu-b200 (1 test): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_deepseek_v4_flash_fp4_megamoe_b200.py

@kpham-sgl
kpham-sgl force-pushed the kpham/dsv41-mxfp8-gemm-autotune branch from bf8fec1 to 1abc2e1 Compare October 17, 2026 03:30
@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test registered/unit/model_executor/runner/test_flashinfer_autotune_sync.py registered/unit/server_args/test_server_args.py registered/e2e/models/test_deepseek_v41_flash_gb300_tp4ep4.py registered/e2e/models/test_deepseek_v4_flash_fp4_megamoe_b200.py

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Rebase Required Before Re-run

A major update has landed on main. Your PR is diverged relative to required base commit 6a39ddf1f2e0.

Re-run was not dispatched. What to do:

  • Rebase your branch onto the latest main and push again
  • Follow issue #21065 for context
  • CI-fix PRs may request the bypass-maintenance label to skip this check

@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

GB300 validation, DEP2 (TP2 attention-DP2 EP2), MegaAttention + MegaMoE + Mega-mHC, decoder bounded replay, eager prefill, device prefix cache only, same stack with and without this change (jobs 3471 / 3470, torch profiler on rank 0). The worker log shows Running FlashInfer autotune with cache: .../flashinfer/autotune/0.7.1/sm103/... and FlashInfer autotune completed. about 5 s later, on both DP ranks.

16K-token cold prefill chunk per rank before after
Dense MXFP8 GEMM time (ms), 210 launches 46.5 29.9
Dense MXFP8 GEMM, average per launch (µs) 221 142
GPU kernel time in the step (ms) 219 201
Step wall (ms) 278 276
128K prompt, 8 x 16K steps: dense GEMM (ms) 488 358
128K prompt, 8 x 16K steps: per-step wall (ms) 254 to 275 247 to 266
128K prompt, HTTP latency (s) 1.91 1.77

Launch count is unchanged (1,854 per step), and this eager step is dispatch-bound, so the single-chunk wall barely moves even though 18 ms of kernel time disappears; the gain shows where steps run back to back (128K prompt, -7%) and will show fully once the launch-count reductions land. Cached-prefix extend cells report the full expected cached-token count.

@kpham-sgl
kpham-sgl force-pushed the kpham/dsv41-mxfp8-gemm-autotune branch from 1abc2e1 to a7d12e3 Compare October 17, 2026 03:41
@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test registered/unit/model_executor/runner/test_flashinfer_autotune_sync.py registered/unit/server_args/test_server_args.py registered/e2e/models/test_deepseek_v41_flash_gb300_tp4ep4.py registered/e2e/models/test_deepseek_v4_flash_fp4_megamoe_b200.py

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/model_executor/runner/test_flashinfer_autotune_sync.py

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/server_args/test_server_args.py

🚀 4-gpu-gb300 (1 test): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300_tp4ep4.py

🚀 4-gpu-b200 (1 test): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_deepseek_v4_flash_fp4_megamoe_b200.py

…s MXFP8

`should_run_flashinfer_autotune` only recognised FP8 dense GEMMs as tunable
for `quantization == "mxfp8"` (and modelopt per-tensor FP8). DeepSeek-V4.1
checkpoints are block-FP8 [32, 32] with ue8m0 scales that the FP8 linear
method serves through the MXFP8 view on FlashInfer CuTe-DSL (the same
`mm_mxfp8` op), and the model's `autotune_prefill_kernels` hook exists to
tune exactly those GEMMs at the prefill token ceiling. Because the gate
returned False, neither the decode pass nor that hook ever ran, and every
dense MXFP8 GEMM in prefill used FlashInfer's untuned fallback tactic
(`pin_tactic` stays on since `mxfp8_prefill_autotune_min_tokens` is never
set).

Measured on GB300 with the torch profiler, one 16K-token DEP2 prefill chunk
per rank: the FlashInfer `dense_blockscaled_gemm_sm100` kernel runs 210
times per step at 221 us average, 46.5 ms of a 322 ms step; the shapes are
the fused wqkv_a (N=1792, K=5120), wq_b (N=32768, K=1280) and wo_b (N=5120,
K=8192) at M=16384, all on the untuned tactic. The same kernel's tuned
tactics for these shapes are what the FlashInfer autotuner selects at
warmup when it is allowed to run.

The gate now also returns True when a resident FP8 linear serves block-FP8
as MXFP8 on a FlashInfer backend, so the existing decode pass and the
DeepSeek-V4.1 prefill hook run and persist their tactics under
SGLANG_CACHE_DIR as for mxfp8 models. Numerics: the tuned tactics change
only the GEMM tile/cluster schedule; batch-invariant and deterministic
modes keep the pinned tactic as before. Also drops the stale
"temporarily skips mxfp8_gemm" help text (the workaround set is empty).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@kpham-sgl
kpham-sgl force-pushed the kpham/dsv41-mxfp8-gemm-autotune branch from a7d12e3 to faba28a Compare October 17, 2026 06:48
@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test registered/unit/model_executor/runner/test_flashinfer_autotune_sync.py registered/unit/server_args/test_server_args.py registered/e2e/models/test_deepseek_v41_flash_gb300_tp4ep4.py registered/e2e/models/test_deepseek_v4_flash_fp4_megamoe_b200.py

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/model_executor/runner/test_flashinfer_autotune_sync.py

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/server_args/test_server_args.py

🚀 4-gpu-gb300 (1 test): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300_tp4ep4.py

🚀 4-gpu-b200 (1 test): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_deepseek_v4_flash_fp4_megamoe_b200.py

@kpham-sgl
kpham-sgl merged commit bce7b27 into sgl-project:main Oct 17, 2026
105 of 122 checks passed
detain added a commit to detain/sglang that referenced this pull request Oct 30, 2026
…nchors -- entries 244/247-era surfaces, 301, sgl-project#44842, sgl-project#42973

Battery damage classes re-derived per-file POST-MERGE (CVD=9, prod venv,
PYTHONPATH=python) with the B5-3/B5-4 code state:

(1) test_modelopt_nvfp4_moe_scales 2F (SUBFAILED pair): merge took
  upstream's sgl-project#45289 test file and DROPPED the fork's entry-244 stub block
  (the small-M workspace gate reads placement attrs in
  process_weights_after_loading regardless of kernel support -- kwargs
  evaluate first). Stub block re-planted VERBATIM from the 309 tip.
  20P/44sub (>= the pre-merge 20P/42sub: upstream grew two subtests).
(2) test_fp4_gemm_backend_sm120 3F: upstream sgl-project#44842 (in-range) grew the
  autotune gate with get_parallel().enable_kv_cache_sharding (sgl-project#42973) +
  the FP8->MXFP8 module-tree pre-check; the gate tests' stubs predate
  both. Test re-anchored (get_parallel stub + empty module tree); the
  three beliefs (b12x keeps the pass, cutlass autotunes, marlin doesn't)
  unchanged. 12P/0F.
(3) test_mem_pool_ep_unit 1F: the DOCUMENTED tip-era class, now attributed
  exactly: the test's id-contract predates entry-247 -- dispatcher skip
  TRUE for b12x vs the stale expected-False. Set re-pinned:
  dispatcher_global_ids += FLASHINFER_B12X_W4A16 (its expert_map contract,
  the very arm B5-3 re-planted into _keeps_global_expert_ids) and the LoRA
  subtraction gains b12x (no LoRA path). EXPERIMENTAL_SGL_TRTLLM verified
  HARMLESS without its removed arm: is_flashinfer_trtllm() covers the
  value by design (utils.py:212-217), confirming B5-3's
  upstream-churn verdict on that branch. 49P/0F/4sub -- class CLOSED, one
  fewer env-class than the pre-merge baseline.

ENV CLASSES CONFIRMED (not new, not fixable here):
  trtllm_gen 8F == documented 8F; moe_fused_gate 52F == documented ~52F
  ALL 'No CUDA GPUs are available'; triton_fused_moe 96F == documented
  ~96F; round_robin 38F (documented 37 + 1 upstream-grown CUDA case, ALL
  'No CUDA GPUs'); mega_moe_deepgemm 1F == documented 1F (test's deep_gemm
  fake vs mxfp4.py's in-range wrapper import -- NOT my redirect: fails
  identically at b3207c7 with mega_moe pre-B5-3; B2 marker :905 covers
  the test-side fix).

GATE RE-CHECK: standard_dispatcher 21P (grew again, green),
runner_backend 16P, fold probe 9P, overrides 121P/1S/210sub.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant