Skip to content

Pass the loaded model's EOS token to Jinja chat templates - #2665

Merged
LostRuins merged 1 commit into
LostRuins:concedo_experimentalfrom
barkly1te:fix/jinja-eos-from-model
Nov 23, 2026
Merged

LostRuins merged 1 commit into
LostRuins:concedo_experimentalfrom
barkly1te:fix/jinja-eos-from-model

Conversation

@barkly1te

Copy link
Copy Markdown

Fixes #2644.

KoboldCpp passed an empty eos_token to Jinja even when the model vocabulary defined one. Templates such as Mistral Instruct v0.3 use eos_token to close prior assistant turns, so the generated prompt joined the assistant reply directly to the next turn.

The native model adapter now reads the loaded GGUF vocabulary's EOS token and exposes its text, including special tokens. Python caches that text at model load and supplies it to both Jinja rendering paths. Older native libraries and model formats that do not expose EOS text keep the existing empty fallback.

Local verification

  • Ran the two regression cases against the issue's original code. Both failed because the rendered history was missing </s>. The cases cover templates invoked with and without tools.
  • python -m unittest discover -s tests -p 'test_*.py' -v passed all 11 tests after the fix.
  • make -j20 koboldcpp_default passed and produced a library that exports get_eos_token_text.
  • Started the rebuilt CPU server with --jinja --debugmode 1 and a locally generated one-layer Mistral GGUF using the Mistral-7B-Instruct-v0.3 tokenizer and chat template. A user–assistant–user request to /v1/chat/completions returned HTTP 200 with 16 prompt tokens and one completion token. The vocabulary log reported EOS token 2 as </s>, and the tokenization log showed [INST] First question[/INST] First answer</s>[INST] Follow-up[/INST]. This checks the chat prompt path with synthetic model weights.
  • git diff --check passed.

@LostRuins
LostRuins changed the base branch from concedo to concedo_experimental November 23, 2026 13:35
@LostRuins
LostRuins merged commit f0fc02b into LostRuins:concedo_experimental Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants