[Bug]: bench serve drops custom headers when stopping the profiler

使用 vllm bench serve --profile --header ... 时,如果服务端或中间代理要求自定义请求头,profiler 的停止请求会因缺少这些头而返回 401,导致 trace 未导出。优先排查 bench 客户端在 /stop_profile 请求中是否携带了 extra

快速结论:使用 vllm bench serve --profile --header ... 时,如果服务端或中间代理要求自定义请求头,profiler 的停止请求会因缺少这些头而返回 401,导致 trace 未导出。优先排查 bench 客户端在 /stop_profile 请求中是否携带了 extra_headers。

适用环境:Issue 中确认的环境为 vLLM 0.28.0 Linux arm64 CPU 官方镜像(sha256:dbc1b4da66bbc0cb3a3f6859cd9046833f9540d34322b192625868f888e8e094),benchmark 源码来自 main cd64c2d;模型为 SmolLM2-135M-Instruct,float32,eager 模式,使用 PyTorch CPU profiler。复现环境为带本地转发代理、要求自定义请求头的服务端。

最快修复方案:暂无确认的一步修复方案。上游合入的 #57875 已把 extra_headers 同时传给 start 和 stop 调用,Issue 作者在 main 5be4266f5c7c10c69e4be5f3ec01d6a1d8bae9a1 上通过 loopback HTTP 服务器验证了四种 start/stop 组合(带与不带自定义 authorization/tenant 头)均通过。可优先尝试升级到包含该修复的 vLLM 版本或提交。

注意事项:验证只覆盖了 loopback HTTP 服务器上的 start/stop 请求头传递,Issue 作者明确说明未重复进行模型推理或 GPU 测试;因此该确认不能等同于完整的端到端 benchmark 回归。若停留在修复前的版本,自行给 /stop_profile 的 RequestFuncInput 补 extra_headers 属于 Issue 正文中提到的思路,需自行验证。

问题场景

在 vLLM 中启用 benchmark profiler:vllm bench serve --profile --header ...,并让服务端配置 --profiler-config '{"profiler":"torch","torch_profiler_dir":"/traces"}'。服务端位于一个本地转发代理之后,该代理要求 POST 请求携带指定的自定义请求头。benchmark 会先后发起 /start_profile、推理请求和 /stop_profile;前两类请求正常完成,停止 profiler 的请求却因缺少请求头被拦下。

Issue 中说明,该问题在默认后端和 --backend openai-chat --endpoint /v1/chat/completions 下都能复现,因此与具体推理接口无关,而与 profiling 停止调用是否透传用户请求头有关。

报错原文

[Bug]: bench serve drops custom headers when stopping the profiler

POST /start_profile      200  both custom headers present
POST /v1/...completions  200  both custom headers present
POST /stop_profile       401  custom headers absent
completed requests: 2; failed inference requests: 0
CPU trace files at benchmark completion: 0

原因分析

最可能的原因是 benchmark 客户端在构造 /stop_profile 请求时,没有把 --header 提供的自定义头写入对应的 RequestFuncInput,而 start 请求和推理请求的构造路径带上了这些头。Issue 正文给出的直接证据是:为 stop 请求的 RequestFuncInput 添加 extra_headers=extra_headers 后,两种 backend 都恢复正常。若服务端或代理强制校验这些头,stop 调用会先返回 401,profiler 保持激活状态,benchmark 结束时不会产生已导出的 trace 文件。

环境排查

  • 确认 vLLM 版本是否早于包含上游 #57875 的版本;Issue 中出问题的版本为 0.28.0。
  • 确认 bench 命令中 --header 的写法是否与服务端代理要求一致,例如 'Authorization=Bearer ...' 和 'X-Tenant=...'。
  • 确认代理是否对所有 POST(包括 /stop_profile)统一校验请求头。
  • 确认 profiler 配置中的 torch_profiler_dir 是否可写,以及 benchmark 结束后该目录下是否出现新的 trace 文件。
  • 若使用 openai-chat 后端,确认 --endpoint /v1/chat/completions 下同样能观察到 /stop_profile 返回 401。
  • Issue 未确认 CUDA、显卡或具体依赖版本信息,相关项目不要据此推断。

解决步骤

  1. 先在代理或服务端日志中确认三个请求的状态码和头信息,定位只有 /stop_profile 缺失自定义头。
  2. 将 vLLM 升级或切换到包含上游 #57875 的版本;该变更通过专门的 profiling helper 把 extra_headers 同时传给 start 和 stop 调用。
  3. 如果无法升级,可参考 Issue 中提出的修复方向:在 /stop_profile 请求的 RequestFuncInput 中传入 extra_headers=extra_headers。该做法在 Issue 未作为官方合并补丁验证,属于可优先尝试的自查修改。
  4. 修复后重新运行原来的 vllm bench serve --profile --header ... 命令,不要去掉自定义头或关闭代理鉴权,以确认问题是否真的解决。

验证方法

重新执行带 --profile --header ... 的 benchmark,检查代理或服务端日志中 /stop_profile 返回 200,并确认 /traces 下生成了包含 CPU 操作的 gzip trace 文件。Issue 中另外确认了两点:在 main 5be4266f5c7c10c69e4be5f3ec01d6a1d8bae9a1 上,带与不带自定义 authorization/tenant 头的四种 start/stop 组合均通过 loopback HTTP 服务器验证;无保护场景下的生成文本和 token 计数保持不变。该验证未重复模型推理或 GPU 测试。

参考来源

vllm-project/vllm #55746

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

这个方案解决了吗?

celebrityanime
celebrityanime
文章: 33388

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注