Prhub

#46260 [ROCm][Test] Fix stale test_gfx950_moe MXFP4 oracle tests

原始 PR 作者 spandantiwari 合并时间 2026-06-23 23:07 文件变更 1 提交数 2 评论 1 代码增减 +23 / -8

执行摘要

修复 gfx950 MXFP4 MoE 测试失效

PR body 指出 gfx950 MXFP4 MoE oracle 测试因产品 API 演进发生三次独立破坏,测试已无法运行。目的是恢复这些测试,确保它们能够正确验证 MXFP4 后端分发行为。

建议审核并通过。该 PR 是纯测试修复,无产品风险,应尽快合并以恢复 gfx950 CI 测试覆盖。值得学习的设计点包括:使用 unittest.mock.patch 桩化全局配置 fixture 的方法,以及测试与产品 API 同步维护的重要性。

讨论亮点

仅有审核人 tjtanaa 的批准评论 "LGTM. Let's check AMD CI",表示认可并计划运行 CI。无其他讨论或未解决疑虑。

实现拆解

  1. 修复 FusedMoEConfig 参数:在 _make_w4a4_moe_config 中将 intermediate_size_per_partition=256 改为 intermediate_size=256,因为该字段已成为必填项,而 intermediate_size_per_partition__post_init__ 中派生。
  2. 添加 vLLM config 桩 fixture:新增 mxfp4_oracle_config fixture,使用 unittest.mock.patch 模拟 get_current_vllm_config 返回 model_config.quantization_config=None,避免因缺少真实配置上下文导致的 AssertionError/AttributeError
  3. 更新回退行为断言:将原 test_w4a4_raises_without_aiter_and_no_moe_backend 重命名为 test_w4a4_falls_back_to_triton_unfused_without_aiter,断言期望从 NotImplementedError 改为 Mxfp4MoeBackend.TRITON_UNFUSED,以匹配 #45896 引入的变化。
  4. 为所有需要配置上下文的测试注入 fixture:除回退测试外,test_w4a4_dispatches_to_aitertest_w4a4_dispatches_to_emulation_with_moe_backend 也添加了 mxfp4_oracle_config 参数。此外,测试执行结果确认:AITER 关闭时 2 通过 1 跳过,AITER 开启时 2 通过 1 跳过。
文件 模块 状态 重要度
tests/quantization/test_gfx950_moe.py 测试 modified 7.1

关键符号

mxfp4_oracle_config test_w4a4_dispatches_to_aiter test_w4a4_raises_without_aiter_and_no_moe_backend test_w4a4_falls_back_to_triton_unfused_without_aiter test_w4a4_dispatches_to_emulation_with_moe_backend _make_w4a4_moe_config

关键源码片段

tests/quantization/test_gfx950_moe.py test-coverage

唯一变更文件,修复了所有因产品 API 变化导致的测试失效

from unittest.mock import patch@pytest.fixture
def mxfp4_oracle_config():
    """Stub the config the oracle reads (``model_config.quantization_config``)
    so backend dispatch resolves without a real model / user override."""
    # 模拟 get_current_vllm_config 返回 quantization_config = None
    # 避免 select_mxfp4_moe_backend 因缺少真实配置而报错
    with patch(
        "vllm.model_executor.layers.fused_moe.oracle.mxfp4.get_current_vllm_config"
    ) as mock_get_config:
        mock_get_config.return_value.model_config.quantization_config = None
        yield
​
​
def _make_w4a4_moe_config(moe_backend: str = "auto") -> FusedMoEConfig:
    from vllm.model_executor.layers.fused_moe.activation import MoEActivation
    # 现在使用必填的 intermediate_size 代替已移除的 intermediate_size_per_partition
    return FusedMoEConfig(
        num_experts=8,
        experts_per_token=2,
        hidden_dim=256,
        intermediate_size=256, # 必填字段,intermediate_size_per_partition 由 __post_init__ 派生
        num_local_experts=8,
        num_logical_experts=8,
        moe_parallel_config=FusedMoEParallelConfig.make_no_parallel(),
        activation=MoEActivation.SILU,
        in_dtype=torch.bfloat16,
        device="cuda",
        routing_method=RoutingMethodType.Renormalize,
        moe_backend=moe_backend,
    )
​
​
# 测试用例均使用 mxfp4_oracle_config fixture
@pytest.mark.skipif(not ROCM_GFX950, reason="Requires GFX950 (mi355x)")
@pytest.mark.skipif(not ROCM_AITER_AVAILABLE, reason="Requires AITER enabled")
def test_w4a4_dispatches_to_aiter(mxfp4_oracle_config):
    # 省略实现,仅展示 fixture 注入方式
    pass
​
​
@pytest.mark.skipif(not ROCM_GFX950, reason="Requires GFX950 (mi355x)")
@pytest.mark.skipif(ROCM_AITER_AVAILABLE, reason="Test requires AITER disabled")
def test_w4a4_falls_back_to_triton_unfused_without_aiter(mxfp4_oracle_config):
    # 无 AITER 时,预期回退到 TRITON_UNFUSED 而非抛异常
    config = _make_w4a4_moe_config()
    backend, experts_cls = select_mxfp4_moe_backend(
        config, activation_key=kMxfp4Dynamic
    )
    assert backend == Mxfp4MoeBackend.TRITON_UNFUSED
    assert experts_cls is not None

评论区精华

没有提炼出高价值讨论线程

当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。

风险与影响

该 PR 仅修改测试文件,不涉及产品代码,回归风险极低。修复后的测试在 MI355 硬件上通过,但可能存在对其他 ROCm 平台(如 gfx942)的兼容性风险:新增的 mxfp4_oracle_config fixture 未作平台跳过,若在其他平台上运行,可能因缺少 on_gfx950 等条件而失败(但测试本身已通过 pytest.mark.skipif 跳过)。此外,patch 桩化了全局配置,如果未来 get_current_vllm_config 行为变化,测试可能再次失效。

影响范围仅限于单个测试文件 tests/quantization/test_gfx950_moe.py,属于对 gfx950 硬件的 MXFP4 MoE 测试修复。恢复了三个关键测试的正确性和可执行性,确保它们能随产品 API 变化持续运行。对用户无感知,对团队的意义是保证 CI 中 gfx950 相关测试的可靠性,防止测试无声跳过或失败。

测试独占变更,无产品风险

关联 Issue

#41566 [Quantization] Rework quantization_config to use QuantKey and allow for activation override

完整报告

参与讨论