From 03ddc1c9bc5e448e0da6236268a611d7d001dbae Mon Sep 17 00:00:00 2001 From: Yiliu Dong <91178480+qianlihuang@users.noreply.github.com> Date: Mon, 18 May 2026 09:57:04 +0800 Subject: [PATCH] [Perf] Wire silu_and_mul_per_block_quant into TritonFP8MoE (MiniMax-M2) (#42497) Signed-off-by: qianlihuang Signed-off-by: Yiliu Dong <91178480+qianlihuang@users.noreply.github.com> Co-authored-by: qianlihuang --- .../layers/fused_moe/experts/triton_moe.py | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/vllm/model_executor/layers/fused_moe/experts/triton_moe.py b/vllm/model_executor/layers/fused_moe/experts/triton_moe.py index f3a8e40e54..77eb483e9f 100644 --- a/vllm/model_executor/layers/fused_moe/experts/triton_moe.py +++ b/vllm/model_executor/layers/fused_moe/experts/triton_moe.py @@ -31,6 +31,9 @@ from vllm.model_executor.layers.fused_moe.utils import ( _resize_cache, moe_kernel_quantize_input, ) +from vllm.model_executor.layers.quantization.utils.fp8_utils import ( + is_deep_gemm_e8m0_used, +) from vllm.model_executor.layers.quantization.utils.quant_utils import ( QuantKey, kFp8Dynamic128Sym, @@ -283,20 +286,36 @@ class TritonExperts(LoRAExpertsMixin, mk.FusedMoEExpertsModular): top_k_num=top_k_num, ) - self.activation( - activation, intermediate_cache2, intermediate_cache1.view(-1, N) - ) - a2q_scale: torch.Tensor | None = None - qintermediate_cache2, a2q_scale = moe_kernel_quantize_input( - intermediate_cache2, - a2_scale, - self.quant_dtype, - self.per_act_token_quant, - self.block_shape, - quantization_emulation=self.quantization_emulation, - ) + # Fuse SiLU+Mul + FP8 block quantize into a single kernel + # when conditions permit (gated SiLU, fp8 block quant with + # group_size=128, no LoRA requiring the BF16 intermediate). + if ( + activation == MoEActivation.SILU + and self.quant_config.use_fp8_w8a8 + and self.block_shape == [128, 128] + and lora_context is None + and not is_deep_gemm_e8m0_used() + ): + qintermediate_cache2, a2q_scale = ops.silu_and_mul_per_block_quant( + intermediate_cache1.view(-1, N), + group_size=128, + quant_dtype=current_platform.fp8_dtype(), + ) + else: + self.activation( + activation, intermediate_cache2, intermediate_cache1.view(-1, N) + ) + + qintermediate_cache2, a2q_scale = moe_kernel_quantize_input( + intermediate_cache2, + a2_scale, + self.quant_dtype, + self.per_act_token_quant, + self.block_shape, + quantization_emulation=self.quantization_emulation, + ) invoke_fused_moe_triton_kernel( qintermediate_cache2,