Text Generation
Transformers
Safetensors
English
olmo3
conversational

chat template: strip out `assistant\n`?

#4
by owao - opened

Hey guys, I don't know if what I did is right, but I needed to get rid of the assistant\n prefix for each responses.
Despite being a minimal change, just adding .lstrip("assistant\n"), I have no idea if this is a good solution. Adapting those jinja templates drive me mad every single time, so the less I deal with them the better I feel lol.

In all case, thanks for offering the fruit of your work to the community! The fully open model gap has finally been filled πŸ™ And I'm thrilled to try it out now :)

Hey! There is a an argument to apply_chat_template called add_generation_prompt. if you set add_generation_prompt=False it will not append "assistant\n" to each set of messages.
https://huggingface.co/docs/transformers/en/chat_templating#using-applychattemplate

It works based on this conditional in the template:

...
' }}{% endif %}{% if loop.last and add_generation_prompt %}{{ '<|im_start|>assistant
<think>' }}{% endif %}{% endfor %}

Thanks for your answer!

I read the doc part you pointed to, and I know get the purpose of add_generation_prompt. But I'm still confused...
So, I understand that the purpose of add_generation_prompt is to prepend the next generation with the right token so that the model "knows" it's its turn, to prevent it from continuing the user message instead of answering.

And from what I understand, in your case you are using the add_generation_prompt conditionnal to prepend the model generation with <|im_start|>assistant\n<think> when true instead of <|im_start|>assistant\n when false.
And so I'm confused because this conditionnal seems to only control if <think> is added or not, but the assistant\n part seems to always be there.

I forgot to mention I'm serving your model quantized through llama.cpp. add_generation_prompt is set client side when sending the request, with "chat_template_kwargs": {"add_generation_prompt": true/false}.

But this is where my brain just crashes, here is what I get:

  • with "add_generation_prompt": true, the model generation starts with <|im_start|> and I directly see its CoT without any <think> or assistant\n
  • with "add_generation_prompt": false, the model generation starts with <|im_start|>assistant\n<think> then its CoT

In other words, I never get the behavior I want (starting by <|im_start|><think>).

And when I try to force the add_generation_prompt behavior, removing assistant\n like so:

    {%- if loop.last and add_generation_prompt -%}
        {{- "<|im_start|><think>" -}}

Then, with "add_generation_prompt": true, same as before: the model generation starts with <|im_start|> and I directly see its CoT without any <think> or assistant\n.

I don't know what's going on I'm so lost with those templates logic every single time. And that's hard to figure out what I don't understand wrong using help from LMs because feeding them with such templates often interfere with their own template thats ironic and frustrating :D That's really one of the rare cases you can't get help from them!

Again, thanks for your answer already, and don't worry if you don't feel like pursuing with my case lol one day I'll figure this out!

Ready to merge
This branch is ready to get merged automatically.

Sign up or log in to comment