[BugFix] Fix potential Python type error in exception tests.#7945
Open
flsgavin wants to merge 1 commit into
Open
[BugFix] Fix potential Python type error in exception tests.#7945flsgavin wants to merge 1 commit into
flsgavin wants to merge 1 commit into
Conversation
|
Thanks for your contribution! |
freeliuzc
approved these changes
May 27, 2026
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-05-27 20:30:53
📋 Review 摘要
PR 概述:在 insert_tasks_v1 方法中增加 prompt_token_ids 类型校验,防止非法类型输入导致服务 crash。
变更范围:fastdeploy/worker/gpu_model_runner.py
影响面 Tag:[BugFix] [Engine]
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🟡 建议 | gpu_model_runner.py:878 |
类型校验未同步到其他硬件 ModelRunner |
📝 PR 规范检查
存在以下问题:
- PR 目标分支为
release/online/20260415(非develop),标题应使用 Cherry-Pick 格式并附原 PR 号; - 标题中 "in exception tests" 描述不准确,修改发生在生产代码而非测试文件;
Usage or Command和Accuracy Tests段落为空,应填写N/A;- Checklist 未按实际情况勾选。
标题建议(可直接复制):
[Cherry-Pick][BugFix] Fix prompt_token_ids type validation in insert_tasks_v1 (#原PR号)
PR 描述建议(点击展开,可直接复制)
## Motivation
在异常测试中,当上游传入非法类型的数据(如 string 类型的 input_ids)时,`insert_tasks_v1` 方法缺少对 `prompt_token_ids` 的输入类型校验,导致服务直接 crash。
## Modifications
在 `fastdeploy/worker/gpu_model_runner.py` 的 `insert_tasks_v1` 方法中,在 `input_ids = prompt_token_ids + request.output_token_ids` 之前增加 `prompt_token_ids` 的参数类型校验:若类型不是 `list` 或 `np.ndarray`,则记录错误日志并通过设置 `stop_flags`、`seq_lens_this_time_buffer`、`seq_lens_encoder` 终止该请求。
## Usage or Command
N/A
## Accuracy Tests
N/A
## Checklist
- [x] Add at least a tag in the PR title.
- Tag list: [`[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]`]
- You can add new tags based on the PR content, but the semantics must be clear.
- [ ] Format your code, run `pre-commit` before commit.
- [ ] Add unit tests. Please write the reason in this PR if no unit tests.
- [ ] Provide accuracy results.
- [ ] If the current PR is submitting to the `release` branch, make sure the PR has been submitted to the `develop` branch, then cherry-pick it to the `release` branch with the `[Cherry-Pick]` PR tag.总体评价
修复思路正确,有效防止了非法类型输入导致的 crash。建议同步到其他硬件 ModelRunner,并补充 Cherry-Pick 格式标题及完整 PR 描述。
| self.share_inputs["max_reply_lens"][idx : idx + 1, :] = -1 | ||
| self.share_inputs["limit_think_status"][idx : idx + 1, :] = 0 | ||
|
|
||
| if not isinstance(request.prompt_token_ids, (list, np.ndarray)): |
There was a problem hiding this comment.
🟡 建议 此类型校验仅在 gpu_model_runner.py 中添加,其他硬件 ModelRunner(xpu_model_runner.py、dcu_model_runner.py、gcu_model_runner.py、hpu_model_runner.py、iluvatar_model_runner.py、metax_model_runner.py)中的 insert_tasks_v1 方法若存在相同逻辑,也应同步添加此校验,否则其他硬件上仍会 crash。
建议修复方式:
检查上述各硬件 ModelRunner 的 insert_tasks_v1 方法,在相同位置添加等价的类型校验逻辑。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
在异常测试中,包含input_ids = "1,2,3,4,5" 这样的异常字符串caae,FastDeploy 的 insert_tasks_v1 方法缺少对 input_ids / prompt_token_ids 的输入类型校验。当上游传入非法类型的数据时(例如string类型),服务直接 crash 。
Modifications
在input_ids = prompt_token_ids + request.output_token_ids前面增加prompt_token_ids的参数类型校验,如果类型异常直接终止这条请求。
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.