Repository navigation
[Bugfix][Tool Parser] Parse multi-line JSON arguments in the DeepSeek V3 and V3.1 parsers - #60362
Conversation
…tool parsers Signed-off-by: niansia <niansia930202@gmail.com>
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in PRs do not trigger a full CI run by default. Reviewers with write access and configured trusted contributors can comment Once the PR is approved or has the If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. Agent GuidelinesIMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban. 🚀 |
|
Reproduced and verified: with real DeepSeek-V3/V3.1 tokenizers and two parallel calls (string-, number-, nested-ending args, indent 2 and 4), main loses or truncates every pretty-printed call in both modes for both parsers, and this PR gets all of them right. I'd prefer this over #60361 because the V3.1 parser has the same bug (#60361 only fixes V3). Related, not introduced here: with multi-token deltas (MTP / |
|
/ci run |
|
✅ @niansia, CI is now available for this PR.
|
|
✅ Triggered Buildkite CI #95901 for commit |
|
This pull request has merge conflicts that must be resolved before it can be |
Signed-off-by: Artem Perevedentsev <aperevedents@nvidia.com> # Conflicts: # tests/tool_parsers/test_deepseekv3_tool_parser.py
|
/ci run |
|
✅ Triggered Buildkite CI #95907 for commit |
… V3 and V3.1 parsers (vllm-project#60362) Signed-off-by: niansia <niansia930202@gmail.com> Co-authored-by: Artem Perevedentsev <aperevedents@nvidia.com>
Overview
Fixes #60342. The
deepseek_v3anddeepseek_v31tool parsers lose tool calls whose JSON arguments the model pretty-prints over several lines: their regexes match the arguments with., which stops at a newline.Claims
deepseek_v3anddeepseek_v31, in both streaming and non-streaming mode.Validation
Reproducer from the issue, run through the test helpers with the real tokenizers (
deepseek-ai/DeepSeek-V3,deepseek-ai/DeepSeek-V3.1), with{"city": "Tokyo", "unit": "celsius"}dumped withindent=2:deepseek_v3tools_called=True,tool_calls=[])get_weatherwith the full argumentsdeepseek_v3get_weatherwith arguments{get_weatherwith the full argumentsdeepseek_v31get_weatherwith the full argumentsdeepseek_v31get_weatherwith arguments{get_weatherwith the full argumentsAdded
test_multiline_json_arguments(DeepSeek-V3, two parallel calls with pretty-printed arguments) andtest_extract_tool_calls_with_multiline_arguments(DeepSeek-V3.1), each run in streaming and non-streaming mode. All four cases fail on main and pass with this change.ruff check,ruff format --checkandtools/pre_commit/mypy.pypass on the changed files.These ran on CPU (WSL,
VLLM_TARGET_DEVICE=empty, with the post-test GPU cleanup skipped since there is no accelerator). I did not run a server end to end with a DeepSeek-V3 checkpoint, which needs a multi-GPU node; the change is limited to the parsers' regexes.Details
DeepSeekV3ToolParsermatchesfunction_argumentswith.*(.*[^\n`]when streaming), andDeepSeekV31ToolParserwith.*?/.*. Withoutre.DOTALL,.doesn't match\n, so the non-streaming regex finds nothing and the streaming regex captures only the first line of the arguments.[\s\S]. It stays non-greedy in the regexes used withfindall, so parallel calls still split at the first closing tag. The type and function-name groups keep., so a name can't span lines and the whole pattern doesn't needre.DOTALL.rust/src/parser/src/tool/deepseek_json) don't use a regex here;take_json_objectscans the object by brace depth, so from reading the code they already handle pretty-printed arguments. Only the Python parsers change.AI assistance was used for this change (tracking down the cause, writing the tests and this description). I reviewed every changed line and ran the tests above.
Pull Request Checklist
I used vLLM's
/pr-checklistskill. (Mandatory for agents, optional for humans).AI assistance was used during the creation of this PR.
Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.
Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.
Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.
Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.