【问题描述】
Deepseek-R1-W8A8推理时有些问题不思考直接回答,返回结果<think>\n\n</think>

【产品及版本】
Atlas 800T A2
Deepseek-R1-W8A8
【问题原因】
deepseek官方就说明了R1对某些问题会倾向于不不思考,所以后来deepseek官方更新过tokenizer的chat_template,在tokenizer_config.json中字段chat_template最后添加了<think>\\n标签,以引导模型强制思考
【处理过程】
- 通过了解,是有些问题返回结果是<think>\n\n</think>,不是所有结果,因此排除了版本、权重问题。
- 查看DeepSeek官网发布说明,DeepSeek-R1在系列模型在回答某些查询时往往会绕过思考模式(即输出“<think>\n\n</think>”),属于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 "<think>\n\n</think>") when responding to certain queries

3. 官网建议:强制模型在每次输出的开头以“<think>\n”开始。已在最新权重文件tokenizer_config.json中字段chat_template最后面添加了“<think>\\n”
cid:link_1/DeepSeek-R1/blob/main/tokenizer_config.json
【解决方案】
更新官方最新的权重文件,tokenizer_config.json中字段chat_template,已在最后强制带上了<think>标签“<think>\\n”
"chat_template": "{% 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 -%}{{'<|User|>' + 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 %}{{'<|Assistant|><|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}}{%- else %}{{'<|Assistant|>' + message['content'] + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}}{%- endif %}{%- set ns.is_first = true -%}{%- else %}{{'\\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}}{%- endif %}{%- endfor %}{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}{%- endif %}{%- if message['role'] == 'assistant' and 'tool_calls' not in message %}{%- if ns.is_tool %}{{'<|tool▁outputs▁end|>' + message['content'] + '<|end▁of▁sentence|>'}}{%- set ns.is_tool = false -%}{%- else %}{% set content = message['content'] %}{% if '</think>' in content %}{% set content = content.split('</think>')[-1] %}{% endif %}{{'<|Assistant|>' + content + '<|end▁of▁sentence|>'}}{%- endif %}{%- endif %}{%- if message['role'] == 'tool' %}{%- set ns.is_tool = true -%}{%- if ns.is_output_first %}{{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}{%- set ns.is_output_first = false %}{%- else %}{{'<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}{%- endif %}{%- endif %}{%- endfor -%}{% if ns.is_tool %}{{'<|tool▁outputs▁end|>'}}{% endif %}{% if add_generation_prompt and not ns.is_tool %}{{'<|Assistant|><think>\\n'}}{% endif %}"
【总结和建议】
1. 只有DeepSeek-R1系列模型存在这个问题,像DeepSeek-R1、DeepSeek-R1-Distill-Llama-70B、DeepSeek-R1-Distill-Qwen-32B,DeepSeek-V3系列模型不存在
可以通过https://huggingface.co/deepseek-ai查看各个模型权重文件tokenizer_config.json中字段chat_template最后是否有“<think>\\n”
2. 最新的DeepSeek-R1-0528权重文件的tokenizer_config.json中字段chat_template最后默认没有“<think>\\n”,如果出现不经过思考直接回答问题,可以手动添加强制思考
【问题描述】
Deepseek-R1-W8A8推理时有些问题不思考直接回答,返回结果<think>\n\n</think>
【产品及版本】
Atlas 800T A2
Deepseek-R1-W8A8
【问题原因】
deepseek官方就说明了R1对某些问题会倾向于不不思考,所以后来deepseek官方更新过tokenizer的chat_template,在tokenizer_config.json中字段chat_template最后添加了<think>\\n标签,以引导模型强制思考
【处理过程】
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 "<think>\n\n</think>") when responding to certain queries
3. 官网建议:强制模型在每次输出的开头以“<think>\n”开始。已在最新权重文件tokenizer_config.json中字段chat_template最后面添加了“<think>\\n”
cid:link_1/DeepSeek-R1/blob/main/tokenizer_config.json
【解决方案】
更新官方最新的权重文件,tokenizer_config.json中字段chat_template,已在最后强制带上了<think>标签“<think>\\n”
"chat_template": "{% 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 -%}{{'<|User|>' + 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 %}{{'<|Assistant|><|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}}{%- else %}{{'<|Assistant|>' + message['content'] + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}}{%- endif %}{%- set ns.is_first = true -%}{%- else %}{{'\\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}}{%- endif %}{%- endfor %}{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}{%- endif %}{%- if message['role'] == 'assistant' and 'tool_calls' not in message %}{%- if ns.is_tool %}{{'<|tool▁outputs▁end|>' + message['content'] + '<|end▁of▁sentence|>'}}{%- set ns.is_tool = false -%}{%- else %}{% set content = message['content'] %}{% if '</think>' in content %}{% set content = content.split('</think>')[-1] %}{% endif %}{{'<|Assistant|>' + content + '<|end▁of▁sentence|>'}}{%- endif %}{%- endif %}{%- if message['role'] == 'tool' %}{%- set ns.is_tool = true -%}{%- if ns.is_output_first %}{{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}{%- set ns.is_output_first = false %}{%- else %}{{'<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}{%- endif %}{%- endif %}{%- endfor -%}{% if ns.is_tool %}{{'<|tool▁outputs▁end|>'}}{% endif %}{% if add_generation_prompt and not ns.is_tool %}{{'<|Assistant|><think>\\n'}}{% endif %}"
【总结和建议】
1. 只有DeepSeek-R1系列模型存在这个问题,像DeepSeek-R1、DeepSeek-R1-Distill-Llama-70B、DeepSeek-R1-Distill-Qwen-32B,DeepSeek-V3系列模型不存在
可以通过https://huggingface.co/deepseek-ai查看各个模型权重文件tokenizer_config.json中字段chat_template最后是否有“<think>\\n”
2. 最新的DeepSeek-R1-0528权重文件的tokenizer_config.json中字段chat_template最后默认没有“<think>\\n”,如果出现不经过思考直接回答问题,可以手动添加强制思考