用SGLang部署的DeepSeek R1推理时没有输出<think>标签

背景

最近同事在公司的服务器上使用SGLang部署了满血版DeepSeek R1,但在请求时有个奇怪的问题,就是接口返回的文本开头没有<think>这个标签,但是却又对应的</think>标签,如下所示:

{
	"id":"ccdb5eb2ab4f432ea91cb22cdef8bebe",
	"object":"chat.completion",
	"created":1740644733,
	"model":"default",
	"choices":[
		{
			"index":0,
			"message":
				{
					"role":"assistant",
					"content":"嗯,用户发了个“hello?”,看起来像是在测试或者看看有没有人在线。我需要确认他们是不是需要帮助,或者有没有具体的问题要问。应该保持友好,开放式的回应,鼓励他们提出具体的问题或者需求。同时注意语气要亲切,避免显得机械。\n</think>\n\nHello! How can I assist you today? 😊",
					"tool_calls":null
				},
			"logprobs":null,
			"finish_reason":"stop",
			"matched_stop":1
		}
	],
	"usage":{"prompt_tokens":9,"total_tokens":81,"completion_tokens":72,"prompt_tokens_details":null}
}

原因

到SGLang的GitHub项目上搜了一下,发现很多人都遇到这个问题:https://github.com/sgl-project/sglang/issues/3668

最后在这里找到了原因:https://github.com/sgl-project/sglang/issues/3620,原来是DeepSeek R1的tokenizer配置的chat_template会在输入给模型的prompt后面添加<think>\n,模型从这个标签后开始生成数据,因此返回的文本开头就没有这个<think>标签。

这其实是DeepSeek团队为了保证模型效果采取的做法,在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, which can adversely affect the model’s performance. To ensure that the model engages in thorough reasoning, we recommend enforcing the model to initiate its response with “<think>\n” at the beginning of every output.

所以如果你不想在客户端自己添加<think>,而是希望模型自己能够输出,那么可以将模型文件中的 tokenizer配置文件chat_template后面增加的<think>\\n去掉然后再重新部署模型。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Elwin Wong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值