[MoE] Refine FlashInfer one-sided All2All integration (#51924)

Signed-off-by: Bo Li <22713281+bobboli@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Bo Li
2026-08-18 00:18:14 +00:00
committed by GitHub
co-authored by mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 0db502c8d8
commit c296851a7d
8 changed files with 129 additions and 68 deletions
@@ -36,6 +36,28 @@ from vllm.utils.flashinfer import has_flashinfer_trtllm_fused_moe
logger = init_logger(__name__)
def prepare_deepseek_fp8_x_sf(x: torch.Tensor, x_sf: torch.Tensor) -> torch.Tensor:
"""Validate DeepSeek Blockwise FP8 tensors and return TRTLLM layout."""
if x.dtype != current_platform.fp8_dtype():
raise ValueError(
f"DeepSeekFp8 activations must use the platform E4M3 dtype; got {x.dtype}"
)
if x.ndim != 2 or x.shape[1] % 128 != 0:
raise ValueError(
"DeepSeekFp8 activations must be [M,K] with K divisible by 128; "
f"got {tuple(x.shape)}"
)
expected_shape = (x.shape[0], x.shape[1] // 128)
if x_sf.dtype != torch.float32 or tuple(x_sf.shape) != expected_shape:
raise ValueError(
"DeepSeekFp8 activation scales must be FP32 [M,K/128]; "
f"expected {expected_shape}, got dtype={x_sf.dtype}, "
f"shape={tuple(x_sf.shape)}"
)
# FlashInfer TRTLLM-gen consumes [K/128,M] for DeepSeekFp8/BlockMajorK.
return x_sf.t().contiguous()
class TrtLlmFp8ExpertsBase:
"""
Fp8 TRTLLM-Gen MoE kernels. Shared base for modular and monolithic
@@ -239,6 +261,10 @@ class TrtLlmFp8ExpertsModular(TrtLlmFp8ExpertsBase, mk.FusedMoEExpertsModular):
# Pack topk ids and weights into format expected by the kernel.
packed_topk_ids = trtllm_moe_pack_topk_ids_weights(topk_ids, topk_weights)
if a1q_scale is None:
raise RuntimeError(
"TRT-LLM FP8 experts require precomputed activation scales"
)
assert a1q_scale is not None
is_mxfp8 = self.quant_config.block_shape == [1, 32]
@@ -251,7 +277,7 @@ class TrtLlmFp8ExpertsModular(TrtLlmFp8ExpertsBase, mk.FusedMoEExpertsModular):
fp8_quant_type = Fp8QuantizationType.DeepSeekFp8
use_shuffled_weight = True
weight_layout = WeightLayout.BlockMajorK
hidden_states_scale = a1q_scale.t().contiguous()
hidden_states_scale = prepare_deepseek_fp8_x_sf(hidden_states, a1q_scale)
flashinfer.fused_moe.trtllm_fp8_block_scale_routed_moe(
topk_ids=packed_topk_ids,