Skip to content

[Perf] mlp: Fuse dense SwiGLU with block-FP8 quantization on decode - #45219

Merged
BBuf merged 11 commits into
sgl-project:mainfrom
JiaFengYu:perf/dense-swiglu-block-fp8
Oct 22, 2026
Merged

BBuf merged 11 commits into
sgl-project:mainfrom
JiaFengYu:perf/dense-swiglu-block-fp8

Conversation

@JiaFengYu

@JiaFengYu JiaFengYu commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Dense block-FP8 MLPs normally launch SwiGLU to materialize a BF16 activation, then launch activation quantization before the down-projection GEMM. This PR fuses those two operations for eligible decode calls, removing one launch and the intermediate BF16 write/read per MLP.

The latest controlled comparison measured 1.92% lower single-request decode TPOT on Qwen3-8B-FP8 on a B200. This is activation/MLP fusion, independent of KV-cache dtype. Concurrent decode and the full-patch prefill non-regression claim have the limitations documented below; this is not an unconditional performance clearance.

Modifications

  • Extend the existing JIT per_token_group_quant kernel with an explicit dense SwiGLU mode. Match the dense CUDA activation's compiler math and round the product to source precision before quantization, without materializing it in HBM. Reuse the existing quantizer and UE8M0 packing machinery; the default/legacy mode is unchanged.
  • Allow the DeepGEMM block-FP8 wrapper to consume validated prequantized FP8 activations and column-major packed UE8M0 scales. Reject incompatible packed layouts instead of passing them to a fallback that cannot consume them.
  • Add a shared DenseSiluAndMulQuant helper and small Llama/Qwen2 MLP integrations; Qwen3 uses the Qwen2 implementation. The runtime fast path is limited to SM100-family CUDA, TP1, ordinary decode, BF16 activations, and dynamic block-128 FP8 with DeepGEMM/UE8M0.
  • Call the helper only for decode. Prefill/extend, speculative verification, other non-decode modes, and calls without a forward batch invoke the original activation directly. Keep the helper's own eligibility checks and preserve fallbacks for unsupported layouts/dtypes/backends, LoRA, deterministic execution, compilation, and overrides. Preserve DualGemm unchanged. The model-level phase check remains; this is not a claim of literally zero host overhead.
  • Use the current fused-op _resolve_forward_method() API when the activation's cached method is unset. This resolves the callable without launching activation; it preserves the check that the dense CUDA activation implementation is selected.
  • Keep operator tests with the quantizer and real-MLP dispatch/graph tests under test/registered/unit/layers/quantization/, registered for the B200 runtime-test stage. Cover cold dispatch and require every non-decode mode to bypass the helper. Include the kernel benchmark extension and standalone numerical-sweep/MLP microbenchmark; keep server A/B automation local and outside this PR.

Checks on B200 with PyTorch 2.14.1+cu130 and CUDA toolkit 13.0:

Check Result
Full per-token-group quantizer suite 167 passed
Kernel namespace and fused-op dispatch suites 119 passed, 1 skipped
Real Llama/Qwen MLP integration, fallback gates, CUDA graph replay 3 passed, 13 subtests passed
Packed DeepGEMM input regression 1 passed, 3 subtests passed
Existing DualGemm regressions 6 passed, 2 subtests passed
Llama parallel regressions 2 passed, 32 subtests passed
Total unique registered tests 298 passed, 1 skipped, plus 50 subtests
Extended numerical sweep 240 cases; 184,023,040 FP8 bytes checked; exact FP8/scales parity
Compute Sanitizer memcheck 46 repeated subset cases; zero memory errors
Full pinned pre-commit suite and diff whitespace checks Passed

The dense quantizer tests compare FP8 bytes and scale bits against the real CUDA SwiGLU followed by the existing quantizer, including BF16/FP16 sources, multiple shapes and scale layouts, special values, non-mutation, and graph replay. Runtime integration is narrower than the standalone operator: BF16 only. Real-MLP and packed-DeepGEMM comparisons use zero tolerance. The non-decode bypass regression failed before the dispatch changes and passed afterward. Repeated test runs and the memcheck subset are not added to the unique-test total.

In the latest full A/B, all 174,720 measured client requests completed without reported request errors. All 81,920 paired prefill texts and 320/320 concurrency-1 decode responses matched. Concurrency-32 decode matched 5,084/5,120 paired responses: those differences are disclosed, and their cause was not isolated. A separate 192-output-token probe had identical token IDs and zero corresponding logprob difference. Both variants scored 19/20 on the GSM8K sanity sample. These focused checks are not a comprehensive model-quality evaluation or a claim of bit-identical concurrent generation.

Speed tests and profiling

Full fusion versus direct unfused activation

Ten paired fresh-server comparisons on one B200, TP1, Qwen/Qwen3-8B-FP8, DeepGEMM, BF16 activations, TRTLLM MHA, KV dtype auto resolving to BF16, full decode CUDA graphs, breakable prefill CUDA graphs, and torch.compile disabled. Runtime dependencies included Python 3.12.15, PyTorch 2.14.1+cu130, CUDA toolkit 13.0, sgl-deep-gemm 0.2.3, sglang-kernel 0.4.10, and FlashInfer 0.7.2.

Five pairs were baseline-first and five fused-first, with matched requests and alternating phase/concurrency order. There were no result-dependent retries, exclusions, or added pairs. All 80 timed windows were unprofiled and excluded server startup:

  • Prefill: exact 1,024 input token IDs and one output token; 1,024 warmups and 4,096 measured requests per window. Every response reported zero cached tokens. TTFT uses the first token-bearing SSE event, including blank rendered output.
  • Decode: nominal 1,024 inputs and 512 outputs using the stock serving benchmark, random-ids, seed 42, temperature zero. Concurrency 1 used 16 warmups and 32 measured requests; concurrency 32 used 128 warmups and 512 measured requests. Actual input lengths after text round-trip were 992-1,325 and 867-1,360 respectively, with identical vectors across variants. These are client concurrency limits, not fixed GPU batch sizes.

Changes are geometric means of ten paired per-window median ratios. Negative means lower latency. Intervals are paired log-ratio Student-t 97.5% two-sided confidence intervals, df=9. The absolute columns are medians of ten run medians; their ratio is not the paired estimator.

Workload Metric Baseline Fused Paired change 97.5% interval Interpretation
Decode, concurrency 1 Median TPOT 3.02064 ms 2.96433 ms -1.921% [-2.082, -1.759]% Faster in 10/10 pairs
Decode, concurrency 32 Stock median TPOT 4.35948 ms 4.30988 ms -0.919% [-1.643, -0.188]% Provisional: client timing defect
Prefill, concurrency 1 Median TTFT 13.199 ms 13.363 ms +0.662% [-0.464, +1.800]% Inconclusive against the +1% non-regression bound
Prefill, concurrency 32 Median TTFT 314.701 ms 314.469 ms +0.062% [-0.132, +0.256]% Passes the +1% bound; not a speedup claim

Secondary whole-request latency decreased 1.901% at concurrency 1 (interval [-2.077, -1.724]%) and 0.837% at concurrency 32 ([-1.083, -0.590]%), with 10/10 paired wins each. These are secondary metrics, not substitutes for an invalid primary endpoint.

Limitations: the stock decode client records timing only when rendered text is nonempty. One response per concurrency-32 window had empty text, TTFT zero, no inter-token timings, and a defaulted completion length. All 20 affected responses were retained; no statistics were silently corrected. That TPOT result remains provisional. Prefill concurrency 1 also remains inconclusive against the +1% bound and showed execution-order sensitivity. The full experiment therefore does not establish unconditional prefill neutrality or an all-workload performance clearance.

Incremental prefill effect of bypassing the helper

A separate, predeclared ten-pair experiment compared the previous fused implementation (always enters the helper; helper falls back on prefill) against the new decode-only call sites. Both retain decode fusion and the callable-resolution fix; only the two MLP dispatch sites differ. It used the same model/runtime, exact 1,024-input/one-output uncached requests, and concurrency 1/32, with 1,024 warmups and 4,096 measured requests per window.

All 163,840 measured requests and 40,960 warmups succeeded, and all 81,920 paired texts matched. No pairs were retried, excluded, or added. The paired estimator and 97.5% Student-t intervals are reported separately from the full-fusion experiment.

Client concurrency Previous fused TTFT New bypass TTFT Paired change 97.5% interval +1% non-regression bound
1 13.353 ms 13.326 ms -0.155% [-0.979, +0.676]% Pass
32 315.272 ms 314.586 ms -0.158% [-0.470, +0.156]% Pass

This supports keeping the bypass for explicit non-decode isolation. Neither a prefill speedup nor a slowdown is statistically established. It bounds the incremental change relative to the previous fused implementation.

Engagement and scope

Post-timing first-pair profiles from the full A/B recorded 5,667 GPU kernels in the baseline and 5,343 with fusion, including 324 dense-fused launches only in the fused variant. Separate activation launches decreased from 360 to 36. This is 324 net launches removed in a mixed ten-step capture (one prefill plus nine decode steps), not a per-token count. Profiler durations were not used for end-to-end latency claims.

Both experiments retained frozen source manifests, plans, raw measurements, and ownership/telemetry checks. No foreign compute process was observed on the selected GPU in sampled checks; its 750 W power cap was unchanged and no thermal-slowdown samples were recorded. Clocks were not locked and the host was shared. Results apply to this model/configuration, not all workloads. H100, TP greater than one, and MoE are outside the runtime fast path.

Reproduction and retained evidence

With this checkout and matching dependencies installed on a B200:

python test/manual/kernels/bench_dense_swiglu_quant.py --check-only

Representative server command used in the full A/B and direct bypass comparison:

python -m sglang.launch_server \
  --model-path Qwen/Qwen3-8B-FP8 \
  --revision 220b46e3b2180893580a4454f21f22d3ebb187d3 \
  --dtype bfloat16 --tp-size 1 --fp8-gemm-backend deep_gemm \
  --mem-fraction-static 0.6 --random-seed 42 \
  --host 127.0.0.1 --port 30000

Variant selection used frozen Python source snapshots; all other server settings were identical. The local-only full_run.py/runner.py and direct-comparison run.py retain the orchestration, preregistered plans, and raw results. Evidence identifiers are sglang-swiglu-prefill-bypass.dCzr2o (focused checks), sglang-swiglu-prefill-bypass-run.4j38zT (full A/B), and sglang-swiglu-direct-bypass.9mmC3I (incremental bypass comparison). These artifacts are retained locally and are not publicly attached. Independent reproduction of the exact server tables requires supplying those harnesses/manifests; the included microbenchmark and server command alone do not reproduce them.

Checklist

  • Add focused operator and runtime integration tests.
  • Run local correctness, graph-replay, fallback, and memory-safety checks.
  • Provide controlled live A/B measurements and disclose their limitations.
  • Complete the full pinned pre-commit hook suite.
  • Obtain passing required PR CI on the submitted commit.

CI States

Latest PR Test (Base): ❌ Run #39817918938
Latest PR Test (Extra): 🚫 Run #39817918671
Latest PR Test (AMD ROCm 10): ❌ Run #39817918271

@github-actions github-actions Bot added quant LLM Quantization jit-kernel labels Oct 19, 2026
@JiaFengYu JiaFengYu changed the title [JIT] Fuse dense SwiGLU with block-FP8 quantization on decode [Perf] mlp: Fuse dense SwiGLU with block-FP8 quantization on decode Oct 21, 2026

@BBuf BBuf 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.

The decode-only fusion approach looks reasonable. Please address the cleanup comments to keep the implementation and tests small. I haven't rerun the B200 checks; required CI still needs to run.

or x.stride(0) % 16 != 0
or x.device != down_proj.weight.device
or x.shape[1] != 2 * down_proj.weight.shape[1]
or down_proj.weight.shape[1] % 128 != 0

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.

Could we reuse _deepgemm_block_fp8_supported instead of repeating the % 128 / % 64 rules here? Please also move checks of layer properties that stay fixed after weight loading out of the per-call path where practical. Keep the dynamic mode, override and input checks, but aim for a much smaller dispatch helper.

@BBuf BBuf added the run-ci CI: run the baseline test suite on this PR label Oct 22, 2026
@BBuf BBuf added the run-ci-extra CI: also run the extra suite (requires run-ci) label Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jit-kernel quant LLM Quantization run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants