Prhub

#46749 [CI][Bugfix] Spawn engine in mm cache sleep test to fix ROCm HIP error

原始 PR 作者 peizhang56 合并时间 2026-06-26 13:38 文件变更 1 提交数 1 评论 0 代码增减 +3 / -0

执行摘要

修复 ROCm 上 mm cache 测试因 fork 继承 HIP 上下文失败

该测试是为回归验证 issue #42995 而添加的,但在 ROCm CI 中失败,报错 torch.AcceleratorError: HIP error: invalid argument。原因是在同一进程中运行多个测试后,父进程持有的 HIP 上下文在 fork 后对子进程无效。PR 描述明确说明“root cause: the test instantiates an LLM, which launches EngineCore via the default VLLM_WORKER_MULTIPROC_METHOD=fork start method... The forked child inherits an invalid HIP context”。

值得合并。这是一个最小修复,精准针对 ROCm HIP 上下文 fork 问题,且已通过测试验证。可作为在 ROCm 测试中处理多进程测试启动方式的参考。

讨论亮点

仅有两条审核评论:claude[bot] 自动评论表示 fork 仓库禁止自动审核;AndreasKaratzas 批准并致谢。无实质性讨论。

实现拆解

变更仅涉及一个测试文件,分两步:

  1. 导入装饰器:在 tests/multimodal/test_cache.py 中添加 from ..utils import create_new_process_for_each_test 导入。
  2. 添加装饰器:在测试函数 test_sleep_wake_preserves_mm_cache_consistency 上添加 @create_new_process_for_each_test() 装饰器。该装饰器在 ROCm/XPU 上默认使用 spawn 启动方式,在 CUDA 上保持 fork,从而隔离 HIP 上下文,避免冲突。
文件 模块 状态 重要度
tests/multimodal/test_cache.py 缓存 modified 3.52

关键源码片段

tests/multimodal/test_cache.py test-coverage

唯一变更文件:修复在 ROCm CI 上因 fork 继承无效 HIP 上下文导致的测试失败。添加了装饰器和导入。

# tests/multimodal/test_cache.py
# 新增导入:使用 create_new_process_for_each_test 将测试隔离到独立进程中
from ..utils import create_new_process_for_each_test# ... 其他导入和辅助函数 ...@create_new_process_for_each_test() # 新增装饰器:在 ROCm/XPU 上 spawn,CUDA 上 fork
@pytest.mark.skipif(
    not torch.cuda.is_available(),
    reason="sleep mode regression requires a CUDA GPU",
)
def test_sleep_wake_preserves_mm_cache_consistency():
    """Regression for vllm-project/vllm#42995."""
    from vllm import LLM, SamplingParams
    from vllm.assets.image import ImageAsset
​
    image = ImageAsset("stop_sign").pil_image
    prompt = {
        "prompt": _SLEEP_VISION_PROMPT,
        "multi_modal_data": {"image": image},
    }
    sampling_params = SamplingParams(temperature=0, max_tokens=8)
​
    llm = LLM(
        model="Qwen/Qwen2-VL-2B-Instruct",
        enable_sleep_mode=True,
        enforce_eager=True,
        gpu_memory_utilization=0.5,
        max_model_len=2048,
    )
​
    llm.generate([prompt], sampling_params)
    llm.sleep(level=1)
    llm.wake_up()
    output2 = llm.generate([prompt], sampling_params)
    assert output2[0].outputs[0].text

评论区精华

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

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

风险与影响

风险极低。变更仅 3 行,且使用已有工具函数 create_new_process_for_each_test,该工具已在 tests/basic_correctness/test_mem.py 中用于类似睡眠测试。NVIDIA CUDA 平台行为不变,因为装饰器在 CUDA 上仍使用 fork。测试结果验证了 186 通过、0 失败。

直接影响 ROCm 平台的 test_sleep_wake_preserves_mm_cache_consistency 测试,使其在 CI 多测试环境下正确运行。对用户无影响,因为仅修改测试代码。团队受益于更稳定的 ROCm CI。

测试变更 平台特定(ROCm)

关联 Issue

#42995 [Bug]: V1 sleep/wake leaves P0 multimodal sender cache desynced from P1 → AssertionError on next image reuse
#44543 [Bugfix] Couple audio+video in mm processor cache for use_audio_in_video (fixes #44538)

完整报告

参与讨论