tokenizer_config.json中的聊天模板似乎不正确

#23
by Akias - opened

以下是使用llama-server加载原模板的效果,<think>标签以及思考内容会被直接在正文中
屏幕截图_20260625_005727


然后加载以下修改后的模板

{%- if tools %}
    {{ '<|im_start|>system\n' }}
    {%- if messages[0]['role'] == 'system' %}
        {{ messages[0]['content'] }}
    {%- else %}
        {{ 'You are a helpful assistant.' }}
    {%- endif %}
    {{ "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
    {%- for tool in tools %}
        {{ "\n" }}
        {{ tool | tojson }}
    {%- endfor %}
    {{ "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
{%- else %}
    {%- if messages[0]['role'] == 'system' %}
        {{ '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
    {%- else %}
        {{ '<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n' }}
    {%- endif %}
{%- endif %}
{%- for message in messages %}
    {%- if message.role == "user" or (message.role == "system" and not loop.first) %}
        {{ '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
    {%- elif message.role == "assistant" and not message.tool_calls %}
        {{ '<|im_start|>' + message.role + '\n' }}
        {%- if message.reasoning_content is defined %}
            {{ '<think>\n' + message.reasoning_content + '\n</think>\n' }}
        {%- endif %}
        {{ message.content + '<|im_end|>' + '\n' }}
    {%- elif message.role == "assistant" %}
        {{ '<|im_start|>' + message.role }}
        {%- if message.content %}
            {{ '\n' + message.content }}
        {%- endif %}
        {%- for tool_call in message.tool_calls %}
            {%- if tool_call.function is defined %}
                {%- set tool_call = tool_call.function %}
            {%- endif %}
            {{ '\n<tool_call>\n{"name": "' }}
            {{ tool_call.name }}
            {{ '", "arguments": ' }}
            {{ tool_call.arguments | tojson }}
            {{ '}\n</tool_call>' }}
        {%- endfor %}
        {{ '<|im_end|>\n' }}
    {%- elif message.role == "tool" %}
        {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
            {{ '<|im_start|>user' }}
        {%- endif %}
        {{ '\n<tool_response>\n' }}
        {{ message.content }}
        {{ '\n</tool_response>' }}
        {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
            {{ '<|im_end|>\n' }}
        {%- endif %}
    {%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
    {{ '<|im_start|>assistant\n' }}
{%- endif %}

此时思考内容被正确的放在了reasoning_content中
屏幕截图_20260625_005554

WeiboAI org

Hi,我们确认了一下,目前用的就是 base模型原始的 chat template,没有针对 VibeThinker-3B 做额外修改。VibeThinker-3B 当前只支持 thinking mode,如果你希望 llama-server 把 reasoning content 和最终回答分开展示,可以根据自己的 runtime 自行修改 template。

感谢反馈。我们的模型沿用了原始 Qwen2.5-Coder 的 chat template,原模型并非推理模型,因此模版在序列化普通 assistant 消息时只处理 message.content,没有处理 message.reasoning_content。由于我们前期主要关注单轮推理能力,因此只做了让模型支持 thinking 推理所需的最小修改,没有完整添加reasoning 历史序列化逻辑。特别是历史 assistant 对话会以独立 reasoning_content 字段传回的多轮对话场景,确实存在问题。我们会在后续优化模型多轮对话支持时修复这个问题。再次感谢您发现这个问题。

Sign up or log in to comment