mirror of
https://github.com/deepseek-ai/DeepSeek-R1.git
synced 2026-11-05 00:47:42 +00:00
[GH-ISSUE #352] 本地部署DeepSeek-R1-Distill-Qwen-32B,输出仅有</think>,没有<think> #271
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
deepseek-ai/DeepSeek-R1#271
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @goufbest on GitHub (Feb 10, 2025).
Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-R1/issues/352
参照这里的代码启动了DeepSeek-R1-Distill-Qwen-32B模型服务。
主要的轮子是:
fastapi==0.115.8
uvicorn==0.34.0
transformers==4.48.2
向模型提问时,模型只能输出/think标签,但是没有开头的think标签,导致前段web无法正确识别区分思考过程。
例如:
input : hello
output like
`Alright, the user just said "hello." That's a friendly greeting. I should respond in a warm and welcoming manner. Maybe say something like, "Hello! How can I assist you today?" That way, I'm open to whatever they need help with.
Hello! How can I assist you today?`
该怎么解决这个问题?更换模型例如DeepSeek-R1-Distill-Qwen-7B会有效吗?
@haowang02 commented on GitHub (Feb 10, 2025):
我想你遇到这个问题是因为昨天模型仓库更新后 chat_template 末尾增加了
<think>\\n,也就是说<think>标签在 prompt 中,而非生成的内容中。不妨尝试将 chat_template 中的
<think>\\n去掉再进行尝试。参考如下代码:
对比结果如下:
输出:
@haowang02 commented on GitHub (Feb 10, 2025):
当然这样并不是一个好的解决问题的方法,因为官方说:
@zhaob1n commented on GitHub (Feb 10, 2025):
如果是vllm部署的该如何解决?
@Kenwwww commented on GitHub (Feb 10, 2025):
新版vllm的话 ,可以把deepseek_r1_reasoning_parser.py改了,里面解析think标签的部分自定义一下
@goufbest commented on GitHub (Feb 10, 2025):
感谢您的解决方案
@haowang02 commented on GitHub (Feb 10, 2025):
@xcpky 您好,给您提供一个我目前的解决方法。
如果不方便修改
deepseek_r1_reasoning_parser.py,可以在 vllm serve 命令中指定 chat template。具体而言,首先需要创建一个
template_deepseek_r1.jinja文件,写入如下 chat template:上述 template 是官方模型仓库中更新前的 template
之后在 vllm serve 命令中指定该 template 即可(
--chat-template ./template_deepseek_r1.jinja):@zhaob1n commented on GitHub (Feb 10, 2025):
我刚才直接修改了huggingface下载的文件里面的template。我在想能否有更好的办法,比如在content输出中直接添加
<think>?@haowang02 commented on GitHub (Feb 10, 2025):
那试试修改 vllm 的 deepseek_r1_reasoning_parser.py? 还能顺便给 vllm 提个 PR 👍
@ariesfish commented on GitHub (Feb 10, 2025):
直接修改tokenizer_config.json里的chat-template,去掉末尾的<think>\\n,vLLM重新部署一下就可以了。
加上系统提示词:
可以大幅提高模型思考的概率
@hicaonmb commented on GitHub (Feb 10, 2025):
系统提示词在哪里加?
@hwb96 commented on GitHub (Feb 11, 2025):
huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B@3865e12a1e直接查看文本差异,拿到之前的,修改tokenizer_config.json文件,重新启动模型就不需要这么麻烦了。
@joze2016 commented on GitHub (Feb 12, 2025):
这样修改后会造成有的问题没有模型思考。这个修改应该就是解决让模型每次都思考的。
@547414 commented on GitHub (Feb 13, 2025):
要加上提示词才行,提示词可以加在prompt上,或者如果用了第三方web ui, 可以在设置中配置提示词
提示词参考:
prompt:

maxkb:

@ch9hn commented on GitHub (Feb 13, 2025):
We did exactly the same steps and run it, here the code:
Chat Template (ending):
Instead of:
We put in this:
instead of
Still the same result:
@ibrahimsteed commented on GitHub (Feb 14, 2025):
你的接口调用结果content字段的标签内容,是不是应该在reasoning_content返回?
@liwei-rk commented on GitHub (Feb 14, 2025):
为什么加上
<think>\n, 模型就一定会进入思考模式?<think>\n\n</think>,难道不是模型的输出吗?本质上没有区别啊@ch9hn commented on GitHub (Feb 14, 2025):
This is actually true, with the old Chat Template the model is not responding with thinking text.
@Kenwwww commented on GitHub (Feb 17, 2025):
一样的 你预加一个相当于诱导模型接着生成,思考不思考什么的都是模型输出,只是不输出,解析部分就不会把他解析到reasoning_content里面
@jussker commented on GitHub (Feb 17, 2025):
个人使用的方法,激活思考不在 Asssistant 消息上加引导, 而是在 User 消息上加引导:
对于蒸馏模型: 修改 HuggingFace 模型的消息模版
这里以 DeepSeek-R1-Distill-Qwen-32B 为例子。
去模型文件里,有一个 tokenizer_config.json 文件,把里面
chat_template的<think>\\n删除掉,旧的:
删除后,新的:
同时,设置用户消息增加前缀,把旧的:
替换为新的:
@Cyclones-Y commented on GitHub (Feb 18, 2025):
@ibrahimsteed commented on GitHub (Feb 18, 2025):
是存在这个问题,但模型实际是做了思维推理,只不过把推理过程放到了
<content>中@isky-cd commented on GitHub (Feb 19, 2025):
但是通过加系统提示词的方式会存在一个问题就是,如果系统提示词是英文的,那虽然提问是用中文提问的但是他回答的是英文,相反,你系统提示词中文的,如果你使用英文问问题,他可能回答的是中文
@hahmad2008 commented on GitHub (Feb 19, 2025):
@jussker
I tried this chat template and now I can see the reasoning content, however I there is
\n\n\nin the beginning of the reasoning content and the content.example:
chat-template:
@jussker commented on GitHub (Feb 19, 2025):
@hahmad2008
After comparing the
chat-templatedifferences, found that you missed adding a prefix to user messages.The modified
chat-templateis as follows:I have tested the modified
chat-templateonDeepSeek-R1-Distill-Qwen-1.5B, and it works normally.@hahmad2008 commented on GitHub (Feb 19, 2025):
@jussker Thanks for your prompt response.
I tried the chatemplate you provided. but still I got the
\n\n\nin the beginning of the reasoning content and the content.@verigle commented on GitHub (Feb 20, 2025):
sglang 用户如何解决这个问题?
@newledge commented on GitHub (Feb 27, 2025):
什么版本?
@xring commented on GitHub (Feb 28, 2025):
if you are using
vllm, upgrade to 0.7.3 or later should solve this problem.https://github.com/vllm-project/vllm/issues/13375#issuecomment-2676496362
I tried myself with
DeepSeek-R1-Distill-Qwen-32B, worked.@lpb1 commented on GitHub (Feb 28, 2025):
The
reasoning_contentis worked, but<think></think>tag still lost the first one@xring commented on GitHub (Feb 28, 2025):
true, we use
reasoning_contentonly.@Modas-Li commented on GitHub (Mar 1, 2025):
same issue
@wifewriter commented on GitHub (Mar 2, 2025):
ollama本地部署deepseek r1也出现了这个问题,模型输出没有一开始的标签,应该怎么编写modelfile呢?
@Liusuqing commented on GitHub (Mar 5, 2025):
xinference 里 也一样。
@shuzhiweb commented on GitHub (Mar 11, 2025):
升级sglang最新版, 并保留chat_template 中的 think标签
@Liusuqing commented on GitHub (Mar 11, 2025):
好像说反了吧?
另外,模型不同,解决方法好像也有差异。
以 qwen 32 4bit量化版为例,直接删除
@shuzhiweb commented on GitHub (Mar 11, 2025):
你说的可能是对的,目前我们用的是满血版的,以上是我们的解决方案
@CiaranYoung commented on GitHub (Mar 14, 2025):
直接vllm离线推理好像也没有
@longshine commented on GitHub (Apr 7, 2025):
如果是 vllm 部署,加上这个参数:
--enable-reasoning --reasoning-parser deepseek_r1亲测 vllm v0.8.3 有效
See also: https://docs.vllm.ai/en/latest/features/reasoning_outputs.html#quickstart
@Modas-Li commented on GitHub (Apr 7, 2025):
Thank you for your email !您好,你的邮件我已收到,我会尽快给你回复。
@sgr-china commented on GitHub (Apr 24, 2025):
这个确实有效,vLLM 0.6.3,DeepSeek-R1-Distill-Qwen-14B和QwQ-32B都有效
@lhhssd commented on GitHub (Apr 27, 2025):
请问, \n\n
<think>\n 添加到具体哪个位置呢??是tokenizer_config.json文件的chat_template开头还是末尾的'<|Assistant|><think>\\n' 改为'<|Assistant|><think>\n\n</think>\n' 呢???@T-DeBuger commented on GitHub (May 15, 2025):
起因:msr2000 commited on Feb 9 更新了 tokenizer_config.json
huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Llama-70B@0d6d11a6ea@Modas-Li commented on GitHub (May 15, 2025):
Thank you for your email !您好,你的邮件我已收到,我会尽快给你回复。
@HZOK2022 commented on GitHub (May 15, 2025):
vllm 部署时在--reasoning-parser deepseek_r1前加上--enable-reasoning,推理内容会输出到reasoning_content字段内。并且不需要修改tokenizer_config.json中的模板,即不需要删掉think标签,也能正常输出。
vllm version: 0.8.5.post1
@llc2peak commented on GitHub (May 20, 2025):
使用ollama部署的,也是一样这个问题,开始没有,而且好像并不只是没有think,还会丢失一小段话,请问要怎么解决
@github-actions[bot] commented on GitHub (Jun 22, 2025):
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this issue is still relevant, please leave a comment to keep it open. Thank you for your contributions!
@Modas-Li commented on GitHub (Jun 22, 2025):
Thank you for your email !您好,你的邮件我已收到,我会尽快给你回复。
@github-actions[bot] commented on GitHub (Jul 25, 2025):
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this issue is still relevant, please leave a comment to keep it open. Thank you for your contributions!
@github-actions[bot] commented on GitHub (Aug 9, 2025):
false