[XPU] Route grouped_topk to the fused _moe_C kernel on XPU (#53580)

Signed-off-by: Marceli Fylcek <marceli.fylcek@intel.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Marceli Fylcek
2026-09-07 17:43:38 +08:00
committed by GitHub
co-authored by Claude Opus 5
parent 7dbe386833
commit 9b85112e13
2 changed files with 23 additions and 3 deletions
+22 -2
View File
@@ -2500,9 +2500,9 @@ def grouped_topk(
bias: Bias tensor (e_score_correction_bias). Always fused in kernel. bias: Bias tensor (e_score_correction_bias). Always fused in kernel.
scoring_func: 0=none (no activation), 1=sigmoid scoring_func: 0=none (no activation), 1=sigmoid
""" """
if not current_platform.is_cuda(): if not (current_platform.is_cuda() or current_platform.is_xpu()):
raise NotImplementedError( raise NotImplementedError(
"The fused grouped_topk kernel is only available on CUDA platforms" "The fused grouped_topk kernel is only available on CUDA and XPU platforms"
) )
return torch.ops._moe_C.grouped_topk( return torch.ops._moe_C.grouped_topk(
scores, scores,
@@ -2516,6 +2516,26 @@ def grouped_topk(
) )
if hasattr(torch.ops, "_moe_C") and hasattr(torch.ops._moe_C, "grouped_topk"):
@register_fake("_moe_C::grouped_topk")
def _grouped_topk_fake(
scores: torch.Tensor,
num_expert_group: int,
topk_group: int,
topk: int,
renormalize: bool,
routed_scaling_factor: float,
bias: torch.Tensor,
scoring_func: int = 0,
) -> tuple[torch.Tensor, torch.Tensor]:
num_tokens = scores.size(0)
return (
scores.new_empty((num_tokens, topk), dtype=torch.float32),
scores.new_empty((num_tokens, topk), dtype=torch.int32),
)
def moe_wna16_marlin_gemm( def moe_wna16_marlin_gemm(
input: torch.Tensor, input: torch.Tensor,
output: torch.Tensor | None, output: torch.Tensor | None,
@@ -90,7 +90,7 @@ def grouped_topk(
) -> tuple[torch.Tensor, torch.Tensor]: ) -> tuple[torch.Tensor, torch.Tensor]:
if ( if (
envs.VLLM_USE_FUSED_MOE_GROUPED_TOPK envs.VLLM_USE_FUSED_MOE_GROUPED_TOPK
and current_platform.is_cuda() and (current_platform.is_cuda() or current_platform.is_xpu())
and num_expert_group <= 32 and num_expert_group <= 32
and topk <= 32 and topk <= 32
and e_score_correction_bias is not None and e_score_correction_bias is not None