{#- ChatML template with assistant-generation markers (transformers convention): wrapping the assistant turn in {% generation %}...{% endgeneration %} lets apply_chat_template(..., return_assistant_tokens_mask=True) mark the assistant tokens so assistant_only_loss masks the prompt. Assistant content is passed through verbatim, so the ... trace in the data is preserved. A math system prompt is injected (own wording); a caller-supplied system message, if any, is appended after it. #} {%- set enable_thinking = true -%} {%- set sys_instruction = "You are a mathematics problem solver. Work through each problem with brief, focused reasoning: show only the steps that matter, keeping it short when a short path suffices and taking more space only when the problem genuinely needs it. Give the final answer exactly once, enclosed in \\boxed{...}, as the final value in exact form. Put nothing else inside the box (no words, units, or working), and write nothing after it." -%} {%- if messages|length > 0 and messages[0]['role'] == 'system' %} {{- '<|im_start|>system\n' + sys_instruction + '\n\n' + messages[0]['content'] + '<|im_end|>\n' }} {%- set loop_messages = messages[1:] %} {%- else %} {{- '<|im_start|>system\n' + sys_instruction + '<|im_end|>\n' }} {%- set loop_messages = messages %} {%- endif %} {%- for message in loop_messages %} {%- if message['role'] == 'assistant' %} {{- '<|im_start|>assistant\n' }}{% generation %}{{ message['content'] }}{{ '<|im_end|>' }}{% endgeneration %}{{ '\n' }} {%- else %} {{- '<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>\n' }} {%- endif %} {%- endfor %} {%- if add_generation_prompt %} {{- '<|im_start|>assistant\n' }} {%- endif %}