diff --git a/tests/quantization/test_auto_round.py b/tests/quantization/test_auto_round.py index 6df7211549b8..f2bab28f602b 100644 --- a/tests/quantization/test_auto_round.py +++ b/tests/quantization/test_auto_round.py @@ -766,6 +766,115 @@ def __init__(self, cfg, moe): assert captured["moe"] is DummyLayer.moe_config +def test_get_moe_method_xpu_keeps_dequant_for_unsupported_config( + monkeypatch, +) -> None: + """On XPU only sym int4 GPTQ has a working quantized MoE path; anything + else must keep the pre-existing bf16 fallback rather than be routed into + MoeWNA16Method, whose N-first layout the oracle's XPU branch corrupts.""" + monkeypatch.setattr(current_platform, "is_xpu", lambda: True) + monkeypatch.setattr(current_platform, "is_cpu", lambda: False) + + class DummyMoeConfig: + pass + + class DummyLayer: + moe_config = DummyMoeConfig() + + class DummyUnquantized: + def __init__(self, moe_config) -> None: + self.moe_config = moe_config + + monkeypatch.setattr( + "vllm.model_executor.layers.fused_moe.UnquantizedFusedMoEMethod", + DummyUnquantized, + ) + + method = INCWna16Scheme().get_moe_method( + make_config(), DummyLayer(), "layer", make_layer_config(bits=8) + ) + + assert isinstance(method, DummyUnquantized) + assert method.moe_config is DummyLayer.moe_config + + +def test_get_moe_method_xpu_keeps_auto_gptq_for_sym_int4(monkeypatch) -> None: + """Sym int4 GPTQ must still reach AutoGPTQMoEMethod, which selects + XPUExpertsWNA16 through the oracle — this is the path the PR enables.""" + monkeypatch.setattr(current_platform, "is_xpu", lambda: True) + monkeypatch.setattr(current_platform, "is_cpu", lambda: False) + + class DummyMoeConfig: + pass + + class DummyLayer: + moe_config = DummyMoeConfig() + + class DummyMethod: + def __init__(self, cfg, moe) -> None: + self.cfg = cfg + + monkeypatch.setattr( + "vllm.model_executor.layers.quantization.utils.marlin_utils.check_marlin_supported", + lambda *args, **kwargs: True, + ) + monkeypatch.setattr( + "vllm.model_executor.layers.quantization.utils.marlin_utils." + "check_moe_marlin_supports_layer", + lambda *args, **kwargs: True, + ) + monkeypatch.setattr( + "vllm.model_executor.layers.quantization.auto_gptq.AutoGPTQMoEMethod", + DummyMethod, + ) + + method = INCWna16Scheme().get_moe_method( + make_config(), DummyLayer(), "layer", make_layer_config() + ) + + assert isinstance(method, DummyMethod) + assert isinstance(method.cfg, AutoGPTQConfig) + + +def test_get_moe_method_xpu_keeps_dequant_when_layer_shape_unsupported( + monkeypatch, +) -> None: + """Sym int4 whose (possibly sharded) layer shape Marlin rejects would fall + through to MoeWNA16Method, so it must keep the bf16 fallback too.""" + monkeypatch.setattr(current_platform, "is_xpu", lambda: True) + monkeypatch.setattr(current_platform, "is_cpu", lambda: False) + + class DummyMoeConfig: + pass + + class DummyLayer: + moe_config = DummyMoeConfig() + + class DummyUnquantized: + def __init__(self, moe_config) -> None: + self.moe_config = moe_config + + monkeypatch.setattr( + "vllm.model_executor.layers.quantization.utils.marlin_utils.check_marlin_supported", + lambda *args, **kwargs: True, + ) + monkeypatch.setattr( + "vllm.model_executor.layers.quantization.utils.marlin_utils." + "check_moe_marlin_supports_layer", + lambda *args, **kwargs: False, + ) + monkeypatch.setattr( + "vllm.model_executor.layers.fused_moe.UnquantizedFusedMoEMethod", + DummyUnquantized, + ) + + method = INCWna16Scheme().get_moe_method( + make_config(), DummyLayer(), "layer", make_layer_config() + ) + + assert isinstance(method, DummyUnquantized) + + def test_resolve_awq_moe_uses_marlin_when_supported(monkeypatch) -> None: captured = {} diff --git a/vllm/model_executor/layers/quantization/inc/schemes/inc_wna16_scheme.py b/vllm/model_executor/layers/quantization/inc/schemes/inc_wna16_scheme.py index 46ad24ea5b47..9dee21f950e7 100644 --- a/vllm/model_executor/layers/quantization/inc/schemes/inc_wna16_scheme.py +++ b/vllm/model_executor/layers/quantization/inc/schemes/inc_wna16_scheme.py @@ -97,8 +97,30 @@ def get_moe_method( layer_config: "INCLayerConfig", ): del config, prefix - # XPU and CPU do not support MoE quantization yet - if current_platform.is_xpu() or current_platform.is_cpu(): + # CPU does not support quantized MoE yet; fall back to dequantized bf16. + # XPU has a quantized MoE path, but only via AutoGPTQMoEMethod, whose + # K-first layout the oracle's XPU branch expects. Any config that would + # instead land on MoeWNA16Method is fed to _process_weights_xpu in + # MoeWNA16's N-first layout, which it transposes and corrupts, so those + # keep the bf16 fallback until that conversion is fixed. + xpu_supported = ( + layer_config.is_gptq and layer_config.bits == 4 and layer_config.sym + ) + if xpu_supported and current_platform.is_xpu(): + # Same checks _resolve_gptq_moe uses to pick AutoGPTQMoEMethod over + # the MoeWNA16Method fallback; e.g. a sharded intermediate size can + # fail these even when the checkpoint itself is supported. + from vllm.model_executor.layers.quantization.utils.marlin_utils import ( + check_marlin_supported, + check_moe_marlin_supports_layer, + ) + + xpu_supported = check_marlin_supported( + scalar_types.uint4b8, layer_config.group_size, has_zp=False + ) and check_moe_marlin_supports_layer(layer, layer_config.group_size) + if current_platform.is_cpu() or ( + current_platform.is_xpu() and not xpu_supported + ): from vllm.model_executor.layers.fused_moe import ( UnquantizedFusedMoEMethod, )