Repository navigation
[kernel] add fused silu mul quant fp8 - #37376
Conversation
d6ac1a9 to
503ef02
Compare
BBuf
left a comment
There was a problem hiding this comment.
Change summary
This PR adds an opt-in Triton fusion for the MoE activation boundary: it computes SiLU(gate) * up, derives per-token-group FP8 scales, writes FP8 activations directly, and passes those scales into the down-projection MoE GEMM, avoiding the separate activation buffer and quantization launch.
flowchart LR
A["Gate-up MoE GEMM"] --> B{"Fusion predicate"}:::changed
B -->|fused| C["SiLU × up + group absmax + FP8"]:::changed
C --> D["Down MoE GEMM with fused scales"]:::changed
B -->|fallback| E["Existing activation / modifier path"]
E --> F["Existing group FP8 quantization"]
F --> D
classDef changed stroke-dasharray: 5 5,stroke-width: 2px;
The new server flag enables the fast path only for CUDA blockwise-FP8 gated SiLU MoE. The fused kernel produces row-major activation scales consumed by the existing down GEMM; all unsupported cases should remain on the established activation/modifier path. Dashed nodes are changed by this PR.
Findings
-
[P1] The fusion predicate bypasses two existing correctness contracts (
python/sglang/srt/layers/moe/moe_runner/triton_utils/fused_moe.py:588-597):- It does not require
gemm1_limit is None, so a limit-only model that normally executes_swiglu_silu_clamp_mul()instead gets plain SiLU×up when the flag is enabled. - It can run with an
after_downLoRA hook. The base down GEMM receives the new FP8 scales, but the hook receivesintermediate_cache2as raw FP8 without those scales and uses it as the LoRA down input, changing or breaking adapter output.
Please preserve these paths in the predicate (or implement their exact semantics in the fusion) and add integration tests that exercise
gemm1_limitand active MoE LoRA hooks through_fused_moe_kernel_sequence(). - It does not require
-
[P2]
swiglu_limitis an advertised no-op in the new public wrapper (python/sglang/kernels/ops/moe/fused_moe_triton_kernels.py:1228). The docstring says10.0applies the DeepSeek-V4 clamp, but the argument is never passed into the Triton kernel. Please implement the clamp and test it, or remove the argument/documentation so callers cannot silently get unclamped results.
Review evidence
- Reviewed all five changed files and traced the generated FP8 tensor/scale pair into the down MoE GEMM and LoRA hook call sites.
- Exhaustively swept 32,639 historical human-review threads for every touched path plus SiLU/SwiGLU, FP8, quantization, clamp/modifier, correctness, kernel, performance, and test terms. Prior DeepSeek-V4 reviews specifically require preserving SwiGLU clamp and real end-to-end accuracy, not only isolated kernel tolerance.
- Compared the design with the current upstream vLLM fused SiLU/group-FP8 kernels, which explicitly carry clamp/alpha/beta controls and preserve the intended intermediate precision before quantization.
git diff --checkand Python byte-compilation pass. No CUDA device is available locally, and CI only ran lint/change detection; GPU lanes are gated because the PR lacksrun-ci.
Residual validation risk after the fixes: the test covers the standalone plain-SiLU kernel with tolerance, but the opt-in serving path still needs at least one real FP8 MoE model accuracy/e2e comparison and a benchmark using SGLang's standard kernel timing utilities.
| and activation == "silu" | ||
| and is_gated | ||
| and gemm1_alpha is None | ||
| and swiglu_limit is None |
There was a problem hiding this comment.
[P1] Two existing semantics need guards here. First, gemm1_limit is not excluded, so a limit-only model that normally runs _swiglu_silu_clamp_mul() silently takes plain SiLU×up under this flag. Second, this can run with an after_down LoRA hook: the base down GEMM gets _a2_scale_fused, but the hook receives raw FP8 intermediate_cache2 without its scales and uses it as the LoRA down input. Please preserve both paths in the predicate (or implement their exact semantics) and add _fused_moe_kernel_sequence() integration tests for gemm1_limit and active MoE LoRA.
| tl.store(scale_ptrs, scale, mask=scale_mask) | ||
|
|
||
|
|
||
| def fused_silu_mul_quant_fp8(x, group_size, swiglu_limit=0.0): |
There was a problem hiding this comment.
[P2] swiglu_limit is advertised as supporting the DeepSeek-V4 clamp, but the value is never passed to or read by _fused_silu_mul_quant_fp8_kernel; 10.0 produces exactly the same unclamped result as 0.0. Please implement and test the clamp, or remove this argument/documentation so future callers cannot silently get the wrong semantics.
47217ba to
0c28495
Compare
|
I prepared the CPU CI + auto-dispatch fix in xieminghe1#1. The original PR has Allow edits from maintainers disabled, so GitHub rejected a direct push to the head branch. The follow-up removes the new ServerArgs flag and Validation: CPU legacy ratchet passed; H200 kernel/dispatch suite passed ( |
fix(moe): auto-dispatch fused SiLU FP8 quant
|
/rerun-test test/registered/kernels/ops/quantization/test_fused_silu_mul_quant_fp8.py |
|
Results for 🚀 |
Motivation
Reduce MoE launch and memory-traffic overhead by fusing
silu_and_mulandper_token_group_quant_fp8. The fused Triton kernel computes the gated activation, derives per-token-group FP8 scales, and writes the FP8 down-projection input in one pass.Changes
fused_silu_mul_quant_fp8and its H200 benchmark.swiglu_limitclamp inside the fused kernel.Automatic dispatch
The fast path is selected only when all of the following are true:
gemm1_alphaorgemm1_limitmodifier.swiglu_limitis supported for DeepSeek-V4. Every incompatible case keeps the existing activation + quantization fallback.flowchart LR A[Gate-up MoE GEMM] --> B{CUDA blockwise FP8\nand all contracts match?} B -->|yes| C[Fused SiLU × up + group FP8 quant] B -->|no| D[Existing activation path] D --> E[Existing per-token-group quant] C --> F[Down MoE GEMM with fused scales] E --> FValidation
H200 (
CUDA_VISIBLE_DEVICES=4):Results:
1 test).32 tests).Accuracy results
DeepSeek-V4:
Performance results
H200 activation-boundary benchmark:
End-to-end baseline:
End-to-end fused path (captured on the earlier opt-in revision; after the follow-up merges, the same path is selected automatically with no extra flag):
Comparison:
Checklist
CI States
Latest PR Test (Base): 🚫 Run #34007782658
Latest PR Test (Extra): 🚫 Run #34007782493
Latest PR Test (AMD ROCm 7.2): ❌ Run #34007782660