【案例】Deepseek-R1-W8A8推理时有些问题不思考直接回答,返回结果<think>\n\n</think>
收藏回复举报
【案例】Deepseek-R1-W8A8推理时有些问题不思考直接回答,返回结果<think>\n\n</think>
发表于2025-04-16 22:29:24
0 查看

【问题描述】 

Deepseek-R1-W8A8推理时有些问题不思考直接回答,返回结果&lt;think&gt;\n\n&lt;/think&gt;

cke_1113.png

【产品及版本】

Atlas 800T A2

Deepseek-R1-W8A8

【问题原因】

deepseek官方就说明了R1对某些问题会倾向于不不思考,所以后来deepseek官方更新过tokenizerchat_template,在tokenizer_config.json中字段chat_template最后添加了&lt;think&gt;\\n标签,以引导模型强制思考

【处理过程】

  1. 通过了解,是有些问题返回结果是&lt;think&gt;\n\n&lt;/think&gt;,不是所有结果,因此排除了版本、权重问题
  2. 查看DeepSeek官网发布说明,DeepSeek-R1在系列模型在回答某些查询时往往会绕过思考模式(即输出“&lt;think&gt;\n\n&lt;/think&gt;”),属于DeepSeek-R1模型的一个正常现象

https://github.com/deepseek-ai/DeepSeek-R1

Additionally, we have observed that the DeepSeek-R1 series models tend to bypass thinking pattern (i.e., outputting &quot;&lt;think&gt;\n\n&lt;/think&gt;&quot;) when responding to certain queries

cke_40697.png

3. 官网建议:强制模型在每次输出的开头以“&lt;think&gt;\n”开始。已在最新权重文件tokenizer_config.json中字段chat_template最后面添加了“&lt;think&gt;\\n

cid:link_1/DeepSeek-R1/blob/main/tokenizer_config.json

【解决方案】

更新官方最新的权重文件,tokenizer_config.json中字段chat_template,已在最后强制带上了&lt;think&gt;标签“&lt;think&gt;\\n

&quot;chat_template&quot;: &quot;{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% set ns = namespace(is_first=false, is_tool=false, is_output_first=true, system_prompt='', is_first_sp=true) %}{%- for message in messages %}{%- if message['role'] == 'system' %}{%- if ns.is_first_sp %}{% set ns.system_prompt = ns.system_prompt + message['content'] %}{% set ns.is_first_sp = false %}{%- else %}{% set ns.system_prompt = ns.system_prompt + '\\n\\n' + message['content'] %}{%- endif %}{%- endif %}{%- endfor %}{{ bos_token }}{{ ns.system_prompt }}{%- for message in messages %}{%- if message['role'] == 'user' %}{%- set ns.is_tool = false -%}{{'&lt;User&gt;' + message['content']}}{%- endif %}{%- if message['role'] == 'assistant' and 'tool_calls' in message %}{%- set ns.is_tool = false -%}{%- for tool in message['tool_calls'] %}{%- if not ns.is_first %}{%- if message['content'] is none %}{{'&lt;Assistant&gt;&lt;toolcallsbegin&gt;&lt;toolcallbegin&gt;' + tool['type'] + '&lt;toolsep&gt;' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '&lt;toolcallend&gt;'}}{%- else %}{{'&lt;Assistant&gt;' + message['content'] + '&lt;toolcallsbegin&gt;&lt;toolcallbegin&gt;' + tool['type'] + '&lt;toolsep&gt;' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '&lt;toolcallend&gt;'}}{%- endif %}{%- set ns.is_first = true -%}{%- else %}{{'\\n' + '&lt;toolcallbegin&gt;' + tool['type'] + '&lt;toolsep&gt;' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '&lt;toolcallend&gt;'}}{%- endif %}{%- endfor %}{{'&lt;toolcallsend&gt;&lt;endofsentence&gt;'}}{%- endif %}{%- if message['role'] == 'assistant' and 'tool_calls' not in message %}{%- if ns.is_tool %}{{'&lt;tooloutputsend&gt;' + message['content'] + '&lt;endofsentence&gt;'}}{%- set ns.is_tool = false -%}{%- else %}{% set content = message['content'] %}{% if '&lt;/think&gt;' in content %}{% set content = content.split('&lt;/think&gt;')[-1] %}{% endif %}{{'&lt;Assistant&gt;' + content + '&lt;endofsentence&gt;'}}{%- endif %}{%- endif %}{%- if message['role'] == 'tool' %}{%- set ns.is_tool = true -%}{%- if ns.is_output_first %}{{'&lt;tooloutputsbegin&gt;&lt;tooloutputbegin&gt;' + message['content'] + '&lt;tooloutputend&gt;'}}{%- set ns.is_output_first = false %}{%- else %}{{'&lt;tooloutputbegin&gt;' + message['content'] + '&lt;tooloutputend&gt;'}}{%- endif %}{%- endif %}{%- endfor -%}{% if ns.is_tool %}{{'&lt;tooloutputsend&gt;'}}{% endif %}{% if add_generation_prompt and not ns.is_tool %}{{'&lt;Assistant&gt;&lt;think&gt;\\n'}}{% endif %}&quot;

【总结和建议】

1. 只有DeepSeek-R1系列模型存在这个问题,像DeepSeek-R1DeepSeek-R1-Distill-Llama-70BDeepSeek-R1-Distill-Qwen-32BDeepSeek-V3系列模型不存在

可以通过https://huggingface.co/deepseek-ai查看各个模型权重文件tokenizer_config.json中字段chat_template最后是否有“&lt;think&gt;\\n

2.  最新的DeepSeek-R1-0528权重文件的tokenizer_config.json中字段chat_template最后默认没有“&lt;think&gt;\\n”,如果出现不经过思考直接回答问题,可以手动添加强制思考

本帖最后由 匿名用户2025/06/09 23:03:53 编辑

我要发帖子