Prhub

#56670 [XPU][CI] fix jit_warmup_triton_launcher

原始 PR 作者 zhenwei-intel 合并时间 2026-09-13 21:44 文件变更 1 提交数 1 评论 2 代码增减 +5 / -3

执行摘要

jit 预热测试改用 current_platform 设备类型,适配 XPU CI

PR body 明确说明目的:“Make the test platform-agnostic: assert against current_platform.device_type instead of hardcoding CUDA”。没有关联 Issue。原测试通过 first.is_cuda 和结果断言中的 "cuda" 硬编码 CUDA 设备,而 vLLM 平台抽象在 XPU 上生成的 fake tensor 的 device.type 为 "xpu",导致该测试在 XPU CI 失败,需要改为跟随当前运行平台。

值得快速浏览。该 PR 展示了如何用 vLLM 的 current_platform 抽象消除测试中的硬件平台硬编码,对负责 XPU / 多平台 CI 的工程师有直接参考价值;阅读重点是测试重命名与断言替换的对应关系,生产代码无需关注。

讨论亮点

claude[bot] 指出该 PR 来自 fork,自动审查被禁用,维护者可评论 @claude review 触发单次审查;维护者 jikunshang 直接批准(APPROVED),并通过 /ci run 触发 Buildkite CI #88626。整体没有实质技术争论,属于修改很小、意图明确的维护者直接合并路径。

实现拆解

  1. 新增平台抽象导入:文件头部加入 from vllm.platforms import current_platform,通过 vLLM 统一的平台入口获取当前设备类型。
  2. 重命名测试函数:将 test_triton_kernel_dispatch_uses_cuda_fake_tensors 重命名为 test_triton_kernel_dispatch_uses_device_fake_tensors,并在函数体开头捕获 device_type = current_platform.device_type 作为断言基准。
  3. 替换两处硬编码断言:dispatch 内的 assert first.is_cuda 改为 assert first.device.type == device_type;最终校验 warmup key 中 fake tensor 设备的断言从 "cuda" 改为 device_type,保证校验与运行平台一致。
  4. 配套情况:无配置、schema、部署或文档变更;单个 commit 完成,测试覆盖范围不变,仅提升可移植性,对 CUDA 等原有平台行为无影响。
文件 模块 状态 重要度
tests/model_executor/test_jit_warmup_triton_launcher.py 预热模块 modified 4.96

关键符号

test_triton_kernel_dispatch_uses_device_fake_tensors

关键源码片段

tests/model_executor/test_jit_warmup_triton_launcher.py test-coverage

唯一变更文件。修复测试中硬编码 CUDA 的断言,使 jit warmup / Triton 内核分发测试能在 XPU 等非 CUDA 平台运行,是本次 CI 修复的核心。

# 平台抽象入口:在 CUDA、XPU、ROCm 等平台返回各自的 device_type
from vllm.platforms import current_platform
​
def test_triton_kernel_dispatch_uses_device_fake_tensors(
    monkeypatch: pytest.MonkeyPatch,
) -> None:
    kernel = _FakeTritonKernel()
    # 以当前平台设备类型作为断言基准,替代原来写死的 cuda
    device_type = current_platform.device_type
​
    def warmup_inputs() -> dict[str, Any]:
        return dict(
            first=TritonWarmupTensor(torch.float32, shape=(2, 3)),
            second=1,
        )
​
    @triton_kernel_dispatcher_with_warmup(
        kernel=kernel, warmup_inputs=warmup_inputs)
    def dispatch(first: torch.Tensor, second: int) -> LaunchSpec:
        assert isinstance(first, torch.Tensor)
        # 原实现使用 first.is_cuda,在 XPU 上会误判为 False;
        # 改为与 current_platform.device_type 比较,行为平台无关
        assert first.device.type == device_type
        assert first[0].is_contiguous()
        return (first.shape[0],), dict(CONST=first[0].numel())
​
    # _patch_key_deriver 是本文件内的 monkeypatch 辅助函数,
    # 用于替换 TritonJitKey 派生逻辑,避免真实编译
    _patch_key_deriver(
        monkeypatch,
        lambda kernel, kwargs: {
            TritonJitKey(id(kernel), "fake", 0, kwargs["CONST"])},
    )
​
    keys = dispatch.get_warmup_keys()
    assert len(keys) == 1
    # 校验 warmup key 中携带的 fake tensor 设备类型与当前平台一致
    assert dict(keys[0].inputs)["first"].device.type == device_type

评论区精华

Fork PR 自动审查与维护者批准 other

claude[bot] 称来自 fork 的 PR 自动审查被禁用,可评论 @claude review 触发单次审查;随后 jikunshang 直接批准并触发 /ci run。

结论:无实质技术争议,维护者批准并合并,CI 已触发。 · 已解决

风险与影响

变更仅限测试文件 tests/model_executor/test_jit_warmup_triton_launcher.py,不进入任何生产路径,回归风险极低。需要留意的是测试现在依赖 current_platform.device_type 的动态值:若某个平台的 device_type 返回异常,断言可能误判,但失败信息直接指向该测试,容易定位;此外 dispatch 中 first[0].is_contiguous() 对 fake tensor 的行为在各平台保持一致,未发现兼容性隐患。

对用户无影响(无服务端代码改动);对 CI 有直接正面影响,XPU 流水线不再因该测试的平台假设失败;对团队而言,这是 vLLM 将 XPU 视为一等平台的配套工作,与 current_platform 抽象在 CPU、ROCm 等平台的使用方式一致,可作为后续平台无关测试的参考写法。

仅测试文件变更 平台断言依赖 current_platform

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论