Buckets:

hf-doc-build/doc-dev / trl /pr_5313 /en /chat_templates.html
download
raw
62.5 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Chat Templates&quot;,&quot;local&quot;:&quot;chat-templates&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Supported model families&quot;,&quot;local&quot;:&quot;supported-model-families&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Training templates&quot;,&quot;local&quot;:&quot;training-templates&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;cohere_training.jinja&quot;,&quot;local&quot;:&quot;coheretrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;cohere2_training.jinja&quot;,&quot;local&quot;:&quot;cohere2trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;deepseekv3_training.jinja&quot;,&quot;local&quot;:&quot;deepseekv3trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;gemma_training.jinja&quot;,&quot;local&quot;:&quot;gemmatrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;gemma3_training.jinja&quot;,&quot;local&quot;:&quot;gemma3trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;glm4moe_training.jinja&quot;,&quot;local&quot;:&quot;glm4moetrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;qwen3_training.jinja&quot;,&quot;local&quot;:&quot;qwen3trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;qwen3_vl_training.jinja&quot;,&quot;local&quot;:&quot;qwen3vltrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;gptoss_training.jinja&quot;,&quot;local&quot;:&quot;gptosstrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;idefics3_training.jinja&quot;,&quot;local&quot;:&quot;idefics3trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;lfm2_training.jinja&quot;,&quot;local&quot;:&quot;lfm2trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;llama3_training.jinja&quot;,&quot;local&quot;:&quot;llama3trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;llava_next_training.jinja&quot;,&quot;local&quot;:&quot;llavanexttrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;nemotron_3_nano_training.jinja&quot;,&quot;local&quot;:&quot;nemotron3nanotrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;nemotron_3_super_training.jinja&quot;,&quot;local&quot;:&quot;nemotron3supertrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;nemotron_3_ultra_training.jinja&quot;,&quot;local&quot;:&quot;nemotron3ultratrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;phi3_training.jinja&quot;,&quot;local&quot;:&quot;phi3trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;phi3_5_training.jinja&quot;,&quot;local&quot;:&quot;phi35trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;qwen2_5_training.jinja&quot;,&quot;local&quot;:&quot;qwen25trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;qwen2_5_vl_training.jinja&quot;,&quot;local&quot;:&quot;qwen25vltrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;qwen3_instruct_2507_training.jinja&quot;,&quot;local&quot;:&quot;qwen3instruct2507trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;qwen3_5_think_training.jinja / qwen3_5_nothink_training.jinja&quot;,&quot;local&quot;:&quot;qwen35thinktrainingjinja--qwen35nothinktrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;qwen3_6_training.jinja&quot;,&quot;local&quot;:&quot;qwen36trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Related utilities&quot;,&quot;local&quot;:&quot;related-utilities&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/>
<link href="/docs/trl/main/en/_app/immutable/entry/start.BZkqJbXc.js" rel="modulepreload">
<link href="/docs/trl/main/en/_app/immutable/chunks/Xx05pit2.js" rel="modulepreload">
<link href="/docs/trl/main/en/_app/immutable/chunks/Cgtr6oey.js" rel="modulepreload">
<link href="/docs/trl/main/en/_app/immutable/entry/app.CTLZrs8D.js" rel="modulepreload">
<link href="/docs/trl/main/en/_app/immutable/chunks/YRUHZxfA.js" rel="modulepreload">
<link href="/docs/trl/main/en/_app/immutable/chunks/CF2wz0qP.js" rel="modulepreload">
<link href="/docs/trl/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload">
<link href="/docs/trl/main/en/_app/immutable/chunks/B4jKbUu6.js" rel="modulepreload">
<link href="/docs/trl/main/en/_app/immutable/nodes/0.CD6H8d2I.js" rel="modulepreload">
<link href="/docs/trl/main/en/_app/immutable/chunks/B8yBvtRr.js" rel="modulepreload">
<link href="/docs/trl/main/en/_app/immutable/nodes/8.Dz180DJc.js" rel="modulepreload">
<link href="/docs/trl/main/en/_app/immutable/chunks/DMzrT19u.js" rel="modulepreload">
<!--zqk19n--><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Chat Templates&quot;,&quot;local&quot;:&quot;chat-templates&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Supported model families&quot;,&quot;local&quot;:&quot;supported-model-families&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Training templates&quot;,&quot;local&quot;:&quot;training-templates&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;cohere_training.jinja&quot;,&quot;local&quot;:&quot;coheretrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;cohere2_training.jinja&quot;,&quot;local&quot;:&quot;cohere2trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;deepseekv3_training.jinja&quot;,&quot;local&quot;:&quot;deepseekv3trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;gemma_training.jinja&quot;,&quot;local&quot;:&quot;gemmatrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;gemma3_training.jinja&quot;,&quot;local&quot;:&quot;gemma3trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;glm4moe_training.jinja&quot;,&quot;local&quot;:&quot;glm4moetrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;qwen3_training.jinja&quot;,&quot;local&quot;:&quot;qwen3trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;qwen3_vl_training.jinja&quot;,&quot;local&quot;:&quot;qwen3vltrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;gptoss_training.jinja&quot;,&quot;local&quot;:&quot;gptosstrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;idefics3_training.jinja&quot;,&quot;local&quot;:&quot;idefics3trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;lfm2_training.jinja&quot;,&quot;local&quot;:&quot;lfm2trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;llama3_training.jinja&quot;,&quot;local&quot;:&quot;llama3trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;llava_next_training.jinja&quot;,&quot;local&quot;:&quot;llavanexttrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;nemotron_3_nano_training.jinja&quot;,&quot;local&quot;:&quot;nemotron3nanotrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;nemotron_3_super_training.jinja&quot;,&quot;local&quot;:&quot;nemotron3supertrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;nemotron_3_ultra_training.jinja&quot;,&quot;local&quot;:&quot;nemotron3ultratrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;phi3_training.jinja&quot;,&quot;local&quot;:&quot;phi3trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;phi3_5_training.jinja&quot;,&quot;local&quot;:&quot;phi35trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;qwen2_5_training.jinja&quot;,&quot;local&quot;:&quot;qwen25trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;qwen2_5_vl_training.jinja&quot;,&quot;local&quot;:&quot;qwen25vltrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;qwen3_instruct_2507_training.jinja&quot;,&quot;local&quot;:&quot;qwen3instruct2507trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;qwen3_5_think_training.jinja / qwen3_5_nothink_training.jinja&quot;,&quot;local&quot;:&quot;qwen35thinktrainingjinja--qwen35nothinktrainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;qwen3_6_training.jinja&quot;,&quot;local&quot;:&quot;qwen36trainingjinja&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Related utilities&quot;,&quot;local&quot;:&quot;related-utilities&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/><!---->
<link href="/docs/trl/main/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg><!----></button></div> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="chat-templates" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#chat-templates"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Chat Templates</span></h1><!--]--><!----> <p>A <a href="https://huggingface.co/docs/transformers/en/chat_templating" rel="nofollow">chat template</a> is a Jinja2 snippet that formats messages into the string a model was trained on. For example:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;Qwen/Qwen2-0.5B-Instruct&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.chat_template
<span class="hljs-string">&quot;{% for message in messages %}{% if loop.first and messages[0][&#x27;role&#x27;] != &#x27;system&#x27; %}{{ &#x27;&lt;|im_start|&gt;system\nYou are a helpful assistant.&lt;|im_end|&gt;\n&#x27; }}{% endif %}{{&#x27;&lt;|im_start|&gt;&#x27; + message[&#x27;role&#x27;] + &#x27;\n&#x27; + message[&#x27;content&#x27;] + &#x27;&lt;|im_end|&gt;&#x27; + &#x27;\n&#x27;}}{% endfor %}{% if add_generation_prompt %}{{ &#x27;&lt;|im_start|&gt;assistant\n&#x27; }}{% endif %}&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.apply_chat_template([{<span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;user&quot;</span>, <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;Hi!&quot;</span>}], tokenize=<span class="hljs-literal">False</span>)
<span class="hljs-string">&#x27;&lt;|im_start|&gt;system\nYou are a helpful assistant.&lt;|im_end|&gt;\n&lt;|im_start|&gt;user\nHi!&lt;|im_end|&gt;\n&#x27;</span><!----></pre></div><!----> <p>In most cases you don’t need to worry about chat templates: models ship their template along with the tokenizer, and TRL applies it for you. The whole thing is transparent. But some TRL recipes rely on features that most shipped templates don’t include:</p> <ul><li><strong>SFT with <code>assistant_only_loss=True</code></strong> needs <code>{% generation %}</code> / <code>{% endgeneration %}</code> markers around assistant output, so the loss mask can target only assistant tokens.</li> <li><strong>GRPO with tool calls</strong> needs the template to be <em>prefix-preserving</em>: appending a tool message must not change how earlier messages are rendered.</li></ul> <p>TRL ships patched templates under <a href="https://github.com/huggingface/trl/tree/main/trl/chat_templates" rel="nofollow"><code>trl/chat_templates/</code></a> for common families (Qwen, Llama, DeepSeek-V3, GPT-OSS, …) and swaps them in automatically for supported models. For any other model, you’ll need to patch its template yourself. The rest of this page catalogs what’s bundled.</p> <!--[1--><h2 class="relative group"><a id="supported-model-families" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#supported-model-families"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Supported model families</span></h2><!--]--><!----> <p>TRL stores reference copies of the original templates so it can identify supported models at init and swap in a training template when needed. The following families are recognized: Cohere, Cohere2, DeepSeek-V3, Gemma, Gemma3, Gemma4, GLM-4-MoE, GPT-OSS, Idefics3, LFM2, LFM2.5, Llama 3 / 3.1 / 3.2, Llava-Next, Nemotron 3 (Nano, Super, Ultra), Phi-3, Phi-3.5, Qwen2-VL, Qwen2.5, Qwen2.5-VL, Qwen3 (including the Instruct-2507 variant), Qwen3-VL, Qwen3.5, Qwen3.6.</p> <!--[1--><h2 class="relative group"><a id="training-templates" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#training-templates"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Training templates</span></h2><!--]--><!----> <p>Patched templates that fix training-specific issues. Swapped in at init when tools are enabled (GRPO) or when <code>assistant_only_loss=True</code> (SFT).</p> <!--[2--><h3 class="relative group"><a id="coheretrainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#coheretrainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>cohere_training.jinja</span></h3><!--]--><!----> <p>Patched Cohere template. Diff vs <code>cohere.jinja</code>:</p> <p>Wrap assistant message output with <code>{% generation %}</code> / <code>{% endgeneration %}</code> so that <code>return_assistant_tokens_mask=True</code> produces correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="cohere2trainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#cohere2trainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>cohere2_training.jinja</span></h3><!--]--><!----> <p>Patched Cohere2 template. Diff vs <code>cohere2.jinja</code>:</p> <p>Move the trailing <code>&lt;|END_OF_TURN_TOKEN|></code> from after the role-dispatch <code>{% endif %}</code> into each role branch, and wrap the assistant branch (<code>&lt;|START_RESPONSE|>...&lt;|END_RESPONSE|>&lt;|END_OF_TURN_TOKEN|></code>) with <code>{% generation %}</code> / <code>{% endgeneration %}</code> so that <code>return_assistant_tokens_mask=True</code> produces correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="deepseekv3trainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#deepseekv3trainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>deepseekv3_training.jinja</span></h3><!--]--><!----> <p>Patched DeepSeek-V3 template. Diff vs <code>deepseekv3.jinja</code>:</p> <ul><li>Uses <code>| tojson</code> on <code>tool['function']['arguments']</code> so that <code>arguments</code> can be passed as a <code>dict</code> (the documented format per <a href="https://huggingface.co/docs/transformers/en/chat_extras#tool-calling-example" rel="nofollow">transformers docs</a>). The original template uses raw string concatenation, which crashes on dict inputs.</li> <li>Wraps assistant message output with <code>{% generation %}</code> / <code>{% endgeneration %}</code> markers for SFT assistant-only loss.</li></ul> <!--[2--><h3 class="relative group"><a id="gemmatrainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#gemmatrainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>gemma_training.jinja</span></h3><!--]--><!----> <p>Patched Gemma template (shared by Gemma and Gemma2, which ship identical chat templates). Diff vs <code>gemma.jinja</code>:</p> <p>Split the unified assistant output so that the <code>&lt;start_of_turn>model\n</code> header (a prompt cue, not generated by the model) sits outside the generation block, and wrap the assistant content with <code>{% generation %}</code> / <code>{% endgeneration %}</code> markers for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="gemma3trainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#gemma3trainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>gemma3_training.jinja</span></h3><!--]--><!----> <p>Patched Gemma 3 template. Same diff as <code>gemma_training.jinja</code> (split the unified output line into role-specific branches so the <code>&lt;start_of_turn>model\n</code> prompt cue sits outside the generation block, and wrap the assistant content with <code>{% generation %}</code> / <code>{% endgeneration %}</code>), applied to the Gemma 3 base template that supports system messages and multimodal content blocks.</p> <!--[2--><h3 class="relative group"><a id="glm4moetrainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#glm4moetrainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>glm4moe_training.jinja</span></h3><!--]--><!----> <p>Patched GLM-4-MoE template. Diff vs <code>glm4moe.jinja</code>:</p> <p>Require both <code>&lt;think></code> and <code>&lt;/think></code> to be present before parsing, to avoid incorrect splitting when the model generates only one tag:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-diff "><!----><span class="hljs-deletion">- {%- if &#x27;&lt;/think&gt;&#x27; in content %}</span>
<span class="hljs-addition">+ {%- if &#x27;&lt;think&gt;&#x27; in content and &#x27;&lt;/think&gt;&#x27; in content %}</span><!----></pre></div><!----> <p>Wrap assistant message output (including the thinking block and tool calls) with <code>{% generation %}</code> / <code>{% endgeneration %}</code> markers for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="qwen3trainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#qwen3trainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>qwen3_training.jinja</span></h3><!--]--><!----> <p>Patched Qwen3 template. Diff vs <code>qwen3.jinja</code>:</p> <p>Require both <code>&lt;think></code> and <code>&lt;/think></code> to be present before parsing, to avoid incorrect splitting when the model generates only one tag:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-diff "><!----><span class="hljs-deletion">- {%- if &#x27;&lt;/think&gt;&#x27; in content %}</span>
<span class="hljs-addition">+ {%- if &#x27;&lt;think&gt;&#x27; in content and &#x27;&lt;/think&gt;&#x27; in content %}</span><!----></pre></div><!----> <p>Always include the thinking block regardless of message position. The original conditionally omits it based on <code>loop.last</code>, which changes the assistant rendering when a tool message is appended, breaking prefix-preservation:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-diff "><!----><span class="hljs-deletion">- {%- if loop.index0 &gt; ns.last_query_index %}</span>
<span class="hljs-deletion">- {%- if loop.last or (not loop.last and reasoning_content) %}</span>
<span class="hljs-deletion">- {{- &#x27;&lt;|im_start|&gt;&#x27; + message.role + &#x27;\n&lt;think&gt;\n&#x27; + reasoning_content.strip(&#x27;\n&#x27;) + &#x27;\n&lt;/think&gt;\n\n&#x27; + content.lstrip(&#x27;\n&#x27;) }}</span>
<span class="hljs-deletion">- {%- else %}</span>
<span class="hljs-deletion">- {{- &#x27;&lt;|im_start|&gt;&#x27; + message.role + &#x27;\n&#x27; + content }}</span>
<span class="hljs-deletion">- {%- endif %}</span>
<span class="hljs-deletion">- {%- else %}</span>
<span class="hljs-deletion">- {{- &#x27;&lt;|im_start|&gt;&#x27; + message.role + &#x27;\n&#x27; + content }}</span>
<span class="hljs-deletion">- {%- endif %}</span>
<span class="hljs-addition">+ {{- &#x27;&lt;|im_start|&gt;&#x27; + message.role + &#x27;\n&lt;think&gt;\n&#x27; + reasoning_content.strip(&#x27;\n&#x27;) + &#x27;\n&lt;/think&gt;\n\n&#x27; + content.lstrip(&#x27;\n&#x27;) }}</span><!----></pre></div><!----> <p>Wrap assistant message output with <code>{% generation %}</code> / <code>{% endgeneration %}</code> so that <code>return_assistant_tokens_mask=True</code> produces correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="qwen3vltrainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#qwen3vltrainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>qwen3_vl_training.jinja</span></h3><!--]--><!----> <p>Patched Qwen3-VL template. Diff vs <code>qwen3_vl.jinja</code>:</p> <p>Wrap assistant message output (both <code>content</code> and <code>tool_calls</code>) with <code>{% generation %}</code> / <code>{% endgeneration %}</code> so that <code>return_assistant_tokens_mask=True</code> produces correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="gptosstrainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#gptosstrainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>gptoss_training.jinja</span></h3><!--]--><!----> <p>Patched GPT-OSS template. Diff vs <code>gptoss.jinja</code>:</p> <p>Wrap assistant message output with <code>{% generation %}</code> / <code>{% endgeneration %}</code> so that <code>return_assistant_tokens_mask=True</code> produces correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="idefics3trainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#idefics3trainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>idefics3_training.jinja</span></h3><!--]--><!----> <p>Patched Idefics3 template. Diff vs <code>idefics3.jinja</code>:</p> <p>Split the assistant message into its own branch so the <code>{% generation %}</code> / <code>{% endgeneration %}</code> markers wrap the assistant content. This enables <code>return_assistant_tokens_mask=True</code> to produce correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="lfm2trainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#lfm2trainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>lfm2_training.jinja</span></h3><!--]--><!----> <p>Patched LFM2 template. Diff vs <code>lfm2.jinja</code>:</p> <p>Split the unified message output line into role-specific branches, so the <code>&lt;|im_start|>assistant\n</code> prompt cue sits outside the generation block (it is not generated by the model), while the assistant’s content and <code>&lt;|im_end|>\n</code> (which the model must learn to produce and to stop on) sit inside. Wrap the assistant content with <code>{% generation %}</code> / <code>{% endgeneration %}</code> so that <code>return_assistant_tokens_mask=True</code> produces correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="llama3trainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#llama3trainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>llama3_training.jinja</span></h3><!--]--><!----> <p>Patched Llama 3 template. Diff vs <code>llama3.jinja</code>:</p> <p>Wrap assistant message output with <code>{% generation %}</code> / <code>{% endgeneration %}</code> so that <code>return_assistant_tokens_mask=True</code> produces correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="llavanexttrainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#llavanexttrainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>llava_next_training.jinja</span></h3><!--]--><!----> <p>Patched Llava-Next template. Diff vs <code>llava_next.jinja</code>:</p> <p>Wrap assistant message output with <code>{% generation %}</code> / <code>{% endgeneration %}</code> so that <code>return_assistant_tokens_mask=True</code> produces correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="nemotron3nanotrainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#nemotron3nanotrainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>nemotron_3_nano_training.jinja</span></h3><!--]--><!----> <p>Patched Nemotron Nano template. Diff vs <code>nemotron_3_nano.jinja</code>: the original is already prefix-preserving, so the only change is wrapping assistant message output with <code>{% generation %}</code> / <code>{% endgeneration %}</code> so that <code>return_assistant_tokens_mask=True</code> produces correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="nemotron3supertrainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#nemotron3supertrainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>nemotron_3_super_training.jinja</span></h3><!--]--><!----> <p>Patched Nemotron Super template. Diff vs <code>nemotron_3_super.jinja</code>: same as <code>nemotron_3_nano_training.jinja</code> — the original is already prefix-preserving, so the only change is wrapping assistant message output with <code>{% generation %}</code> / <code>{% endgeneration %}</code> so that <code>return_assistant_tokens_mask=True</code> produces correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="nemotron3ultratrainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#nemotron3ultratrainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>nemotron_3_ultra_training.jinja</span></h3><!--]--><!----> <p>Patched Nemotron Ultra template. Diff vs <code>nemotron_3_ultra.jinja</code>: same as <code>nemotron_3_nano_training.jinja</code> — the original is already prefix-preserving, so the only change is wrapping assistant message output with <code>{% generation %}</code> / <code>{% endgeneration %}</code> so that <code>return_assistant_tokens_mask=True</code> produces correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="phi3trainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#phi3trainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>phi3_training.jinja</span></h3><!--]--><!----> <p>Patched Phi-3 template. Diff vs <code>phi3.jinja</code>:</p> <p>Wrap assistant message output with <code>{% generation %}</code> / <code>{% endgeneration %}</code> so that <code>return_assistant_tokens_mask=True</code> produces correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="phi35trainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#phi35trainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>phi3_5_training.jinja</span></h3><!--]--><!----> <p>Patched Phi-3.5 template. Diff vs <code>phi3_5.jinja</code>:</p> <p>Wrap assistant message output with <code>{% generation %}</code> / <code>{% endgeneration %}</code> so that <code>return_assistant_tokens_mask=True</code> produces correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="qwen25trainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#qwen25trainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>qwen2_5_training.jinja</span></h3><!--]--><!----> <p>Patched Qwen2.5 template. Diff vs <code>qwen2_5.jinja</code>:</p> <p>Wrap assistant message output with <code>{% generation %}</code> / <code>{% endgeneration %}</code> so that <code>return_assistant_tokens_mask=True</code> produces correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="qwen25vltrainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#qwen25vltrainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>qwen2_5_vl_training.jinja</span></h3><!--]--><!----> <p>Patched Qwen2.5-VL template (also used for Qwen2-VL, which ships a byte-identical template). Diff vs <code>qwen2_5_vl.jinja</code>:</p> <p>Split the assistant message into its own branch so the <code>{% generation %}</code> / <code>{% endgeneration %}</code> markers wrap the assistant content. This enables <code>return_assistant_tokens_mask=True</code> to produce correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="qwen3instruct2507trainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#qwen3instruct2507trainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>qwen3_instruct_2507_training.jinja</span></h3><!--]--><!----> <p>Patched Qwen3-Instruct-2507 template (used by models like <code>Qwen3-4B-Instruct-2507</code>, which ship a simpler Qwen3 variant without <code>reasoning_content</code> / <code>&lt;think></code> parsing, <code>multi_step_tool</code> tracking, or the <code>enable_thinking</code> flag). Diff vs <code>qwen3_instruct_2507.jinja</code>:</p> <p>Wrap assistant message output with <code>{% generation %}</code> / <code>{% endgeneration %}</code> so that <code>return_assistant_tokens_mask=True</code> produces correct masks for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="qwen35thinktrainingjinja--qwen35nothinktrainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#qwen35thinktrainingjinja--qwen35nothinktrainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>qwen3_5_think_training.jinja / qwen3_5_nothink_training.jinja</span></h3><!--]--><!----> <p>Patched Qwen3.5 templates, shared logic across both flavors (they differ only in the default value of the <code>enable_thinking</code> flag — <code>qwen3_5_think_training.jinja</code> defaults to thinking enabled, used by Qwen3.5-4B and larger; <code>qwen3_5_nothink_training.jinja</code> defaults to thinking disabled, used by Qwen3.5-2B and smaller). Diff vs <code>qwen3_5_think.jinja</code> / <code>qwen3_5_nothink.jinja</code>: same set of changes as <code>qwen3_training.jinja</code> — require both <code>&lt;think></code> and <code>&lt;/think></code> to be present before parsing, drop the <code>loop.index0 > ns.last_query_index</code> conditional so the thinking block is always emitted (prefix-preservation), and wrap assistant output with <code>{% generation %}</code> / <code>{% endgeneration %}</code> markers for SFT assistant-only loss.</p> <!--[2--><h3 class="relative group"><a id="qwen36trainingjinja" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#qwen36trainingjinja"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>qwen3_6_training.jinja</span></h3><!--]--><!----> <p>Patched Qwen3.6 template. Diff vs <code>qwen3_6.jinja</code>: same set of changes as <code>qwen3_training.jinja</code> — require both <code>&lt;think></code> and <code>&lt;/think></code> to be present before parsing, drop the <code>loop.index0 > ns.last_query_index</code> conditional so the thinking block is always emitted (prefix-preservation), and wrap assistant output with <code>{% generation %}</code> / <code>{% endgeneration %}</code> markers for SFT assistant-only loss.</p> <!--[1--><h2 class="relative group"><a id="related-utilities" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#related-utilities"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Related utilities</span></h2><!--]--><!----> <p>See <a href="chat_template_utils">Chat Template Utilities</a> for the helper functions (<a href="/docs/trl/pr_5313/en/chat_template_utils#trl.clone_chat_template">clone_chat_template()</a>, <code>is_chat_template_prefix_preserving</code>, <a href="/docs/trl/pr_5313/en/chat_template_utils#trl.get_training_chat_template">get_training_chat_template()</a>) that operate on these templates.</p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/trl/blob/main/docs/source/chat_templates.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg><!----> <span><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]-->
<script>
{
__sveltekit_1to0zqp = {
base: "/docs/trl/main/en",
assets: "/docs/trl/main/en"
};
const element = document.currentScript.parentElement;
Promise.all([
import("/docs/trl/main/en/_app/immutable/entry/start.BZkqJbXc.js"),
import("/docs/trl/main/en/_app/immutable/entry/app.CTLZrs8D.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 8],
data: [null,null],
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
62.5 kB
·
Xet hash:
f492cb0a5e2ad4725369b45d9d88cc1919b726cac278a83199bb82f7d2410efe

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.