From 5893426b88f7b3cd21101d194eb1c6f0a6f0e27b Mon Sep 17 00:00:00 2001 From: Gabriel Wu <13583761+lucifer1004@users.noreply.github.com> Date: Mon, 7 Sep 2026 15:19:13 +0800 Subject: [PATCH] [Bugfix] DSv4 MXFP4 selector: stop narrowing explicit aliases to their BF16 variant (#53586) Signed-off-by: Zihua Wu Signed-off-by: Zihua Wu <13583761+lucifer1004@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Jee Jee Li Co-authored-by: Yongye Zhu --- tests/kernels/moe/test_b12x.py | 29 +++++++++++++++++++ .../layers/fused_moe/oracle/mxfp4.py | 8 ++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/kernels/moe/test_b12x.py b/tests/kernels/moe/test_b12x.py index fa1dd4410d..d0b1ce7cae 100644 --- a/tests/kernels/moe/test_b12x.py +++ b/tests/kernels/moe/test_b12x.py @@ -464,6 +464,35 @@ def test_deepseek_v4_b12x_activation_selection( assert experts_cls is B12xExperts +def test_deepseek_v4_flashinfer_cutlass_falls_through_to_w4a8( + monkeypatch: pytest.MonkeyPatch, +) -> None: + """Explicit flashinfer_cutlass must try the W4A8 variant when the BF16 + variant is unsupported (the BF16 variant is gated to SM90).""" + from vllm.model_executor.layers.fused_moe.experts.flashinfer_cutlass_moe import ( + FlashInferExperts, + ) + + monkeypatch.setattr(FlashInferExperts, "_supports_current_device", lambda: True) + + def sm120_quant_gate(weight_key, activation_key): + return (weight_key, activation_key) == ( + mxfp4_oracle.kMxfp4Static, + mxfp4_oracle.kMxfp8Dynamic, + ) + + monkeypatch.setattr( + FlashInferExperts, "_supports_quant_scheme", staticmethod(sm120_quant_gate) + ) + config = make_dummy_moe_config(hidden_dim=256, intermediate_size=64) + config.moe_backend = "flashinfer_cutlass" + + backend, experts_cls = select_deepseek_v4_mxfp4_moe_backend(config) + + assert backend == Mxfp4MoeBackend.FLASHINFER_CUTLASS_MXFP4_MXFP8 + assert experts_cls is FlashInferExperts + + def test_compressed_tensors_mxfp4_preserves_checkpoint_packing( monkeypatch: pytest.MonkeyPatch, ) -> None: diff --git a/vllm/model_executor/layers/fused_moe/oracle/mxfp4.py b/vllm/model_executor/layers/fused_moe/oracle/mxfp4.py index 77083c67ea..1fa2f63e5d 100644 --- a/vllm/model_executor/layers/fused_moe/oracle/mxfp4.py +++ b/vllm/model_executor/layers/fused_moe/oracle/mxfp4.py @@ -670,7 +670,13 @@ def select_deepseek_v4_mxfp4_moe_backend( # falling back to the auto priority list. runner_backend = config.moe_backend if runner_backend != "auto": - requested_backends = _get_requested_backends(runner_backend, None) + if runner_backend == "b12x": + requested_backends = _get_requested_backends(runner_backend, None) + else: + # Try every variant of the alias in priority order. Narrowing to + # the BF16 variant would drop SM100+ W4A8 variants on devices where + # the BF16 variant is gated to SM90. + requested_backends = map_mxfp4_backend(runner_backend) if activation_format == mk.FusedMoEActivationFormat.BatchedExperts: requested_backends = [ Mxfp4MoeBackend.BATCHED_MARLIN if b == Mxfp4MoeBackend.MARLIN else b