# PR #41895 完整报告

- 仓库：`vllm-project/vllm`
- 标题：[Bugfix] Fix XPU/ROCm compatibility in spawn_new_process_for_each_test
- 合并时间：2026-05-08 12:47
- 原文链接：http://prhub.com.cn/vllm-project/vllm/pull/41895

---

# 执行摘要

- 一句话：修复 XPU/ROCm 测试 spawn 兼容性
- 推荐动作：建议阅读此 PR 以了解跨平台测试兼容性问题的典型处理方式。对于更彻底的修复，建议同时参考 PR #42040。

# 功能与动机

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 子进程中无法序列化，需要移除装饰器。

# 实现拆解

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`（模块 测试；类别 test；类型 test-coverage）: 本 PR 唯一修改文件，通过移除 spawn 装饰器解决 XPU/ROCm 兼容性问题，保障测试在非 fork 环境运行。

关键符号：未识别

## 关键源码片段

### `tests/v1/logits_processors/test_custom_online.py`

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

```python
# 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))

```

# 评论区精华

@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 修复。

- Spawn decorator incompatibility with RemoteOpenAIServerCustom (correctness): @dzhengAP 确认问题，并移除装饰器，改用 @pytest.mark.asyncio。
- Need for mp start method and env vars in child script (correctness): 本次 PR 未采纳，后续 PR #42040 提供更完整修复。
- Merge conflict slip through (other): @dzhengAP 修复并说明是手工 rebase 疏忽。
- Pre-existing XPU test failures misinterpreted (question): @jikunshang 认可，计划另开 PR 禁用这些测试。

# 风险与影响

- 风险：主要风险是移除 spawn 装饰器后，该测试不再在隔离子进程中运行，可能漏掉一些子进程特有的错误。但由于原装饰器在 XPU/ROCm 上本身无法工作，修复是必要的。此外，本 PR 仅修改测试文件，风险很低。
- 影响：影响 XPU 和 ROCm 平台的 CI 测试通过率，使之前因 fork 错误导致的失败变为通过。其他平台无影响。测试覆盖保持稳定。
- 风险标记：测试隔离性降低 , 跨平台兼容性

# 关联脉络

- PR #41423 Fix spawn_new_process_for_each_test silently swallowing test failures: 本 PR 是其后续修复，恢复其对 XPU/ROCm 的影响。
- PR #42040 Fix LOGITPROC_SOURCE_ENTRYPOINT fork compatibility on XPU/ROCm: 更彻底的修复，涉及 entrypoint 的兼容性，引用自本 PR 讨论。