Chat template is too restrictive
This part of the chat template is too restrictive
{#- This block checks for alternating user/assistant messages, skipping tool calling messages #}
{%- set ns = namespace() %}
{%- set ns.index = 0 %}
{%- for message in loop_messages %}
{%- if not (message.role == "tool" or message.role == "tool_results" or (message.tool_calls is defined and message.tool_calls is not none)) %}
{%- if (message["role"] == "user") != (ns.index % 2 == 0) %}
{{- raise_exception("After the optional system message, conversation roles must alternate user/assistant/user/assistant/...") }}
{%- endif %}
{%- set ns.index = ns.index + 1 %}
{%- endif %}
{%- endfor %}
I keep hitting it in vllm using ChatterUI as a frontend even on an empty chat.
Furthermore the check for ns.index % 2 == 0 is fragile and the conversation can be setup with an set initial assistant message.
I hit this on MarsupialAI/Monstral-123B-v2 as well, it seems like it's automatically extracted from tokenizer_config.json: https://huggingface.co/MarsupialAI/Monstral-123B-v2/blob/main/tokenizer_config.json#L6176
And looking at Largestral-2411 the chat template does not have the restriction https://huggingface.co/mistralai/Mistral-Large-Instruct-2411/blob/main/tokenizer_config.json#L6177
So I assume it's a Largestral-2407 unfortunate restriction.
Anyway problem solved, it's from upstream and people can workaround by supplying a custom chat-template with --chat-template path/to/chat_template.jinja with vLLM.