Safetensors
French
English
nemotron
openllm-france

Add preserve_thinking option to the chat template

#1
OpenLLM France org

This adds a preserve_thinking parameter to the chat template, controlling whether <think>…</think> reasoning blocks from previous assistant turns are kept when formatting a multi-turn conversation.

  • Default: preserve_thinking = true — reasoning is kept in every assistant turn, exactly as before. The rendered output is unchanged for existing callers (verified byte-identical on multi-turn conversations, with and without a generation prompt).
  • preserve_thinking = false — reasoning is removed from all assistant turns preceding the last user message; only the most recent turn keeps its <think> block. This shortens the prompt and reduces the KV-cache footprint in multi-turn settings. The mechanism reuses the template's existing last_query_index logic, matching the behavior introduced in Qwen3.6.

Usage:

tokenizer.apply_chat_template(messages, preserve_thinking=False, ...)

or, when serving (e.g. vLLM), pass it through chat_template_kwargs={"preserve_thinking": false}.

Jeronymous changed pull request status to merged

Sign up or log in to comment