Prhub

#41895 [Bugfix] Fix XPU/ROCm compatibility in spawn_new_process_for_each_test

原始 PR 作者 dzhengAP 合并时间 2026-05-08 12:47 文件变更 1 提交数 4 评论 32 代码增减 +2 / -2

执行摘要

修复 XPU/ROCm 测试 spawn 兼容性

PR #41423 重写 spawn_new_process_for_each_test 时移除了 mp.set_start_method('spawn'),导致 XPU/ROCm 上直接使用 mp.Process 的 worker 默认使用 fork,引发 'Cannot re-initialize XPU in forked subprocess' 错误。此外,test_custom_logitsprocs 使用的 RemoteOpenAIServerCustom fixture 包含不可 pickled 的 AuthenticationString,在 spawn 子进程中无法序列化,需要移除装饰器。

建议阅读此 PR 以了解跨平台测试兼容性问题的典型处理方式。对于更彻底的修复,建议同时参考 PR #42040。

讨论亮点

@chaojun-zhang 指出 @create_new_process_for_each_test() 在 XPU 上与 RemoteOpenAIServerCustom fixture 不兼容,因为 AuthenticationString 不可 pickled。@dzhengAP 确认并移除装饰器。@gemini-code-assist 建议在 child_script 中设置 mp.set_start_method('spawn') 和环境变量,但最终本次 PR 未包含,由后续 #42040 完成。@AndreasKaratzas 发现合并冲突残留,@dzhengAP 修复。

实现拆解

  1. 修改导入:从 from tests.utils import RemoteOpenAIServerCustom, create_new_process_for_each_test 移除 create_new_process_for_each_test,避免未使用导入。
  2. 替换装饰器:将 @create_new_process_for_each_test() 替换为 @pytest.mark.asyncio,使测试函数在事件循环中运行,而不是在 spawn 子进程中执行,从而解决 AuthenticationString 的 pickling 问题。
文件 模块 状态 重要度
tests/v1/logits_processors/test_custom_online.py 测试 modified 3.59

关键源码片段

tests/v1/logits_processors/test_custom_online.py test-coverage

本 PR 唯一修改文件,通过移除 spawn 装饰器解决 XPU/ROCm 兼容性问题,保障测试在非 fork 环境运行。

# tests/v1/logits_processors/test_custom_online.py ( 修改后 )
# 原来导入 : from tests.utils import RemoteOpenAIServerCustom, create_new_process_for_each_test
# 修改后 : 移除 create_new_process_for_each_test,因为 spawn 装饰器与 XPU/ROCm fixture 不兼容
from tests.utils import RemoteOpenAIServerCustom
from tests.v1.logits_processors.utils import entry_points as fake_entry_points
​
# 原装饰器 @create_new_process_for_each_test() 移除,替换为 @pytest.mark.asyncio
# 原因是 RemoteOpenAIServerCustom fixture 包含不可 pickled 的 AuthenticationString,
# spawn 子进程无法序列化它,导致 TypeError。
@pytest.mark.asyncio
@pytest.mark.parametrize('model_name', [MODEL_NAME])
def test_custom_logitsprocs(server, model_name: str):
    '''测试自定义 logits processsor 功能(不再隔离到子进程)'''
    import asyncio
    async def _async_main(srv, mn):
        async with srv.get_async_client() as client:
            await _run(client)
    async def _run(client):
        # ... 请求验证逻辑 ...
        pass
    asyncio.run(_async_main(server, model_name))

评论区精华

Spawn decorator incompatibility with RemoteOpenAIServerCustom 正确性

@chaojun-zhang 指出 @create_new_process_for_each_test() 在 XPU 上与 RemoteOpenAIServerCustom fixture 不兼容,因为 AuthenticationString 不可 pickled。

结论:@dzhengAP 确认问题,并移除装饰器,改用 @pytest.mark.asyncio。 · 已解决

Need for mp start method and env vars in child script 正确性

@gemini-code-assist 建议在 child_script 中显式设置 mp.set_start_method('spawn') 和环境变量 VLLM_WORKER_MULTIPROC_METHOD=spawn 以确保 workers 使用 spawn。

结论:本次 PR 未采纳,后续 PR #42040 提供更完整修复。 · partially resolved

Merge conflict slip through other

@AndreasKaratzas 发现合并冲突标记泄漏到代码中,并表达对 AI 使用质量的担忧。

结论:@dzhengAP 修复并说明是手工 rebase 疏忽。 · 已解决

Pre-existing XPU test failures misinterpreted question

@dzhengAP 分析 CI 失败实际上是预存问题(如 test_qwen35_text_lora 断言 XPU 不支持 LoRA),非本 PR 导致。

结论:@jikunshang 认可,计划另开 PR 禁用这些测试。 · 已解决

风险与影响

主要风险是移除 spawn 装饰器后,该测试不再在隔离子进程中运行,可能漏掉一些子进程特有的错误。但由于原装饰器在 XPU/ROCm 上本身无法工作,修复是必要的。此外,本 PR 仅修改测试文件,风险很低。

影响 XPU 和 ROCm 平台的 CI 测试通过率,使之前因 fork 错误导致的失败变为通过。其他平台无影响。测试覆盖保持稳定。

测试隔离性降低 跨平台兼容性

关联 Issue

#41423 [Bugfix] Fix spawn_new_process_for_each_test silently swallowing test failures

完整报告

参与讨论