Rendered text for moonshotai/Kimi-K2-Thinking seems not correct.

#3
by bigmoyan - opened

model: moonshotai/Kimi-K2-Thinking

Following code:

from transformers import AutoTokenizer
tknz = AutoTokenizer.from_pretrained("moonshotai/Kimi-K2-Thinking", trust_remote_code=True)
messages = [
    {
    "role": "system",
    "content": "You are a helpful assistant."
    },
    {
    "role": "user",
    "content": "What is the capital of France?"
    },
    {
    "role": "assistant",
    "reasoning_content": "The user is asking for the capital of France. This is a factual question. I know this information.",
    "content": "The capital of France is Paris."
    },
    {
    "role": "user",
    "content": "What about Chile?"
    },
]
pred = tknz.apply_chat_template(conversation=messages, 
                                            tools = None,
                                            tokenize=False, 
                                            add_generation_prompt=True)
print(pred

gets

<|im_system|>system<|im_middle|>You are a helpful assistant.<|im_end|><|im_user|>user<|im_middle|>What is the capital of France?<|im_end|><|im_assistant|>assistant<|im_middle|><think></think>The capital of France is Paris.<|im_end|><|im_user|>user<|im_middle|>What about Chile?<|im_end|><|im_assistant|>assistant<|im_middle|>

Note that reasoning_content of assistant msg was ignored, which is what chat template expects.

However, playground gives

<|im_system|>system<|im_middle|>You are a helpful assistant.<|im_end|><|im_user|>user<|im_middle|>What is the capital of France?<|im_end|><|im_assistant|>assistant<|im_middle|><think>The user is asking for the capital of France. This is a factual question. I know this information.</think>The capital of France is Paris.<|im_end|><|im_user|>user<|im_middle|>What about Chile?<|im_end|><|im_assistant|>assistant<|im_middle|>

reasoning content in assistant msg was reserved. Why?

Btw, default think demo puts think content in content, but k2-think (and many other models) expects think content in reasoning_content, could you pls offer an alternative demo?

@huggingfacejs-inference pls have a look

Sign up or log in to comment