Prhub

#44819 [CI] Consolidate multimodal entrypoint tests.

原始 PR 作者 noooop 合并时间 2026-06-08 19:48 文件变更 24 提交数 12 评论 7 代码增减 +107 / -62

执行摘要

合并多模态入口测试文件并统一资源管理

PR 描述指出合并多模态入口测试的动机:"These tests have more in common. Reduce the number of files in the tests/entrypoints/openai/chat_completion folder. These all make the entrypoint tests easy to maintain." 同时,review 评论进一步确认多模态输入必须使用 chat 请求,因此测试函数名需要修正。

值得快速阅读。该 PR 展示了测试目录布局规范化的实践:通过 conftest.py 共享常量和按功能域组织测试文件,对后续多模态测试扩展具有参考价值。但由于无核心逻辑变动,不强制深度审查。

讨论亮点
  • 目录布局建议:审核者 DarkLight1337 建议镜像 tests/entrypoints 目录结构(即在 multimodal 下使用 openai/chat_completion 而非 online),作者 noooop 采纳并调整。
  • 测试函数名修正:作者 noooop 指出原文件 test_completion_with_image_embeds.py 应更名为 test_chat_completions_with_image_embeds,因为多模态输入必须使用 Chat Completion API。DarkLight1337 最初因文件截断产生误解,讨论后确认正确并批准。

实现拆解

  1. 创建共享资源层:新建 tests/entrypoints/multimodal/conftest.py,定义 TEST_IMAGE_ASSETS 常量列表(包含四种不同格式和色彩的测试图片),供所有多模态测试文件统一引用,消除跨文件重复定义。
  2. 迁移 LLM 多模态测试:从 tests/entrypoints/llm/test_chat.py 中移除 vision_llm fixture 和 test_chat_multi_image 函数(删除 42 行),并在 tests/entrypoints/multimodal/llm/test_chat.py 中重新创建(新增 50 行),将 import 由旧的 tests.entrypoints.openai.chat_completion.test_vision 改为新的 tests.entrypoints.multimodal.conftest
  3. 重组 OpenAI Chat Completion 测试:将原 tests/entrypoints/openai/chat_completion/test_completion_with_image_embeds.py 重命名为 tests/entrypoints/multimodal/openai/chat_completion/test_chat_completion_with_image_embeds.py,并将测试函数名从 test_completions_with_image_embeds 改为 test_chat_completions_with_image_embeds;将 test_vision.py 重命名并移除本地 TEST_IMAGE_ASSETS 定义,改为从 conftest 导入。
  4. 重组 Responses 测试:将 tests/entrypoints/openai/responses/test_image.py 重命名至 tests/entrypoints/multimodal/openai/responses/test_image.py,移除重复资源定义并改为从 conftest 导入。
  5. 补充包初始化文件:在新增目录中添加空的 __init__.py 文件。
  6. 更新 CI 配置:修改 .buildkite/test-amd.yaml(+29 行)和 .buildkite/test_areas/entrypoints.yaml(+13 行),将旧路径替换为新路径。
文件 模块 状态 重要度
tests/entrypoints/multimodal/llm/test_chat.py LLM 测试 added 6.07
tests/entrypoints/llm/test_chat.py LLM 测试 modified 5.37
tests/entrypoints/multimodal/conftest.py 测试共享层 added 4.51
tests/entrypoints/multimodal/openai/chat_completion/test_chat_completion_with_image_embeds.py Chat 测试 renamed 5.08
tests/entrypoints/multimodal/openai/chat_completion/test_vision.py 视觉测试 renamed 4.25
tests/entrypoints/multimodal/openai/responses/test_image.py 响应测试 renamed 4.21
.buildkite/test-amd.yaml CI 配置 modified 3.88
.buildkite/test_areas/entrypoints.yaml CI 配置 modified 3.63

关键符号

vision_llm test_chat_multi_image test_chat_completions_with_image_embeds

关键源码片段

tests/entrypoints/multimodal/llm/test_chat.py test-coverage

新增文件,将多图片聊天测试从纯文本测试文件中分离,并复用共享资源常量,体现测试组织重构的核心目标。

# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import weakrefimport pytestfrom tests.entrypoints.multimodal.conftest import TEST_IMAGE_ASSETS
from vllm import LLM
from vllm.distributed import cleanup_dist_env_and_memory
​
​
@pytest.fixture(scope="function")
def vision_llm():
    # pytest caches the fixture so we use weakref.proxy to
    # enable garbage collection
    llm = LLM(
        model="microsoft/Phi-3.5-vision-instruct",
        max_model_len=4096,
        max_num_seqs=5,
        enforce_eager=True,
        trust_remote_code=True,
        limit_mm_per_prompt={"image": 2},
        seed=0,
    )
​
    yield weakref.proxy(llm)
​
    del llm
​
    cleanup_dist_env_and_memory()
​
​
@pytest.mark.parametrize(
    "image_urls", [[TEST_IMAGE_ASSETS[0], TEST_IMAGE_ASSETS[1]]], indirect=True
)
def test_chat_multi_image(vision_llm, image_urls: list[str]):
    messages = [
        {
            "role": "user",
            "content": [
                *(
                    {"type": "image_url", "image_url": {"url": image_url}}
                    for image_url in image_urls
                ),
                {"type": "text", "text": "What's in this image?"},
            ],
        }
    ]
    outputs = vision_llm.chat(messages)
    assert len(outputs) >= 0
tests/entrypoints/multimodal/conftest.py test-coverage

新增的共享配置文件,集中定义了多模态测试所需的图片资源常量,避免了在多个测试文件中重复定义,降低了维护成本。

# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project# 多模态测试公用图片资源常量,覆盖不同图片格式(JPG/PNG)和色彩模式(灰度 /RGB/RGBA)
# 所有多模态测试文件通过以下语句导入:
# from tests.entrypoints.multimodal.conftest import TEST_IMAGE_ASSETS
TEST_IMAGE_ASSETS = [
    "2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", # 典型自然风景 JPG
    "Grayscale_8bits_palette_sample_image.png", # 8 位灰度 PNG
    "1280px-Venn_diagram_rgb.svg.png", # RGB 彩色 PNG
    "RGBA_comp.png", # 带有 Alpha 通道的 PNG
]

评论区精华

测试目录结构布局建议 设计

审核者 DarkLight1337 建议镜像 tests/entrypoints 目录结构,即在 multimodal 下直接使用 openai/chat_completion 等子目录,而不是使用自定义的 online 等名称。

结论:作者 noooop 采纳了建议,调整了目录结构,采用了与 tests/entrypoints 一致的布局。 · 已解决

测试函数名更正:Chat API vs Completions API 正确性

作者 noooop 在评论中指出原测试文件 test_completion_with_image_embeds.py 应改名,因为多模态输入必须使用 Chat Completion API,而非 Completions API。审核者 DarkLight1337 最初因文件名截断误解了文件路径,讨论后确认该更改是正确的。

结论:文件被重命名为 test_chat_completion_with_image_embeds.py,测试函数名改为 test_chat_completions_with_image_embeds。 · 已解决

风险与影响

风险极低。主要风险是 CI 配置未同步更新导致测试丢失,但本 PR 已同步修改 .buildkite/test-amd.yaml.buildkite/test_areas/entrypoints.yaml,确保新路径被覆盖。测试本身无核心逻辑变更,回归风险可忽略。

  • 用户影响:无。纯测试文件和 CI 配置变更,不影响运行时功能。
  • 系统影响:CI 管道将按新路径执行测试,旧路径不再被覆盖,无重复风险。
  • 团队影响:多模态测试集中在 tests/entrypoints/multimodal/ 下,共享资源减少冗余,提升了可维护性和一致性。
CI 配置更新 测试路径变更 无核心逻辑变更

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论