Update to simple question/answer pretraining template (all tokens trainable)
Browse files- chat_template.jinja +9 -209
- tokenizer_config.json +1 -1
chat_template.jinja
CHANGED
|
@@ -1,211 +1,11 @@
|
|
| 1 |
-
{
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
{%- endif %}
|
| 11 |
-
{% endmacro %}
|
| 12 |
-
{%- set kw = chat_template_kwargs if chat_template_kwargs is defined else {} %}
|
| 13 |
-
{%- set enable_thinking = kw.enable_thinking if kw.enable_thinking is defined else True %}
|
| 14 |
-
{%- set reasoning_budget = kw.reasoning_budget if kw.reasoning_budget is defined else None %}
|
| 15 |
-
{%- set truncate_history_thinking = kw.truncate_history_thinking if kw.truncate_history_thinking is defined else True %}
|
| 16 |
-
{%- set response_format = kw.response_format if kw.response_format is defined else None %}
|
| 17 |
-
|
| 18 |
-
{%- set ns = namespace(last_user_idx = -1) %}
|
| 19 |
-
{%- set loop_messages = messages %}
|
| 20 |
-
{%- for m in loop_messages %}
|
| 21 |
-
{%- if m["role"] == "user" %}
|
| 22 |
-
{%- set ns.last_user_idx = loop.index0 %}
|
| 23 |
-
{%- endif %}
|
| 24 |
-
{%- endfor %}
|
| 25 |
-
|
| 26 |
-
{%- if messages[0]["role"] == "system" %}
|
| 27 |
-
{%- set system_message = messages[0]["content"] %}
|
| 28 |
-
{%- set loop_messages = messages[1:] %}
|
| 29 |
-
{%- else %}
|
| 30 |
-
{%- set system_message = "" %}
|
| 31 |
-
{%- set loop_messages = messages %}
|
| 32 |
-
{%- endif %}
|
| 33 |
-
{%- if not tools is defined %}
|
| 34 |
-
{%- set tools = [] %}
|
| 35 |
{%- endif %}
|
| 36 |
-
{# Recompute last_user_idx relative to loop_messages after handling system #}
|
| 37 |
-
{%- set ns = namespace(last_user_idx = -1) %}
|
| 38 |
-
{%- for m in loop_messages %}
|
| 39 |
-
{%- if m["role"] == "user" %}
|
| 40 |
-
{%- set ns.last_user_idx = loop.index0 %}
|
| 41 |
-
{%- endif %}
|
| 42 |
{%- endfor %}
|
| 43 |
-
{%- if system_message is defined %}
|
| 44 |
-
{{- "<|im_start|>system\n" + system_message }}
|
| 45 |
-
{%- else %}
|
| 46 |
-
{%- if tools is iterable and tools | length > 0 %}
|
| 47 |
-
{{- "<|im_start|>system\n" }}
|
| 48 |
-
{%- endif %}
|
| 49 |
-
{%- endif %}
|
| 50 |
-
{%- if tools is iterable and tools | length > 0 %}
|
| 51 |
-
{%- if system_message is defined and system_message | length > 0 %}
|
| 52 |
-
{{- "\n\n" }}
|
| 53 |
-
{%- endif %}
|
| 54 |
-
{{- "# Tools\n\nYou have access to the following functions:\n\n" }}
|
| 55 |
-
{{- "<tools>" }}
|
| 56 |
-
{%- for tool in tools %}
|
| 57 |
-
{%- if tool.function is defined %}
|
| 58 |
-
{%- set tool = tool.function %}
|
| 59 |
-
{%- endif %}
|
| 60 |
-
{{- "\n<function>\n<name>" ~ tool.name ~ "</name>" }}
|
| 61 |
-
{%- if tool.description is defined %}
|
| 62 |
-
{{- '\n<description>' ~ (tool.description | trim) ~ '</description>' }}
|
| 63 |
-
{%- endif %}
|
| 64 |
-
{{- '\n<parameters>' }}
|
| 65 |
-
{%- if tool.parameters is defined and tool.parameters is mapping and tool.parameters.properties is defined and tool.parameters.properties is mapping %}
|
| 66 |
-
{%- for param_name, param_fields in tool.parameters.properties|items %}
|
| 67 |
-
{{- '\n<parameter>' }}
|
| 68 |
-
{{- '\n<name>' ~ param_name ~ '</name>' }}
|
| 69 |
-
{%- if param_fields.type is defined %}
|
| 70 |
-
{{- '\n<type>' ~ (param_fields.type | string) ~ '</type>' }}
|
| 71 |
-
{%- endif %}
|
| 72 |
-
{%- if param_fields.description is defined %}
|
| 73 |
-
{{- '\n<description>' ~ (param_fields.description | trim) ~ '</description>' }}
|
| 74 |
-
{%- endif %}
|
| 75 |
-
{%- if param_fields.enum is defined %}
|
| 76 |
-
{{- '\n<enum>' ~ (param_fields.enum | tojson | safe) ~ '</enum>' }}
|
| 77 |
-
{%- endif %}
|
| 78 |
-
{%- set handled_keys = ['name', 'type', 'description', 'enum'] %}
|
| 79 |
-
{{- render_extra_keys(param_fields, handled_keys) }}
|
| 80 |
-
{{- '\n</parameter>' }}
|
| 81 |
-
{%- endfor %}
|
| 82 |
-
{%- endif %}
|
| 83 |
-
{% set handled_keys = ['type', 'properties', 'required'] %}
|
| 84 |
-
{{- render_extra_keys(tool.parameters, handled_keys) }}
|
| 85 |
-
{%- if tool.parameters is defined and tool.parameters.required is defined %}
|
| 86 |
-
{{- '\n<required>' ~ (tool.parameters.required | tojson | safe) ~ '</required>' }}
|
| 87 |
-
{%- endif %}
|
| 88 |
-
{{- '\n</parameters>' }}
|
| 89 |
-
{%- set handled_keys = ['type', 'name', 'description', 'parameters'] %}
|
| 90 |
-
{{- render_extra_keys(tool, handled_keys) }}
|
| 91 |
-
{{- '\n</function>' }}
|
| 92 |
-
{%- endfor %}
|
| 93 |
-
{{- "\n</tools>" }}
|
| 94 |
-
|
| 95 |
-
{{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
|
| 96 |
-
{%- endif %}
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
{%- if system_message is defined %}
|
| 100 |
-
{{- '<|im_end|>\n' }}
|
| 101 |
-
{%- else %}
|
| 102 |
-
{%- if tools is iterable and tools | length > 0 %}
|
| 103 |
-
{{- '<|im_end|>\n' }}
|
| 104 |
-
{%- endif %}
|
| 105 |
-
{%- endif %}
|
| 106 |
-
|
| 107 |
-
{%- for message in loop_messages %}
|
| 108 |
-
{%- if message.role == "assistant" %}
|
| 109 |
-
{# Add reasoning content in to content field for unified processing below. #}
|
| 110 |
-
{%- if message.reasoning_content is defined and message.reasoning_content is string and message.reasoning_content | trim | length > 0 %}
|
| 111 |
-
{%- set content = "<think>\n" ~ message.reasoning_content ~ "\n</think>\n" ~ (message.content | default('', true)) %}
|
| 112 |
-
{%- else %}
|
| 113 |
-
{%- set content = message.content | default('', true) %}
|
| 114 |
-
{%- if content is string -%}
|
| 115 |
-
{# Allow downstream logic to to take care of broken thought, only handle coherent reasoning here. #}
|
| 116 |
-
{%- if '<think>' not in content and '</think>' not in content -%}
|
| 117 |
-
{%- set content = "<think></think>" ~ content -%}
|
| 118 |
-
{%- endif -%}
|
| 119 |
-
{%- else -%}
|
| 120 |
-
{%- set content = content -%}
|
| 121 |
-
{%- endif -%}
|
| 122 |
-
{%- endif %}
|
| 123 |
-
{%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 %}
|
| 124 |
-
{# Assistant message has tool calls. #}
|
| 125 |
-
{{- '<|im_start|>assistant\n' }}{% generation %}
|
| 126 |
-
{%- set include_content = not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
|
| 127 |
-
{%- if content is string and content | trim | length > 0 %}
|
| 128 |
-
{%- if include_content %}
|
| 129 |
-
{{- (content | trim) ~ '\n' -}}
|
| 130 |
-
{%- else %}
|
| 131 |
-
{%- set c = (content | string) %}
|
| 132 |
-
{%- if '</think>' in c %}
|
| 133 |
-
{# Keep only content after the last closing think. Also generation prompt causes this. #}
|
| 134 |
-
{%- set c = c.split('</think>')[-1] %}
|
| 135 |
-
{%- elif '<think>' in c %}
|
| 136 |
-
{# If <think> was opened but never closed, drop the trailing think segment #}
|
| 137 |
-
{%- set c = c.split('<think>')[0] %}
|
| 138 |
-
{%- endif %}
|
| 139 |
-
{%- set c = "<think></think>" ~ c | trim %}
|
| 140 |
-
{%- if c | length > 0 %}
|
| 141 |
-
{{- c ~ '\n' -}}
|
| 142 |
-
{%- endif %}
|
| 143 |
-
{%- endif %}
|
| 144 |
-
{%- else %}
|
| 145 |
-
{{- "<think></think>" -}}
|
| 146 |
-
{%- endif %}
|
| 147 |
-
{%- for tool_call in message.tool_calls %}
|
| 148 |
-
{%- if tool_call.function is defined %}
|
| 149 |
-
{%- set tool_call = tool_call.function %}
|
| 150 |
-
{%- endif %}
|
| 151 |
-
{{- '<tool_call>\n<function=' ~ tool_call.name ~ '>\n' -}}
|
| 152 |
-
{%- if tool_call.arguments is defined %}
|
| 153 |
-
{%- for args_name, args_value in tool_call.arguments|items %}
|
| 154 |
-
{{- '<parameter=' ~ args_name ~ '>\n' -}}
|
| 155 |
-
{%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
|
| 156 |
-
{{- args_value ~ '\n</parameter>\n' -}}
|
| 157 |
-
{%- endfor %}
|
| 158 |
-
{%- endif %}
|
| 159 |
-
{{- '</function>\n</tool_call>\n' -}}
|
| 160 |
-
{%- endfor %}
|
| 161 |
-
{{- '<|im_end|>' }}{% endgeneration %}{{- '\n' }}
|
| 162 |
-
{%- else %}
|
| 163 |
-
{# Assistant message doesn't have tool calls. #}
|
| 164 |
-
{%- if not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
|
| 165 |
-
{{- '<|im_start|>assistant\n' }}{% generation %}{{- (content | default('', true) | string | trim) }}{{- '<|im_end|>' }}{% endgeneration %}{{- '\n' }}
|
| 166 |
-
{%- else %}
|
| 167 |
-
{%- set c = (content | default('', true) | string) %}
|
| 168 |
-
{%- if '<think>' in c and '</think>' in c %}
|
| 169 |
-
{%- set c = "<think></think>" ~ c.split('</think>')[-1] %}
|
| 170 |
-
{%- endif %}
|
| 171 |
-
{%- set c = c | trim %}
|
| 172 |
-
{%- if c | length > 0 %}
|
| 173 |
-
{{- '<|im_start|>assistant\n' }}{% generation %}{{- c }}{{- '<|im_end|>' }}{% endgeneration %}{{- '\n' }}
|
| 174 |
-
{%- else %}
|
| 175 |
-
{{- '<|im_start|>assistant\n' }}{% generation %}{{- '<|im_end|>' }}{% endgeneration %}{{- '\n' }}
|
| 176 |
-
{%- endif %}
|
| 177 |
-
{%- endif %}
|
| 178 |
-
{%- endif %}
|
| 179 |
-
{%- elif message.role == "user" or message.role == "system" %}
|
| 180 |
-
{{- '<|im_start|>' + message.role + '\n' }}
|
| 181 |
-
{%- set content = message.content | string %}
|
| 182 |
-
{%- if message.role == "user" and loop.index0 == ns.last_user_idx and reasoning_budget is not none %}
|
| 183 |
-
{{- content + '\n\n{thinking token budget: ' + (reasoning_budget | string) + '}' }}
|
| 184 |
-
{%- else %}
|
| 185 |
-
{{- content }}
|
| 186 |
-
{%- endif %}
|
| 187 |
-
{{- '<|im_end|>\n' }}
|
| 188 |
-
{%- elif message.role == "tool" %}
|
| 189 |
-
{%- if loop.previtem and loop.previtem.role != "tool" %}
|
| 190 |
-
{{- '<|im_start|>user\n' }}
|
| 191 |
-
{%- endif %}
|
| 192 |
-
{{- '<tool_response>\n' }}
|
| 193 |
-
{{- message.content }}
|
| 194 |
-
{{- '\n</tool_response>\n' }}
|
| 195 |
-
{%- if not loop.last and loop.nextitem.role != "tool" %}
|
| 196 |
-
{{- '<|im_end|>\n' }}
|
| 197 |
-
{%- elif loop.last %}
|
| 198 |
-
{{- '<|im_end|>\n' }}
|
| 199 |
-
{%- endif %}
|
| 200 |
-
{%- else %}
|
| 201 |
-
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>\n' }}
|
| 202 |
-
{%- endif %}
|
| 203 |
-
{%- endfor %}
|
| 204 |
-
|
| 205 |
-
{%- if add_generation_prompt %}
|
| 206 |
-
{%- if enable_thinking %}
|
| 207 |
-
{{- '<|im_start|>assistant\n<think>\n' }}
|
| 208 |
-
{%- else %}
|
| 209 |
-
{{- '<|im_start|>assistant\n<think></think>' }}
|
| 210 |
-
{%- endif %}
|
| 211 |
-
{%- endif %}
|
|
|
|
| 1 |
+
{#- Simple pretraining chat template: question/answer format, all tokens trainable.
|
| 2 |
+
No chat-ML markers, no thinking tags, no loss masking. -#}
|
| 3 |
+
{%- for message in messages %}
|
| 4 |
+
{%- if message.role == "system" %}
|
| 5 |
+
{{- message.content }}
|
| 6 |
+
{%- elif message.role == "user" %}
|
| 7 |
+
{{- "\nquestion: " + message.content }}
|
| 8 |
+
{%- elif message.role == "assistant" %}
|
| 9 |
+
{{- "\nanswer: " + message.content }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
{%- endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
{%- endfor %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tokenizer_config.json
CHANGED
|
@@ -8015,5 +8015,5 @@
|
|
| 8015 |
"model_max_length": 262144,
|
| 8016 |
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 8017 |
"unk_token": "<unk>",
|
| 8018 |
-
"chat_template": "{% macro render_extra_keys(json_dict, handled_keys) %}\n {%- if json_dict is mapping %}\n {%- for json_key in json_dict if json_key not in handled_keys %}\n {%- if json_dict[json_key] is mapping or (json_dict[json_key] is sequence and json_dict[json_key] is not string) %}\n {{- '\\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | tojson | safe) ~ '</' ~ json_key ~ '>' }}\n {%- else %}\n {{-'\\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | string) ~ '</' ~ json_key ~ '>' }}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n{% endmacro %}\n{%- set kw = chat_template_kwargs if chat_template_kwargs is defined else {} %}\n{%- set enable_thinking = kw.enable_thinking if kw.enable_thinking is defined else True %}\n{%- set reasoning_budget = kw.reasoning_budget if kw.reasoning_budget is defined else None %}\n{%- set truncate_history_thinking = kw.truncate_history_thinking if kw.truncate_history_thinking is defined else True %}\n{%- set response_format = kw.response_format if kw.response_format is defined else None %}\n\n{%- set ns = namespace(last_user_idx = -1) %}\n{%- set loop_messages = messages %}\n{%- for m in loop_messages %}\n {%- if m[\"role\"] == \"user\" %}\n {%- set ns.last_user_idx = loop.index0 %}\n {%- endif %}\n{%- endfor %}\n\n{%- if messages[0][\"role\"] == \"system\" %}\n {%- set system_message = messages[0][\"content\"] %}\n {%- set loop_messages = messages[1:] %}\n{%- else %}\n {%- set system_message = \"\" %}\n {%- set loop_messages = messages %}\n{%- endif %}\n{%- if not tools is defined %}\n {%- set tools = [] %}\n{%- endif %}\n{# Recompute last_user_idx relative to loop_messages after handling system #}\n{%- set ns = namespace(last_user_idx = -1) %}\n{%- for m in loop_messages %}\n {%- if m[\"role\"] == \"user\" %}\n {%- set ns.last_user_idx = loop.index0 %}\n {%- endif %}\n{%- endfor %}\n{%- if system_message is defined %}\n {{- \"<|im_start|>system\\n\" + system_message }}\n{%- else %}\n {%- if tools is iterable and tools | length > 0 %}\n {{- \"<|im_start|>system\\n\" }}\n {%- endif %}\n{%- endif %}\n{%- if tools is iterable and tools | length > 0 %}\n {%- if system_message is defined and system_message | length > 0 %}\n {{- \"\\n\\n\" }}\n {%- endif %}\n {{- \"# Tools\\n\\nYou have access to the following functions:\\n\\n\" }}\n {{- \"<tools>\" }}\n {%- for tool in tools %}\n {%- if tool.function is defined %}\n {%- set tool = tool.function %}\n {%- endif %}\n {{- \"\\n<function>\\n<name>\" ~ tool.name ~ \"</name>\" }}\n {%- if tool.description is defined %}\n {{- '\\n<description>' ~ (tool.description | trim) ~ '</description>' }}\n {%- endif %}\n {{- '\\n<parameters>' }}\n {%- if tool.parameters is defined and tool.parameters is mapping and tool.parameters.properties is defined and tool.parameters.properties is mapping %}\n {%- for param_name, param_fields in tool.parameters.properties|items %}\n {{- '\\n<parameter>' }}\n {{- '\\n<name>' ~ param_name ~ '</name>' }}\n {%- if param_fields.type is defined %}\n {{- '\\n<type>' ~ (param_fields.type | string) ~ '</type>' }}\n {%- endif %}\n {%- if param_fields.description is defined %}\n {{- '\\n<description>' ~ (param_fields.description | trim) ~ '</description>' }}\n {%- endif %}\n {%- if param_fields.enum is defined %}\n {{- '\\n<enum>' ~ (param_fields.enum | tojson | safe) ~ '</enum>' }}\n {%- endif %}\n {%- set handled_keys = ['name', 'type', 'description', 'enum'] %}\n {{- render_extra_keys(param_fields, handled_keys) }}\n {{- '\\n</parameter>' }}\n {%- endfor %}\n {%- endif %}\n {% set handled_keys = ['type', 'properties', 'required'] %}\n {{- render_extra_keys(tool.parameters, handled_keys) }}\n {%- if tool.parameters is defined and tool.parameters.required is defined %}\n {{- '\\n<required>' ~ (tool.parameters.required | tojson | safe) ~ '</required>' }}\n {%- endif %}\n {{- '\\n</parameters>' }}\n {%- set handled_keys = ['type', 'name', 'description', 'parameters'] %}\n {{- render_extra_keys(tool, handled_keys) }}\n {{- '\\n</function>' }}\n {%- endfor %}\n {{- \"\\n</tools>\" }}\n\n {{- '\\n\\nIf you choose to call a function ONLY reply in the following format with NO suffix:\\n\\n<tool_call>\\n<function=example_function_name>\\n<parameter=example_parameter_1>\\nvalue_1\\n</parameter>\\n<parameter=example_parameter_2>\\nThis is the value for the second parameter\\nthat can span\\nmultiple lines\\n</parameter>\\n</function>\\n</tool_call>\\n\\n<IMPORTANT>\\nReminder:\\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\\n- Required parameters MUST be specified\\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\\n</IMPORTANT>' }}\n{%- endif %}\n\n\n{%- if system_message is defined %}\n {{- '<|im_end|>\\n' }}\n{%- else %}\n {%- if tools is iterable and tools | length > 0 %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n\n{%- for message in loop_messages %}\n {%- if message.role == \"assistant\" %}\n {# Add reasoning content in to content field for unified processing below. #}\n {%- if message.reasoning_content is defined and message.reasoning_content is string and message.reasoning_content | trim | length > 0 %}\n {%- set content = \"<think>\\n\" ~ message.reasoning_content ~ \"\\n</think>\\n\" ~ (message.content | default('', true)) %}\n {%- else %}\n {%- set content = message.content | default('', true) %}\n {%- if content is string -%}\n {# Allow downstream logic to to take care of broken thought, only handle coherent reasoning here. #}\n {%- if '<think>' not in content and '</think>' not in content -%}\n {%- set content = \"<think></think>\" ~ content -%}\n {%- endif -%}\n {%- else -%}\n {%- set content = content -%}\n {%- endif -%}\n {%- endif %}\n {%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 %}\n {# Assistant message has tool calls. #}\n {{- '<|im_start|>assistant\\n' }}{% generation %}\n {%- set include_content = not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}\n {%- if content is string and content | trim | length > 0 %}\n {%- if include_content %}\n {{- (content | trim) ~ '\\n' -}}\n {%- else %}\n {%- set c = (content | string) %}\n {%- if '</think>' in c %}\n {# Keep only content after the last closing think. Also generation prompt causes this. #}\n {%- set c = c.split('</think>')[-1] %}\n {%- elif '<think>' in c %}\n {# If <think> was opened but never closed, drop the trailing think segment #}\n {%- set c = c.split('<think>')[0] %}\n {%- endif %}\n {%- set c = \"<think></think>\" ~ c | trim %}\n {%- if c | length > 0 %}\n {{- c ~ '\\n' -}}\n {%- endif %}\n {%- endif %}\n {%- else %}\n {{- \"<think></think>\" -}}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '<tool_call>\\n<function=' ~ tool_call.name ~ '>\\n' -}}\n {%- if tool_call.arguments is defined %}\n {%- for args_name, args_value in tool_call.arguments|items %}\n {{- '<parameter=' ~ args_name ~ '>\\n' -}}\n {%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}\n {{- args_value ~ '\\n</parameter>\\n' -}}\n {%- endfor %}\n {%- endif %}\n {{- '</function>\\n</tool_call>\\n' -}}\n {%- endfor %}\n {{- '<|im_end|>' }}{% endgeneration %}{{- '\\n' }}\n {%- else %}\n {# Assistant message doesn't have tool calls. #}\n {%- if not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}\n {{- '<|im_start|>assistant\\n' }}{% generation %}{{- (content | default('', true) | string | trim) }}{{- '<|im_end|>' }}{% endgeneration %}{{- '\\n' }}\n {%- else %}\n {%- set c = (content | default('', true) | string) %}\n {%- if '<think>' in c and '</think>' in c %}\n {%- set c = \"<think></think>\" ~ c.split('</think>')[-1] %}\n {%- endif %}\n {%- set c = c | trim %}\n {%- if c | length > 0 %}\n {{- '<|im_start|>assistant\\n' }}{% generation %}{{- c }}{{- '<|im_end|>' }}{% endgeneration %}{{- '\\n' }}\n {%- else %}\n {{- '<|im_start|>assistant\\n' }}{% generation %}{{- '<|im_end|>' }}{% endgeneration %}{{- '\\n' }}\n {%- endif %}\n {%- endif %}\n {%- endif %}\n {%- elif message.role == \"user\" or message.role == \"system\" %}\n {{- '<|im_start|>' + message.role + '\\n' }}\n {%- set content = message.content | string %}\n {%- if message.role == \"user\" and loop.index0 == ns.last_user_idx and reasoning_budget is not none %}\n {{- content + '\\n\\n{thinking token budget: ' + (reasoning_budget | string) + '}' }}\n {%- else %}\n {{- content }}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.previtem and loop.previtem.role != \"tool\" %}\n {{- '<|im_start|>user\\n' }}\n {%- endif %}\n {{- '<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>\\n' }}\n {%- if not loop.last and loop.nextitem.role != \"tool\" %}\n {{- '<|im_end|>\\n' }}\n {%- elif loop.last %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>\\n' }}\n {%- endif %}\n{%- endfor %}\n\n{%- if add_generation_prompt %}\n {%- if enable_thinking %}\n {{- '<|im_start|>assistant\\n<think>\\n' }}\n {%- else %}\n {{- '<|im_start|>assistant\\n<think></think>' }}\n {%- endif %}\n{%- endif %}\n"
|
| 8019 |
}
|
|
|
|
| 8015 |
"model_max_length": 262144,
|
| 8016 |
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 8017 |
"unk_token": "<unk>",
|
| 8018 |
+
"chat_template": "{#- Simple pretraining chat template: question/answer format, all tokens trainable.\n No chat-ML markers, no thinking tags, no loss masking. -#}\n{%- for message in messages %}\n{%- if message.role == \"system\" %}\n{{- message.content }}\n{%- elif message.role == \"user\" %}\n{{- \"\\nquestion: \" + message.content }}\n{%- elif message.role == \"assistant\" %}\n{{- \"\\nanswer: \" + message.content }}\n{%- endif %}\n{%- endfor %}\n"
|
| 8019 |
}
|