Prhub

#44513 [XPU] Add online fp8 quantization test

原始 PR 作者 yma11 合并时间 2026-07-28 10:34 文件变更 5 提交数 2 评论 12 代码增减 +28 / -7

执行摘要

XPU 启用在线 FP8 量化测试

vLLM 通过 PR #38318 和 #40152 引入了新的在线 FP8 量化前端,支持 fp8_per_tensor、fp8_per_block 和 mxfp8 等配置。XPU 平台已验证全部支持,但缺乏对应的测试覆盖。为了在 CI 中验证 XPU 上在线量化的正确性,本 PR 添加了相关测试。

本 PR 作为 XPU 平台启用测试覆盖的参考样例,值得其他平台(如 CPU)借鉴其 is_quant_method_supported 的扩展模式。审查时重点关注 supported_quantization 列表的维护成本和测试跳过的条件是否清晰。

讨论亮点
  • 量化方法支持范围:jikunshang 质疑列表中所有方法是否均受支持,yma11 回应“部分支持但至少 modelopt 已有 CI 覆盖”,最终未进一步精简列表,保持现有声明。
  • 跳过 fp8_per_block 测试:jikunshang 认为 XPU BMG 上无需测试 per block,zufangzhu 表示同意,最终在 test 中跳过该配置。
  • CPU 兼容性:原始修改会移除 is_quant_method_supported 中对 CPU 的排除,jikunshang 指出会 break CPU,后调整为明确对 CPU 返回 False。

实现拆解

  1. 声明 XPU 支持的量化方法:在 vllm/platforms/xpu.pyXPUPlatform 类中添加 supported_quantization 静态列表,列举 XPU 当前支持的全部量化方法(含 online、fp8_per_tensor、fp8_per_block 等),为后续平台过滤提供依据。
  2. 调整测试辅助函数:在 tests/quantization/utils.pyis_quant_method_supported 中,将原本仅允许 CUDA/ROCm 的逻辑改为:若为 CPU 则直接返回 False;否则先调用 verify_quantization 验证方法是否被平台支持;若为 XPU 则直接返回 True(无需检查 compute capability),其余平台保持原有 capability 检查。
  3. 适配在线量化测试用例:在 tests/quantization/test_online.pytest_online_quantization 中,添加对 XPU 平台的特殊处理:若当前为 XPU 且量化方案为 fp8_per_block 则跳过该测试(因 BMG 硬件不支持);同时将权重 dtype 断言中的 current_platform.is_cuda() 扩展为 is_cuda() or is_xpu(),确保 XPU 也默认使用 float8_e4m3fn
  4. 排除 XPU 不兼容的模型:在 tests/models/multimodal/processing/test_common.py_XPU_EXCLUDED_MODEL_IDS 中添加 thinkingmachines/Inkling-NVFP4,避免该 NVFP4 量化模型在 XPU 上运行测试。
  5. 配置 CI 执行:在 .buildkite/intel_jobs/test-intel.yaml 中,将 quantization/test_online.py 加入 Intel CI 测试执行命令,使其作为自动化测试的一部分运行。
文件 模块 状态 重要度
vllm/platforms/xpu.py 平台层 modified 5.82
tests/quantization/utils.py 量化工具 modified 4.33
tests/quantization/test_online.py 在线量化测试 modified 4.1
tests/models/multimodal/processing/test_common.py 多模态测试 modified 3.53
.buildkite/intel_jobs/test-intel.yaml CI 配置 modified 3.24

关键符号

is_quant_method_supported test_online_quantization

关键源码片段

tests/quantization/utils.py test-coverage

修改 is_quant_method_supported 函数以允许 XPU 平台通过

def is_quant_method_supported(quant_method: str) -> bool:
    # 目前量化测试只运行在 GPU(非 CPU)
    if current_platform.is_cpu():
        return False
    try:
        current_platform.verify_quantization(quant_method)
    except ValueError:
        return False
    # XPU 平台无需检查 compute capability
    if current_platform.is_xpu():
        return True
    # NVIDIA/AMD 需检查 capability
    capability = current_platform.get_device_capability()
    assert capability is not None
    min_capability = get_quantization_config(quant_method).get_min_capability()
    return capability.to_int() >= min_capability
tests/quantization/test_online.py test-coverage

对 XPU 跳过 fp8_per_block,并扩展权重 dtype 断言

# 在 test_online_quantization 函数开头添加
if current_platform.is_xpu() and quant_scheme == "fp8_per_block":
    pytest.skip("Skip test for online fp8_per_block on XPU platform.")# 权重 dtype 断言处修改
if current_platform.is_cuda() or current_platform.is_xpu():
    assert o_proj.weight.dtype == torch.float8_e4m3fn
elif current_platform.is_rocm():
    assert o_proj.weight.dtype == current_platform.fp8_dtype()
else:
    pytest.skip("Only runs on CUDA and ROCm.")

评论区精华

量化方法支持范围确认 设计

jikunshang 询问是否真的支持所有列出的量化方法,yma11 回复部分支持但至少 modelopt 有 CI 覆盖

结论:未进一步精简列表,接受当前定义 · 已解决

跳过 fp8_per_block 测试 性能

jikunshang 认为 BMG 上不需要测试 per block,zufangzhu 同意不测试

结论:跳过 XPU 下 fp8_per_block 的测试 · 已解决

CPU 平台兼容性 正确性

jikunshang 指出原始修改会 break CPU,后调整为明确排除 CPU

结论:is_quant_method_supported 增加 CPU 返回 False 的逻辑 · 已解决

风险与影响

  • 量化方法列表完整性supported_quantization 列表仅凭经验声明,未逐项验证,可能导致后续测试绕过或误判。
  • 测试跳过导致覆盖缺口:XPU 跳过 fp8_per_block 测试,若未来硬件或内核支持该模式,该跳过逻辑可能未及时更新,造成回归漏检。
  • 权重 dtype 假设:XPU 下断言权重 dtype 为 float8_e4m3fn,但不同 XPU 设备可能支持其他 fp8 表示,此假设不够泛化。

对于 XPU 用户,CI 将自动运行在线量化测试,提升平台稳定性;对于维护者,需在新增量化方法时同步更新 supported_quantization 列表;对 CUDA/ROCm 平台无影响,测试行为保持不变。

测试跳过部分配置 量化方法列表可能不完整 权重 dtype 假设不泛化

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论