Repository navigation
[Perf] mlp: Fuse dense SwiGLU with block-FP8 quantization on decode - #45219
Merged
Merged
Conversation
JiaFengYu
marked this pull request as ready for review
October 21, 2026 06:38
JiaFengYu
requested review from
Alisehen,
AniZpZ,
BBuf,
DarkSharpness,
Edwardf0t1,
FlamingoPg,
HaiShaw,
HydraQYH,
OrangeRedeng,
b8zhong,
celve,
ch-wan,
mmangkad and
yuan-luo
as code owners
October 21, 2026 06:38
BBuf
approved these changes
Oct 21, 2026
BBuf
left a comment
Collaborator
There was a problem hiding this comment.
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 |
Collaborator
There was a problem hiding this comment.
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.
This was referenced Oct 23, 2026
4 of 5 tasks
4 of 5 tasks
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
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
per_token_group_quantkernel 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.DenseSiluAndMulQuanthelper 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._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.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:
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 dtypeautoresolving 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:
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.
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.
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:
Representative server command used in the full A/B and direct bypass comparison:
Variant selection used frozen Python source snapshots; all other server settings were identical. The local-only
full_run.py/runner.pyand direct-comparisonrun.pyretain the orchestration, preregistered plans, and raw results. Evidence identifiers aresglang-swiglu-prefill-bypass.dCzr2o(focused checks),sglang-swiglu-prefill-bypass-run.4j38zT(full A/B), andsglang-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
CI States
Latest PR Test (Base): ❌ Run #39817918938
Latest PR Test (Extra): 🚫 Run #39817918671
Latest PR Test (AMD ROCm 10): ❌ Run #39817918271