Repository navigation
[Perf] [AMD] quantization: Fuse SiLU-and-mul with the dynamic per-tensor fp8 quant of dense MLPs on gfx95 - #48536
Conversation
…e MLPs on gfx95 A dense MLP whose down projection has per-tensor fp8 weights and dynamic activation scales, such as an online --quantization fp8 model, runs SiluAndMul and then aiter's dynamic per-tensor quant on every decode step. On gfx95, with TP 1 and up to 128 decode tokens, DenseSiluAndMulQuant now hands that down projection its quantized activation from a two-launch Triton kernel instead. The kernel writes the bytes and the scale aiter writes: the SiLU and the product rounded to bf16 as SiluAndMul rounds them, amax * (1 / max) as the scale, and the activation times the scale's approximate v_rcp_f32. test_aiter_fp8_quant_triton checks the kernel byte for byte against silu_and_mul and dynamic_per_tensor_quant; test_dense_silu_fp8_per_tensor_gfx95 checks real Llama and Qwen2 MLPs against their unfused output, under CUDA graph replay too.
|
/tag-and-rerun-ci |
|
@BBuf could you take a look? On gfx95 this fuses |
BBuf
left a comment
There was a problem hiding this comment.
[BBuf Review Agent] LGTM. Please wait for the related AMD CI.
|
@BBuf the AMD MI35x stage-b 1-GPU small stage is green on this head ( |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
[BBuf Review Agent] @siliangchen-amd these still fail after a rerun, and I can't tell from the logs whether it's this PR. Could you take a look?
|
|
@BBuf none of these come from this PR. The NVIDIA jobs never reached a test that touches it, and the Arm64 one comes from this branch's base predating #37597:
The change only runs under |
|
[BBuf Review Agent] @siliangchen-amd Agreed, the HIP/gfx95 guards and AMD-only test registration support treating this failure as unrelated. The local history also confirms the branch predates #37597; please go ahead with the rebase. |
|
@BBuf for context on the red MI35x small stage here: it fails only on |
|
[BBuf Review Agent] @siliangchen-amd Agreed, the MiniMax test and attention backend are unchanged from the merged main, and the fake pool lacks the required |
|
/rerun-failed-ci |
PR Pundit review(Testing PR Pundit Code Review agent. Not all comments may be relevant. This is a one-time automated pass: please address what is useful, no need to request a re-review. Please reply to each point, whether it applies or not: we harvest these replies, and both kinds are enormously helpful for tuning the agent. Reach out to @peymanr for suggestions.)
1. 🟠 Should fix: ROCm decode fp8 activations drift by bf16 rounding under aiter SiLU: this PR's gate omits forward-method check
Who is affected: gfx95 users of dense per-tensor FP8 models at tp=1 with SGLANG_USE_AITER=1 who also set SGLANG_OPT_USE_AITER_SILU_MUL=1. Checked against the code by an independent pass. Related past reviews: #37376 on 2. 🟠 Should fix: Second quant kernel does redundant O(n_tiles^2) tile-max loads and extra warmup compiles
In Who is affected: gfx95 ROCm users with SGLANG_USE_AITER, tp=1, online/dynamic per-tensor FP8 dense MLPs, at decode batch sizes ≤128. Checked against the code by an independent pass. Related past reviews: #6369 on 3. 🟠 Should fix: Parity asserts may fail spuriously outside CI: test sets
|
|
Replies to the PR Pundit review above, checked against
I'll send 1 and 3 as a small follow-up after this PR lands, so this approved head and its CI stay as they are. Say if you would rather have them in this PR. |
|
[BBuf Review Agent] @siliangchen-amd The bounded reduction is fine. Could you include the forward-method guard and set AITER before the test's sglang imports in this PR, since both issues come from the new code here? |
…re the test's imports The ROCm gate now falls back unless SiluAndMul resolves to forward_cuda, as the CUDA gate does: with SGLANG_OPT_USE_AITER_SILU_MUL=1 the activation is aiter's, whose rounding the fused kernel does not reproduce. The test sets SGLANG_USE_AITER before importing SGLang, since the unfused reference quantizer is chosen at import, and covers the aiter activation.
|
Both are in
On MI355X (gfx950), image
|
|
[BBuf Review Agent] @siliangchen-amd Both requests are addressed in |
|
[BBuf Review Agent] Could you rebase this onto the latest main? It conflicts with main now. |
|
Merged the latest main in One change beyond the textual merge: git put #48043's |
|
@BBuf the merge of the latest main is pushed as |
|
@BBuf the required checks ( |
Motivation
On ROCm, a dense MLP whose down projection has per-tensor FP8 weights and dynamic activation scales, such as an online
--quantization fp8Qwen3-8B or Llama-3.1-8B, runsSiluAndMuland then aiter'sdynamic_per_tensor_quanton every decode step, as separate launches around a small decode GEMM.DenseSiluAndMulQuantalready fuses the activation and its quant for the block-FP8 DeepGEMM path on SM100; this adds the per-tensor case on gfx95.Modifications
python/sglang/kernels/ops/quantization/aiter_fp8_quant_triton.py:silu_and_mul_fp8_per_tensor, a two-launch Triton kernel (each tile's absmax, then the reduction and the quant) that writes the bytes and the scaleSiluAndMulfollowed bydynamic_per_tensor_quantwrites: the SiLU and the product rounded to bf16,amax * (1 / max)as the scale, and the activation times the scale's approximatev_rcp_f32. For an all-zero tensor it writes 0 where aiter writes -448 at scale 0; both dequantize to 0.python/sglang/srt/layers/quantization/fp8_activation.py: on gfx95 with aiter and TP 1, for aRowParallelLineardown projection underFp8LinearMethodwith dynamic activations, per-tensor weights and no static input scale,DenseSiluAndMulQuant.forward_decodereturns(q, scale, dtype)for decode batches of up to 128 tokens, whichFp8LinearMethod.applyalready takes. Everything else keepsSiluAndMul.test/registered/kernels/ops/quantization/test_aiter_fp8_quant_triton.py: the kernel's bytes and scale againstsilu_and_mulfollowed bydynamic_per_tensor_quant, and an all-zero input.test/registered/unit/layers/quantization/test_dense_silu_fp8_per_tensor_gfx95.py(new): real Llama and Qwen2 MLPs, fused against unfused bit for bit, under CUDA graph replay too; batches past 128 tokens and non-decode modes keepSiluAndMul.Accuracy Tests
GSM8K, all 1319 questions (
python -m sglang.test.few_shot_gsm8k --num-questions 1319 --parallel 128), one MI355X (gfx950), TP 1,SGLANG_USE_AITER=1,--quantization fp8:Invalid answers are 0.000 on both.
Speed Tests and Profiling
python -m sglang.benchmark.one_batch --quantization fp8 --batch-size 1 16 64 --input-len 1024 --output-len 64, same setup, median decode step:Setup: the
lmsysorg/sglang-rocm:v0.5.23-rocm720-mi35x-20261103image, with sglang from source at 1d062d2 andblake3installed.mainis the same tree withfp8_activation.pyat 1d062d2, which never calls the new kernel.Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ✅ Run #42438315678
Latest PR Test (Extra): ❌ Run #42438315661
Latest PR Test (AMD ROCm 10): ✅ Run #42438315623
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: