[XPU][MoE Refactor] Refactor xpu mxfp4 support into oracle (#37784)

Signed-off-by: Kunshang Ji <kunshang.ji@intel.com>
This commit is contained in:
Kunshang Ji
2026-03-23 11:10:41 +00:00
committed by GitHub
parent 9ace378a63
commit debd6e768c
3 changed files with 54 additions and 101 deletions
@@ -141,7 +141,10 @@ def backend_to_kernel_cls(
return [AiterExperts]
elif backend == Mxfp4MoeBackend.XPU:
raise NotImplementedError("XPU backend uses XpuMxfp4MoEMethod directly.")
from vllm.model_executor.layers.fused_moe.xpu_fused_moe import XPUExpertsMXFp4
return [XPUExpertsMXFp4]
else:
raise ValueError(f"Unknown MXFP4 MoE backend: {backend.value}")
@@ -156,6 +159,7 @@ def map_mxfp4_backend(runner_backend: str) -> Mxfp4MoeBackend:
"triton": Mxfp4MoeBackend.TRITON,
"marlin": Mxfp4MoeBackend.MARLIN,
"ck": Mxfp4MoeBackend.CK,
"xpu": Mxfp4MoeBackend.XPU,
}
if backend := mapping.get(runner_backend):
return backend
@@ -178,6 +182,7 @@ def _get_priority_backends() -> list[Mxfp4MoeBackend]:
Mxfp4MoeBackend.TRITON_UNFUSED,
Mxfp4MoeBackend.MARLIN,
Mxfp4MoeBackend.BATCHED_MARLIN,
Mxfp4MoeBackend.XPU,
]
return _AVAILABLE_BACKENDS
@@ -351,7 +356,13 @@ def select_mxfp4_moe_backend(
if current_platform.is_xpu():
backend = Mxfp4MoeBackend.XPU
logger.info_once(_make_log_backend(backend))
return backend, None
return _return_or_raise(
Mxfp4MoeBackend.XPU,
config,
kMxfp4Static,
None,
activation_format,
)
if current_platform.is_cuda() or current_platform.is_rocm():
raise NotImplementedError(
@@ -741,6 +752,16 @@ def convert_to_mxfp4_moe_kernel_format(
w13_bias,
w2_bias,
)
elif mxfp4_backend == Mxfp4MoeBackend.XPU:
# No additional transformation needed for XPU backend
return (
w13_weight,
w2_weight,
w13_weight_scale,
w2_weight_scale,
w13_bias,
w2_bias,
)
else:
raise ValueError(
f"Unsupported mxfp4_backend: {mxfp4_backend}: "
@@ -16,6 +16,7 @@ from vllm.model_executor.layers.quantization.utils.quant_utils import (
QuantKey,
kFp8DynamicTensorSym,
kFp8StaticTensorSym,
kMxfp4Static,
)
from vllm.platforms import current_platform
@@ -38,6 +39,7 @@ class XPUExperts(mk.FusedMoEExpertsModular):
num_dispatchers,
)
self.is_fp8 = False
self.is_mxfp4 = False
@property
def expects_unquantized_inputs(self) -> bool:
@@ -137,6 +139,7 @@ class XPUExperts(mk.FusedMoEExpertsModular):
ep_size=self.moe_config.ep_size,
output=output,
is_fp8=self.is_fp8,
is_mxfp4=self.is_mxfp4,
)
@@ -155,3 +158,30 @@ class XPUExpertsFp8(XPUExperts):
num_dispatchers,
)
self.is_fp8 = True
class XPUExpertsMXFp4(XPUExperts):
def __init__(
self,
moe_config: FusedMoEConfig,
quant_config: FusedMoEQuantConfig,
max_num_tokens: int | None = None,
num_dispatchers: int | None = None,
):
super().__init__(
moe_config,
quant_config,
max_num_tokens,
num_dispatchers,
)
self.is_mxfp4 = True
@staticmethod
def _supports_quant_scheme(
weight_key: QuantKey | None,
activation_key: QuantKey | None,
) -> bool:
SUPPORTED_W_A = [
(kMxfp4Static, None),
]
return (weight_key, activation_key) in SUPPORTED_W_A