Prhub

#47406 [Test][XPU] Skip fork in kv_sharing_fast_prefill test on XPU

原始 PR 作者 Liangliang-Ma 合并时间 2026-07-06 11:32 文件变更 1 提交数 5 评论 1 代码增减 +3 / -1

执行摘要

XPU 跳过 fork 测试装饰器

修复 XPU 上 kv_sharing_fast_prefill 测试因 fork 子进程时 XPU 已初始化而失败的问题。PR body 明确提到:'os.fork() in the fork_new_process_for_each_test decorator triggers Cannot re-initialize XPU in forked subprocess. ROCm bypasses the decorator for the same reason; extend the escape hatch to XPU.'

该 PR 是简单的测试兼容性修复,逻辑清晰、风险极低,建议合入。适合作为学习 XPU 测试环境限制的参考。

讨论亮点

所有 review 讨论中仅有一条来自 claude[bot] 的自动评论(提示 fork 的 PR 自动审查已禁用),以及 jikunshang 的直接批准。无人工讨论需要关注。

实现拆解

  1. tests/v1/e2e/general/test_kv_sharing_fast_prefill.py 中修改 use_fork_for_test 的条件判断。
  2. 将原来的 if not current_platform.is_rocm() 扩展为 if not (current_platform.is_rocm() or current_platform.is_xpu())
  3. 这样 XPU 平台会直接传入恒等函数 lambda x: x,跳过 fork_new_process_for_each_test 装饰器,避免 fork 子进程时 XPU 重初始化错误。
  4. 该变更仅影响测试文件,不涉及生产代码。
文件 模块 状态 重要度
tests/v1/e2e/general/test_kv_sharing_fast_prefill.py KV 共享 modified 3.19

关键源码片段

tests/v1/e2e/general/test_kv_sharing_fast_prefill.py test-coverage

唯一变更文件,修改了 fork 跳过条件以支持 XPU 平台。

# tests/v1/e2e/general/test_kv_sharing_fast_prefill.py
# 原条件只跳过 ROCm,现扩展到 XPU
use_fork_for_test = (
    fork_new_process_for_each_test
    if not (
        current_platform.is_rocm() or current_platform.is_xpu()
    ) # 跳过 fork:XPU 和 ROCm 都不允许在初始化后 fork
    else lambda x: x
)

评论区精华

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

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

风险与影响

变更仅涉及测试条件判断,风险极低。唯一潜在风险是如果未来 XPU 平台支持 fork 子进程,此跳过条件可能导致测试覆盖不足;但短期内 XPU 不支持 fork 是已知限制,且已有明确的 conftest.py 初始化顺序依赖,此修改与 ROCm 策略一致。

影响范围极小:仅对 XPU 平台上的 test_kv_sharing_fast_prefill 测试生效。修复后该测试在 XPU 上可从 'Cannot re-initialize XPU in forked subprocess' 错误恢复为正常运行(跳过 fork 装饰器)。对非 XPU 平台无影响,对生产代码无影响。

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论