From 27b4a9297bbc7a07f51fbfd38f066d50762da13f Mon Sep 17 00:00:00 2001 From: gurwinderintel Date: Mon, 13 Jul 2026 21:17:12 -0700 Subject: [PATCH 1/2] [XPU] Route INC WNA16 MoE to oracle backend instead of bf16 dequant INCWna16Scheme.get_moe_method returned UnquantizedFusedMoEMethod for XPU, materializing every expert as full bf16. On a 24GB card an int4 AutoRound MoE (e.g. Qwen3-30B-A3B) OOMs at load. XPU already has a working quantized MoE path (the WNA16 oracle -> XPUExpertsWNA16, added in #41426), reached via _resolve_gptq_moe -> MoeWNA16Method, so the dequant fallback is both wasteful and broken on memory-constrained cards. - Drop XPU from the dequant early-return (keep CPU, which lacks a quantized MoE path) so sym-int4 GPTQ/AutoRound flows to _resolve_gptq_moe. - Gate use_marlin off for XPU in _resolve_gptq_moe: check_moe_marlin_supports_layer is platform-agnostic, but Marlin is CUDA-only (torch.ops._C), so XPU must take the MoeWNA16Method path, not AutoGPTQMoEMethod. Verified on Arc Pro B60 with Intel/Qwen3-30B-A3B-Instruct-2507-int4-AutoRound: - Before: OOM at load ('not enough GPU memory', UnquantizedFusedMoEMethod). - After: loads and generates correctly via the XPU WNA16 backend. Fixes #47937. Signed-off-by: gurwinderintel --- .../quantization/inc/schemes/inc_wna16_scheme.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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..3d7f4db212d4 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,11 @@ 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 is supported via the WNA16 oracle backend (routes through + # _resolve_gptq_moe -> MoeWNA16Method -> XPUExpertsWNA16), so it must + # NOT take this dequant fallback, which OOMs materializing bf16 experts. + if current_platform.is_cpu(): from vllm.model_executor.layers.fused_moe import ( UnquantizedFusedMoEMethod, ) @@ -128,7 +131,12 @@ def _resolve_gptq_moe(layer: "torch.nn.Module", layer_config: "INCLayerConfig"): (4, True): scalar_types.uint4b8, (8, True): scalar_types.uint8b128, } - use_marlin = (layer_config.bits, layer_config.sym) in gptq_type_map + # Marlin is a CUDA-only path; XPU uses the WNA16 oracle backend instead + # (check_moe_marlin_supports_layer is platform-agnostic, so gate it here). + use_marlin = ( + layer_config.bits, + layer_config.sym, + ) in gptq_type_map and not current_platform.is_xpu() if use_marlin: use_marlin = check_marlin_supported( gptq_type_map[(layer_config.bits, layer_config.sym)], From 014bdcbaad2545ad2c98bdaa8a0b965697f55c63 Mon Sep 17 00:00:00 2001 From: sgurwinderr Date: Wed, 29 Jul 2026 04:20:26 +0000 Subject: [PATCH 2/2] [XPU] Drop the Marlin XPU gate, guard the MoeWNA16 fallback instead The XPU gate added to _resolve_gptq_moe was unnecessary: AutoGPTQMoEMethod never dispatches to Marlin on XPU, since select_wna16_moe_backend's _get_priority_backends() returns [WNA16MoEBackend.XPU] and MarlinExperts._supports_current_device() requires CUDA. The gate also broke test_resolve_gptq_moe_uses_auto_gptq_when_supported, which patches both Marlin checks but not is_xpu. Revert it; _resolve_gptq_moe is now identical to main. Removing the blanket bf16 dequant in get_moe_method makes the MoeWNA16Method route newly reachable on XPU, which is broken: the oracle's XPU branch feeds weights to _process_weights_xpu, whose documented contract is AutoGPTQ's K-first int32 layout, while MoeWNA16Method registers N-first uint8. Pre-check the same conditions _resolve_gptq_moe uses to select AutoGPTQMoEMethod and keep the bf16 fallback otherwise, so only the working route is taken. This is load-bearing at TP>=4 for the target model, where a sharded intermediate size of 192 is not a multiple of the group size. Add tests for get_moe_method, which had no coverage. Signed-off-by: sgurwinderr --- tests/quantization/test_auto_round.py | 109 ++++++++++++++++++ .../inc/schemes/inc_wna16_scheme.py | 34 ++++-- 2 files changed, 133 insertions(+), 10 deletions(-) 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 3d7f4db212d4..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 @@ -98,10 +98,29 @@ def get_moe_method( ): del config, prefix # CPU does not support quantized MoE yet; fall back to dequantized bf16. - # XPU is supported via the WNA16 oracle backend (routes through - # _resolve_gptq_moe -> MoeWNA16Method -> XPUExpertsWNA16), so it must - # NOT take this dequant fallback, which OOMs materializing bf16 experts. - if current_platform.is_cpu(): + # 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, ) @@ -131,12 +150,7 @@ def _resolve_gptq_moe(layer: "torch.nn.Module", layer_config: "INCLayerConfig"): (4, True): scalar_types.uint4b8, (8, True): scalar_types.uint8b128, } - # Marlin is a CUDA-only path; XPU uses the WNA16 oracle backend instead - # (check_moe_marlin_supports_layer is platform-agnostic, so gate it here). - use_marlin = ( - layer_config.bits, - layer_config.sym, - ) in gptq_type_map and not current_platform.is_xpu() + use_marlin = (layer_config.bits, layer_config.sym) in gptq_type_map if use_marlin: use_marlin = check_marlin_supported( gptq_type_map[(layer_config.bits, layer_config.sym)],