[Frontend] Add deepseek v3.1 reasoning parser#23437
[Frontend] Add deepseek v3.1 reasoning parser#23437arsenetar wants to merge 2 commits intovllm-project:mainfrom
Conversation
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run You ask your reviewers to trigger select CI tests on top of Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. 🚀 |
There was a problem hiding this comment.
Code Review
This pull request introduces a new reasoning parser for DeepSeek v3.1, which supports conditional thinking based on the thinking flag in chat_template_kwargs. The implementation correctly adds the new parser and updates the necessary method signatures across the codebase to pass the request object. My review focuses on ensuring the correctness of the new logic. I've identified a potential issue in how the thinking flag is evaluated, which could lead to incorrect behavior. The proposed changes aim to make this check more robust.
b966cf7 to
dc98b10
Compare
|
vllm部署的时候可以默认为思考模式吗? |
|
hope to support the merger and launch as soon as possible |
dc98b10 to
d0c60c1
Compare
3842655 to
b762ca9
Compare
DeepSeek v3.1 is conditionally thinking, so using the existing r1 parser does not work correctly when a non-thinking request is submitted. This adds a new parser that conditionally handles thinking when a request is submitted with the `chat_template_kwargs` of `thinking` set to `true`. (This follows the behavior of the chat template used by the model.) To include the conditional behavior in the `extract_reasoning_content_streaming` method, the `request` is added as an additional argument (this aligns with prior changes to the `extract_reasoning_content` method to include the `request` as an argument). Signed-off-by: Andrew Senetar <asenetar@coreweave.com>
Signed-off-by: Andrew Senetar <asenetar@coreweave.com>
b762ca9 to
cbbe98a
Compare
|
hope to support the merger and launch as soon as possible @chaunceyjiang @aarnphm |
|
Oh, I'm really sorry I didn't notice this PR. There is currently a PR #25589 that is about to be merged. Could you help test this PR? |
|
This pull request has merge conflicts that must be resolved before it can be |
Purpose
DeepSeek v3.1 is conditionally thinking, so using the existing r1 parser does not work correctly when a non-thinking request is submitted. (All the content ends up in reasoning_content as the expected
</think>is not found.) This adds a new parser that conditionally handles thinking (with the r1 parser) when a request is submitted with thechat_template_kwargsofthinkingset totrue. (This follows the behavior of the chat template used by the model.)To include the conditional behavior in the
extract_reasoning_content_streamingmethod, therequestis added as an additional argument (this aligns with prior changes to theextract_reasoning_contentmethod to include therequestas an argument).Test Plan
Tested by running a simple completions request with thinking enabled and disabled (base payload derived from a basic example) with the model using the new parser
deepseek_v31:{ "model": "deepseek-ai/DeepSeek-V3.1", "messages": [ { "role": "assistant", "content": "<think>Hmm</think>" }, { "role": "user", "content": "9.11 and 9.8, which is greater?" } ], "max_tokens": 2000, "stream": false, "chat_template_kwargs": { "thinking": true } }Test Result
With thinking (output filtered to only relevant sections):
{ "choices":[ { "index":0, "message": { "role":"assistant", "content":"To determine which number is greater between 9.11 and 9.8, compare their decimal parts.\n\n- 9.11 has a decimal part of 0.11 (11 hundredths).\n- 9.8 can be written as 9.80, which has a decimal part of 0.80 (80 hundredths).\n\nSince 0.80 is greater than 0.11, 9.8 is greater than 9.11.\n\nThis can also be verified by subtraction: \n9.80 - 9.11 = 0.69, which is positive, confirming that 9.8 is greater.\n\nThus, 9.8 is greater than 9.11.", "function_call": null, "tool_calls": [], "reasoning_content": "I have two numbers: 9.11 and 9.8. I need to figure out which one is greater. Both are decimals, so I should compare them digit by digit.\n\nFirst, I look at the whole number part. Both have 9 as the whole number, so that doesn't help. I need to compare the decimal parts.\n\nThe decimal part of 9.11 is 0.11, and for 9.8, it's 0.8. But 0.8 is the same as 0.80, which is greater than 0.11. Let me think carefully.\n\nI can also think of them as fractions. 9.11 is 911/100, and 9.8 is 98/10, but I should make the denominators the same.\n\n9.8 is equal to 9.80, because adding a zero at the end doesn't change the value. So, comparing 9.80 and 9.11, clearly 9.80 is larger because 80 hundredths is more than 11 hundredths.\n\nSo, 9.8 is greater than 9.11.\n\nI recall that sometimes people get confused because 11 is greater than 8, but that's only if we think of the digits without considering the decimal places. In decimals, the first digit after the decimal is tenths, so for 9.8, it's 8 tenths, which is 0.8, and for 9.11, it's 1 tenth and 1 hundredth, so 0.11, and 0.8 is greater than 0.11.\n\nYes, that makes sense.\n\nSo, to be thorough, I can subtract them. 9.8 minus 9.11 equals 0.69, which is positive, so 9.8 is greater.\n\nTherefore, 9.8 is greater than 9.11." } }] }Without thinking (output filtered to only relevant sections)::
{ "choices": [ { "index":0, "message": { "role":"assistant", "content":"To determine which number is greater between 9.11 and 9.8, you can compare them digit by digit:\n\n- Both numbers have the same whole number part (9).\n- Compare the tenths place: 9.11 has a 1 in the tenths place, while 9.8 has an 8 in the tenths place. Since 8 is greater than 1, 9.8 is greater than 9.11.\n\nTherefore, **9.8 is greater than 9.11**.", "function_call":null, "tool_calls":[], "reasoning_content":null } }] }(Optional) Documentation Update
N/A
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.