[XPU][MoE] Add WNA16 oracle backend for GPTQ sym-int4 (xpu_fused_moe) (#41426)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Kunshang Ji <kunshang.ji@intel.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
Kunshang Ji
parent
a9ec46d4b7
commit
3207e7680e
@@ -16,6 +16,7 @@ from vllm.model_executor.layers.quantization.utils.quant_utils import (
|
||||
QuantKey,
|
||||
kFp8DynamicTensorSym,
|
||||
kFp8StaticTensorSym,
|
||||
kInt4Static,
|
||||
kMxfp4Static,
|
||||
kMxfp8Dynamic,
|
||||
kMxfp8Static,
|
||||
@@ -48,6 +49,7 @@ class XPUExperts(mk.FusedMoEExpertsModular):
|
||||
num_dispatchers,
|
||||
)
|
||||
self.is_fp8 = False
|
||||
self.is_int4 = False
|
||||
self.is_mxfp4 = False
|
||||
self.is_mxfp8 = False
|
||||
self.fused_moe_impl: XpuFusedMoe | None = None
|
||||
@@ -133,6 +135,15 @@ class XPUExperts(mk.FusedMoEExpertsModular):
|
||||
expert_tokens_meta: mk.ExpertTokensMetadata | None,
|
||||
apply_router_weight_on_input: bool,
|
||||
):
|
||||
# The kernel takes is_fp8/is_int4/is_mxfp4 as independent booleans.
|
||||
# In this hierarchy each subclass flips exactly one to True; assert
|
||||
# the invariant so a future subclass that sets two doesn't silently
|
||||
# miscompute (kernel-side priority is undocumented).
|
||||
assert sum([self.is_fp8, self.is_int4, self.is_mxfp4]) <= 1, (
|
||||
"XPUExperts: at most one of is_fp8, is_int4, is_mxfp4 may be True; "
|
||||
f"got is_fp8={self.is_fp8}, is_int4={self.is_int4}, "
|
||||
f"is_mxfp4={self.is_mxfp4}."
|
||||
)
|
||||
if self.fused_moe_impl is None:
|
||||
topk = topk_ids.size(-1)
|
||||
self.fused_moe_impl = XpuFusedMoe(
|
||||
@@ -148,6 +159,7 @@ class XPUExperts(mk.FusedMoEExpertsModular):
|
||||
ep_rank=self.moe_config.ep_rank,
|
||||
ep_size=self.moe_config.ep_size,
|
||||
is_fp8=self.is_fp8,
|
||||
is_int4=self.is_int4,
|
||||
is_mxfp4=self.is_mxfp4,
|
||||
is_mxfp8=self.is_mxfp8,
|
||||
)
|
||||
@@ -217,6 +229,42 @@ class XPUExpertsMxfp8(XPUExpertsFp8):
|
||||
return (weight_key, activation_key) in SUPPORTED_W_A
|
||||
|
||||
|
||||
class XPUExpertsWNA16(XPUExperts):
|
||||
"""W4A16 INT4-symmetric MoE backed by `xpu_fused_moe(is_int4=True)`.
|
||||
|
||||
Weight layout when `is_int4=True` (per `xpu_fused_moe` docstring):
|
||||
w13: [num_experts, 2*inter_size, hidden_size] contiguous int4-packed
|
||||
w13_scales: [num_experts, 2*inter_size, hidden_size // group_size]
|
||||
w2: [num_experts, hidden_size, inter_size] contiguous int4-packed
|
||||
w2_scales: [num_experts, hidden_size, inter_size // group_size]
|
||||
|
||||
Pairs with `INCXPULinearMethod` for the linear layers; together they
|
||||
cover full-attn + MoE on Intel XPU end-to-end without IPEX.
|
||||
"""
|
||||
|
||||
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_int4 = True
|
||||
|
||||
@staticmethod
|
||||
def _supports_quant_scheme(
|
||||
weight_key: QuantKey | None,
|
||||
activation_key: QuantKey | None,
|
||||
) -> bool:
|
||||
return (weight_key, activation_key) == (kInt4Static, None)
|
||||
|
||||
|
||||
class XPUExpertsMXFp4(XPUExperts):
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user