Skip to content

Bug: format_jinja() hardcodes eos_token="", stripping </s> from all Mistral chat templates and causing multi-turn loops #2644

Open

Description

@jdstrohl

Totally sorry if we're wrong about this. My buddy, Hal, found this. Also, sorry if this is already known.

In koboldcpp.py inside format_jinja() (around line 3834–3836), jinja_compiled_template.render() hardcodes bos_token="" and eos_token="":

text = jinja_compiled_template.render(
    messages=messages_for_render,
    add_generation_prompt=True,
    bos_token="",
    eos_token="",
    **chat_template_kwargs
)

Why this breaks all Mistral models (Mistral-7B, Ministral-8B, Mistral-Small, Mistral-Large)

Unlike Qwen (<|im_end|>) or Gemma (<end_of_turn>), which hardcode their end-of-turn literals directly in the Jinja string, Mistral's official Hugging Face chat_template uses the eos_token variable at the end of every assistant turn:

{%- elif message["role"] == "assistant" %}
    {{- message["content"] + eos_token }}

Because format_jinja() passes eos_token="", every assistant reply in multi-turn history has its </s> (token ID 2) stripped ([/INST]assistant reply[INST]next user msg[/INST]). In multi-turn chat, seeing 10+ historical turns with zero </s> tokens conditions the model to never emit </s>, causing runaway paragraph looping and failure to stop.

Verification / Fix

Replacing eos_token with the literal '</s>' in a custom jinjatemplate (or passing the model's actual EOS token string into jinja_compiled_template.render()) immediately restores token ID 2 between turns and triggers (EOS token triggered! ID:2) cleanly without looping.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions