[Cherry-Pick][BugFix] Fix bugs in /v1/abort_requests interface from PR(#6992) (#7176)#7551
Conversation
|
Thanks for your contribution! |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 AI Code Review |
2026-04-22 11:37:08
📋 Review 摘要
PR 概述:修复 /v1/abort_requests 接口中的多个 Bug,包括 EOS token 访问方式、abort 等待逻辑中的竞态处理以及 finish_reason 枚举值缺失问题。
变更范围:engine/common_engine.py、engine/sched/resource_manager_v1.py、entrypoints/openai/protocol.py、tests/engine/test_common_engine.py
影响面 Tag:[Engine] [APIServer] [Scheduler]
📝 PR 规范检查
PR 描述中 Motivation / Modifications 均未填写,无法从 PR body 了解具体 Bug 背景和变更影响面,请补充以下内容:
Motivation 建议(可直接复制):
## Motivation
修复 `/v1/abort_requests` 接口中的多个 Bug:
1. `_control_abort_requests` 通过 `self.data_processor.eos_token_ids[0]` 获取 EOS token 在某些情况下会抛出 AttributeError;
2. `_wait_abort_complete` 在请求已自然结束时仍等待 abort 完成,导致不必要的超时;
3. `recycle_abort_task` / `_trigger_abort` 中使用 `set.remove` 在 key 不存在时抛出 KeyError;
4. `finish_requests` 未清理 abort 相关集合,可能导致后续误判;
5. OpenAI 协议中 `finish_reason` 缺少 `"abort"` 枚举值导致 Pydantic 校验报错。
## Modifications
- 使用 `getattr(request, "eos_token_ids", [0])` 安全获取 EOS token;
- `_wait_abort_complete` 入口及循环内增加"已完成请求"快速跳过逻辑;
- 将 `set.remove` 替换为 `set.discard` 避免 KeyError;
- `finish_requests` 中同步清理 abort 相关集合;
- 四个 Response/Choice 模型中补充 `"abort"` 枚举值;
- 更新相关单元测试以匹配新逻辑。
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🟡 建议 | common_engine.py:1590 |
getattr 默认值 [0] 使用魔法数字,建议添加注释或 warning 日志说明 fallback 原因 |
| ❓ 疑问 | common_engine.py:1641 |
循环内无锁读取 alive_reqs 并直接操作 abort 集合,线程安全性待确认 |
总体评价
本 PR 修复了 abort 接口中多处潜在的 KeyError 和属性访问异常,逻辑方向正确,测试也同步更新。核心逻辑中的无锁并发访问点建议作者确认线程安全性,同时 PR 描述需补充 Motivation/Modifications 以满足项目规范。
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release/2.6 #7551 +/- ##
==============================================
Coverage ? 73.75%
==============================================
Files ? 376
Lines ? 53082
Branches ? 8298
==============================================
Hits ? 39152
Misses ? 11184
Partials ? 2746
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
/re-run stable_tests |
9c91ecb
into
PaddlePaddle:release/2.6
Motivation
Modifications
Usage or Command
Accuracy Tests
Checklist
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.