Prhub

#41084 [Examples][last/6] Resettle examples.

原始 PR 作者 noooop 合并时间 2026-05-08 10:42 文件变更 61 提交数 14 评论 4 代码增减 +60 / -88

执行摘要

按使用场景重新组织 examples 目录

参考 issue #29362 的 RFC 提议,通过按使用场景组织示例来提高可发现性,使用户无需在多个文件夹间搜索特定用例。

此 PR 属于纯组织性变更,值得阅读以理解示例分类思路。关注焦点:新目录结构是否合理、路径引用更新是否彻底。建议合入后清理外部文档链接。

讨论亮点
  • gemini-code-assist[bot] 指出 docs/deployment/frameworks/retrieval_augmented_generation.md 中链接出现重复 examples/examples/ 拼写错误,建议修正。
  • noooop 发现 .buildkite/scripts/hardware_ci/run-tpu-v1-test.sh 中移除的测试文件路径不存在,注释说明"文件未找到"。
  • DarkLight1337 批准并留言"LGTM if tests pass"。

实现拆解

步骤

  1. 创建新目录结构:按照 basic、deployment、applications、features、speech_to_text 等场景建立一级子目录。
  2. 移动与重命名文件:将原有 offline_inference 下的脚本移入 deployment 和 basic;将 online_serving 下的聊天机器人相关脚本移入 applications/chatbot,RAG 示例移入 applications/rag;将 others 下的 tensorizer 示例移入 features。
  3. 删除无主文件:删除了 examples/online_serving/utils.py(含 get_first_model 函数),因为其逻辑已被内联或不再需要。
  4. 更新文档引用:在 docs/ 目录下多处修复了指向示例脚本的路径,并修正了 retrieval_augmented_generation.md 中重复 examples/ 的 typo。
  5. 调整 CI 脚本:在 .buildkite/scripts/hardware_ci/run-tpu-v1-test.sh 中移除了对已删除 offline_inference 测试的引用。
  6. 源码内路径修正:在 vllm/model_executor/model_loader/tensorizer.py 等文件中更新了指向示例脚本的注释路径。
文件 模块 状态 重要度
examples/online_serving/utils.py 服务工具 removed 7.27
examples/features/tensorize_vllm_model.py 序列化特性 renamed 6.28
examples/applications/chatbot/gradio_openai_chatbot_webserver.py 聊天应用 renamed 5.22
examples/deployment/async_llm_streaming.py 部署脚本 renamed 5.22
vllm/model_executor/model_loader/tensorizer.py 模型加载 modified 5.18
docs/deployment/frameworks/retrieval_augmented_generation.md 文档 modified 4.0

关键符号

get_first_model

关键源码片段

examples/online_serving/utils.py deletion

核心删除文件,移除了 get_first_model 函数

# SPDX-License-Identifier: Apache-2.0
# 该文件被完全删除,因为 get_first_model 函数不再被使用
from openai import APIConnectionError, OpenAI
from openai.pagination import SyncPage
from openai.types.model import Model
​
​
def get_first_model(client: OpenAI) -> str:
    """
    从 vLLM 服务器获取第一个模型 ID。
    删除原因:目录重组后该辅助函数不再被任何示例引用,
    各示例改为直接使用 client.models.list() 内联。
    """
    try:
        models: SyncPage[Model] = client.models.list()
    except APIConnectionError as e:
        raise RuntimeError(
            "Failed to get the list of models from the vLLM server at "
            f"{client.base_url} with API key {client.api_key}. Check\n"
            "1. the server is running\n"
            "2. the server URL is correct\n"
            "3. the API key is correct"
        ) from e
    if len(models.data) == 0:
        raise RuntimeError(f"No models found on the vLLM server at {client.base_url}")
    return models.data[0].id

评论区精华

文档链接路径重复 documentation

gemini-code-assist[bot] 指出 docs/deployment/frameworks/retrieval_augmented_generation.md 中链接出现 'examples/examples/' 重复路径,建议修复。

结论:noooop 接受并修复(后续提交已处理)。 · 已解决

TPU 测试脚本中移除不存在的文件 question

noooop 在 .buildkite/scripts/hardware_ci/run-tpu-v1-test.sh 行 139 评论 'The file is not found.' 因为移除了对 examples/offline_inference/... 测试的引用。

结论:该行被正确移除(未再出现错误)。 · 已解决

风险与影响

主要风险在于用户或自动化脚本仍引用旧路径,导致 404。虽然 PR 已更新所有已知引用,但仍可能遗漏外部文档、博客或私有配置。此外,删除 utils.py 的 get_first_model 可能影响内部依赖(但该函数仅在 examples 内部使用,未在 vllm 核心代码中引用)。

用户侧:所有示例脚本的路径发生变化,用户需更新运行命令。但长期改善可发现性。系统侧:CI 脚本移除了一行导致失败的测试。团队侧:目录结构更清晰,易于维护。影响程度:中(60+ 文件变动,但无功能逻辑变化)。

文档链接遗漏 外部引用断裂 CI 脚本路径硬编码

关联 Issue

#29362 [RFC]: Resettle examples.

完整报告

参与讨论