Skip to content

[Frontend] Add deepseek v3.1 reasoning parser#23437

Closed
arsenetar wants to merge 2 commits intovllm-project:mainfrom
arsenetar:as/deepseek-v31-reasoning-parsser
Closed

[Frontend] Add deepseek v3.1 reasoning parser#23437
arsenetar wants to merge 2 commits intovllm-project:mainfrom
arsenetar:as/deepseek-v31-reasoning-parsser

Conversation

@arsenetar
Copy link
Copy Markdown

@arsenetar arsenetar commented Aug 22, 2025

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 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).

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
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

@arsenetar arsenetar requested a review from aarnphm as a code owner August 22, 2025 17:14
@github-actions
Copy link
Copy Markdown

👋 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 fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors.

You ask your reviewers to trigger select CI tests on top of fastcheck CI.

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 ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

🚀

@mergify mergify bot added deepseek Related to DeepSeek models frontend qwen Related to Qwen models labels Aug 22, 2025
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@LeeX852
Copy link
Copy Markdown

LeeX852 commented Sep 19, 2025

vllm部署的时候可以默认为思考模式吗?

@moxingwang
Copy link
Copy Markdown

hope to support the merger and launch as soon as possible

@arsenetar arsenetar force-pushed the as/deepseek-v31-reasoning-parsser branch from dc98b10 to d0c60c1 Compare October 10, 2025 22:05
@arsenetar arsenetar force-pushed the as/deepseek-v31-reasoning-parsser branch 2 times, most recently from 3842655 to b762ca9 Compare October 10, 2025 22:21
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>
@arsenetar arsenetar force-pushed the as/deepseek-v31-reasoning-parsser branch from b762ca9 to cbbe98a Compare October 10, 2025 22:37
@rulongchen
Copy link
Copy Markdown

hope to support the merger and launch as soon as possible @chaunceyjiang @aarnphm

@chaunceyjiang
Copy link
Copy Markdown
Collaborator

chaunceyjiang commented Oct 11, 2025

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?

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Oct 13, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @arsenetar.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Oct 13, 2025
@arsenetar arsenetar closed this Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek Related to DeepSeek models frontend needs-rebase qwen Related to Qwen models

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants