Puujeeeeeeeeeeee commited on
Commit
1d07310
·
verified ·
1 Parent(s): 657e6e0

(Trained with Unsloth)

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
chat_template.jinja ADDED
@@ -0,0 +1,385 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- macro format_parameters(properties, required, filter_keys=false) -%}
2
+ {%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%}
3
+ {%- set ns = namespace(found_first=false) -%}
4
+ {%- for key, value in properties | dictsort -%}
5
+ {%- set add_comma = false -%}
6
+ {%- if not filter_keys or key not in standard_keys -%}
7
+ {%- if ns.found_first %},{% endif -%}
8
+ {%- set ns.found_first = true -%}
9
+ {{ key }}:{
10
+ {%- if value['description'] -%}
11
+ description:<|"|>{{ value['description'] }}<|"|>
12
+ {%- set add_comma = true -%}
13
+ {%- endif -%}
14
+ {%- if value['type'] | upper == 'STRING' -%}
15
+ {%- if value['enum'] -%}
16
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
17
+ enum:{{ format_argument(value['enum']) }}
18
+ {%- endif -%}
19
+ {%- elif value['type'] | upper == 'ARRAY' -%}
20
+ {%- if value['items'] is mapping and value['items'] -%}
21
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
22
+ items:{
23
+ {%- set ns_items = namespace(found_first=false) -%}
24
+ {%- for item_key, item_value in value['items'] | dictsort -%}
25
+ {%- if item_value is not none -%}
26
+ {%- if ns_items.found_first %},{% endif -%}
27
+ {%- set ns_items.found_first = true -%}
28
+ {%- if item_key == 'properties' -%}
29
+ properties:{
30
+ {%- if item_value is mapping -%}
31
+ {{- format_parameters(item_value, value['items']['required'] | default([])) -}}
32
+ {%- endif -%}
33
+ }
34
+ {%- elif item_key == 'required' -%}
35
+ required:[
36
+ {%- for req_item in item_value -%}
37
+ <|"|>{{- req_item -}}<|"|>
38
+ {%- if not loop.last %},{% endif -%}
39
+ {%- endfor -%}
40
+ ]
41
+ {%- elif item_key == 'type' -%}
42
+ {%- if item_value is string -%}
43
+ type:{{ format_argument(item_value | upper) }}
44
+ {%- else -%}
45
+ type:{{ format_argument(item_value | map('upper') | list) }}
46
+ {%- endif -%}
47
+ {%- else -%}
48
+ {{ item_key }}:{{ format_argument(item_value) }}
49
+ {%- endif -%}
50
+ {%- endif -%}
51
+ {%- endfor -%}
52
+ }
53
+ {%- endif -%}
54
+ {%- endif -%}
55
+ {%- if value['nullable'] %}
56
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
57
+ nullable:true
58
+ {%- endif -%}
59
+ {%- if value['type'] | upper == 'OBJECT' -%}
60
+ {%- if value['properties'] is defined and value['properties'] is mapping -%}
61
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
62
+ properties:{
63
+ {{- format_parameters(value['properties'], value['required'] | default([])) -}}
64
+ }
65
+ {%- elif value is mapping -%}
66
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
67
+ properties:{
68
+ {{- format_parameters(value, value['required'] | default([]), filter_keys=true) -}}
69
+ }
70
+ {%- endif -%}
71
+ {%- if value['required'] -%}
72
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
73
+ required:[
74
+ {%- for item in value['required'] | default([]) -%}
75
+ <|"|>{{- item -}}<|"|>
76
+ {%- if not loop.last %},{% endif -%}
77
+ {%- endfor -%}
78
+ ]
79
+ {%- endif -%}
80
+ {%- endif -%}
81
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
82
+ type:<|"|>{{ value['type'] | upper }}<|"|>}
83
+ {%- endif -%}
84
+ {%- endfor -%}
85
+ {%- endmacro -%}
86
+ {%- macro format_function_declaration(tool_data) -%}
87
+ declaration:{{- tool_data['function']['name'] -}}{description:<|"|>{{- tool_data['function']['description'] -}}<|"|>
88
+ {%- set params = tool_data['function']['parameters'] -%}
89
+ {%- if params -%}
90
+ ,parameters:{
91
+ {%- if params['properties'] -%}
92
+ properties:{ {{- format_parameters(params['properties'], params['required']) -}} },
93
+ {%- endif -%}
94
+ {%- if params['required'] -%}
95
+ required:[
96
+ {%- for item in params['required'] -%}
97
+ <|"|>{{- item -}}<|"|>
98
+ {{- ',' if not loop.last -}}
99
+ {%- endfor -%}
100
+ ],
101
+ {%- endif -%}
102
+ {%- if params['type'] -%}
103
+ type:<|"|>{{- params['type'] | upper -}}<|"|>}
104
+ {%- endif -%}
105
+ {%- endif -%}
106
+ {%- if 'response' in tool_data['function'] -%}
107
+ {%- set response_declaration = tool_data['function']['response'] -%}
108
+ ,response:{
109
+ {%- if response_declaration['description'] -%}
110
+ description:<|"|>{{- response_declaration['description'] -}}<|"|>,
111
+ {%- endif -%}
112
+ {%- if response_declaration['type'] | upper == 'OBJECT' -%}
113
+ type:<|"|>{{- response_declaration['type'] | upper -}}<|"|>}
114
+ {%- endif -%}
115
+ {%- endif -%}
116
+ }
117
+ {%- endmacro -%}
118
+ {%- macro format_argument(argument, escape_keys=True) -%}
119
+ {%- if argument is none -%}
120
+ {{- 'null' -}}
121
+ {%- elif argument is string -%}
122
+ {{- '<|"|>' + argument + '<|"|>' -}}
123
+ {%- elif argument is boolean -%}
124
+ {{- 'true' if argument else 'false' -}}
125
+ {%- elif argument is mapping -%}
126
+ {{- '{' -}}
127
+ {%- set ns = namespace(found_first=false) -%}
128
+ {%- for key, value in argument | dictsort -%}
129
+ {%- if ns.found_first %},{% endif -%}
130
+ {%- set ns.found_first = true -%}
131
+ {%- if escape_keys -%}
132
+ {{- '<|"|>' + key + '<|"|>' -}}
133
+ {%- else -%}
134
+ {{- key -}}
135
+ {%- endif -%}
136
+ :{{- format_argument(value, escape_keys=escape_keys) -}}
137
+ {%- endfor -%}
138
+ {{- '}' -}}
139
+ {%- elif argument is sequence -%}
140
+ {{- '[' -}}
141
+ {%- for item in argument -%}
142
+ {{- format_argument(item, escape_keys=escape_keys) -}}
143
+ {%- if not loop.last %},{% endif -%}
144
+ {%- endfor -%}
145
+ {{- ']' -}}
146
+ {%- else -%}
147
+ {{- argument -}}
148
+ {%- endif -%}
149
+ {%- endmacro -%}
150
+ {%- macro strip_thinking(text) -%}
151
+ {%- set ns = namespace(result='') -%}
152
+ {%- for part in text.split('<channel|>') -%}
153
+ {%- if '<|channel>' in part -%}
154
+ {%- set ns.result = ns.result + part.split('<|channel>')[0] -%}
155
+ {%- else -%}
156
+ {%- set ns.result = ns.result + part -%}
157
+ {%- endif -%}
158
+ {%- endfor -%}
159
+ {{- ns.result | trim -}}
160
+ {%- endmacro -%}
161
+
162
+ {%- macro format_tool_response_block(tool_name, response) -%}
163
+ {{- '<|tool_response>' -}}
164
+ {%- if response is mapping -%}
165
+ {{- 'response:' + tool_name + '{' -}}
166
+ {%- for key, value in response | dictsort -%}
167
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
168
+ {%- if not loop.last %},{% endif -%}
169
+ {%- endfor -%}
170
+ {{- '}' -}}
171
+ {%- else -%}
172
+ {{- 'response:' + tool_name + '{value:' + format_argument(response, escape_keys=False) + '}' -}}
173
+ {%- endif -%}
174
+ {{- '<tool_response|>' -}}
175
+ {%- endmacro -%}
176
+
177
+ {#- ===== SETUP ===== -#}
178
+ {%- set ns = namespace(prev_message_type=None, prev_non_tool_role=None) -%}
179
+ {%- set loop_messages = messages -%}
180
+ {%- set enable_thinking = enable_thinking | default(false) -%}
181
+ {%- set preserve_thinking = preserve_thinking | default(false) -%}
182
+ {{- bos_token -}}
183
+ {#- Handle System/Tool Definitions Block -#}
184
+ {%- if enable_thinking or tools or (messages and messages[0]['role'] in ['system', 'developer']) -%}
185
+ {{- '<|turn>system\n' -}}
186
+ {#- Inject Thinking token at the very top of the FIRST system turn -#}
187
+ {%- if enable_thinking -%}
188
+ {{- '<|think|>\n' -}}
189
+ {%- set ns.prev_message_type = 'think' -%}
190
+ {%- endif -%}
191
+ {%- if messages and messages[0]['role'] in ['system', 'developer'] -%}
192
+ {%- if messages[0]['content'] is string -%}
193
+ {{- messages[0]['content'] | trim -}}
194
+ {%- elif messages[0]['content'] is sequence -%}
195
+ {%- for item in messages[0]['content'] -%}
196
+ {{- item['text'] | trim + ' '-}}
197
+ {%- endfor -%}
198
+ {%- endif -%}
199
+ {%- set loop_messages = messages[1:] -%}
200
+ {%- endif -%}
201
+ {%- if tools -%}
202
+ {%- for tool in tools %}
203
+ {{- '<|tool>' -}}
204
+ {{- format_function_declaration(tool) | trim -}}
205
+ {{- '<tool|>' -}}
206
+ {%- endfor %}
207
+ {%- set ns.prev_message_type = 'tool' -%}
208
+ {%- endif -%}
209
+ {{- '<turn|>\n' -}}
210
+ {%- endif %}
211
+
212
+ {#- Pre-scan: find last user message index for reasoning guard -#}
213
+ {%- set ns_turn = namespace(last_user_idx=-1) -%}
214
+ {%- for i in range(loop_messages | length) -%}
215
+ {%- if loop_messages[i]['role'] == 'user' -%}
216
+ {%- set ns_turn.last_user_idx = i -%}
217
+ {%- endif -%}
218
+ {%- endfor -%}
219
+
220
+ {#- Loop through messages -#}
221
+ {%- for message in loop_messages -%}
222
+ {%- if message['role'] != 'tool' -%}
223
+ {%- set ns.prev_message_type = None -%}
224
+ {%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}
225
+ {#- Detect continuation using tracked state — O(1) instead of O(n) backward scan -#}
226
+ {%- set continue_same_model_turn = (role == 'model' and ns.prev_non_tool_role == 'assistant') -%}
227
+ {%- if not continue_same_model_turn -%}
228
+ {{- '<|turn>' + role + '\n' }}
229
+ {%- endif -%}
230
+
231
+ {#- Render reasoning/reasoning_content as thinking channel -#}
232
+ {%- set thinking_text = message.get('reasoning') or message.get('reasoning_content') -%}
233
+ {%- set thinking_gate = (loop.index0 > ns_turn.last_user_idx) or (preserve_thinking and message.get('tool_calls')) -%}
234
+ {%- if thinking_text and thinking_gate -%}
235
+ {{- '<|channel>thought\n' + thinking_text + '\n<channel|>' -}}
236
+ {%- endif -%}
237
+
238
+ {%- if message.get('tool_calls') -%}
239
+ {%- for tool_call in message.get('tool_calls') -%}
240
+ {%- set function = tool_call['function'] -%}
241
+ {{- '<|tool_call>call:' + function['name'] + '{' -}}
242
+ {%- if function['arguments'] is mapping -%}
243
+ {%- set ns_args = namespace(found_first=false) -%}
244
+ {%- for key, value in function['arguments'] | dictsort -%}
245
+ {%- if ns_args.found_first %},{% endif -%}
246
+ {%- set ns_args.found_first = true -%}
247
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
248
+ {%- endfor -%}
249
+ {%- elif function['arguments'] is none -%}
250
+ {%- elif function['arguments'] is string -%}
251
+ {#- Pre-serialized args (e.g. an OpenAI JSON string). We cannot JSON-parse
252
+ portably in-template, so render non-fatally instead of erroring. Strip an
253
+ outer {...} so it composes with the DSL braces rather than double-wrapping.
254
+ Prefer passing arguments as a mapping for exact Gemma DSL. -#}
255
+ {%- set argstr = function['arguments'] | trim -%}
256
+ {%- if argstr[:1] == '{' and argstr[-1:] == '}' -%}
257
+ {{- argstr[1:-1] -}}
258
+ {%- else -%}
259
+ {{- function['arguments'] -}}
260
+ {%- endif -%}
261
+ {%- endif -%}
262
+ {{- '}<tool_call|>' -}}
263
+ {%- endfor -%}
264
+ {%- set ns.prev_message_type = 'tool_call' -%}
265
+ {%- endif -%}
266
+
267
+ {%- set ns_tr_out = namespace(flag=false) -%}
268
+ {%- if message.get('tool_responses') -%}
269
+ {#- Legacy: tool_responses embedded on the assistant message (Google/Gemma native) -#}
270
+ {%- for tool_response in message.get('tool_responses') -%}
271
+ {{- format_tool_response_block(tool_response['name'] | default('unknown', true), tool_response['response']) -}}
272
+ {%- set ns_tr_out.flag = true -%}
273
+ {%- set ns.prev_message_type = 'tool_response' -%}
274
+ {%- endfor -%}
275
+ {%- elif message.get('tool_calls') -%}
276
+ {#- OpenAI Chat Completions: forward-scan consecutive role:tool messages -#}
277
+ {%- set ns_tool_scan = namespace(stopped=false) -%}
278
+ {%- for k in range(loop.index0 + 1, loop_messages | length) -%}
279
+ {%- if ns_tool_scan.stopped -%}
280
+ {%- elif loop_messages[k]['role'] != 'tool' -%}
281
+ {%- set ns_tool_scan.stopped = true -%}
282
+ {%- else -%}
283
+ {%- set follow = loop_messages[k] -%}
284
+ {#- Resolve tool_call_id to function name -#}
285
+ {%- set ns_tname = namespace(name=follow.get('name') or 'unknown') -%}
286
+ {%- for tc in message.get('tool_calls') -%}
287
+ {%- if tc.get('id') == follow.get('tool_call_id') -%}
288
+ {%- set ns_tname.name = tc['function']['name'] -%}
289
+ {%- endif -%}
290
+ {%- endfor -%}
291
+ {#- Handle content as string or content-parts array -#}
292
+ {%- set tool_body = follow.get('content') -%}
293
+ {%- if tool_body is string -%}
294
+ {{- format_tool_response_block(ns_tname.name, tool_body) -}}
295
+ {%- elif tool_body is sequence and tool_body is not string -%}
296
+ {%- set ns_txt = namespace(s='') -%}
297
+ {%- for part in tool_body -%}
298
+ {%- if part.get('type') == 'text' -%}
299
+ {%- set ns_txt.s = ns_txt.s + (part.get('text') | default('')) -%}
300
+ {%- endif -%}
301
+ {%- endfor -%}
302
+ {{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
303
+ {%- for part in tool_body -%}
304
+ {%- if part.get('type') in ['image', 'image_url'] -%}
305
+ {{- '<|image|>' -}}
306
+ {%- elif part.get('type') in ['audio', 'input_audio'] -%}
307
+ {{- '<|audio|>' -}}
308
+ {%- elif part.get('type') == 'video' -%}
309
+ {{- '<|video|>' -}}
310
+ {%- endif -%}
311
+ {%- endfor -%}
312
+ {%- else -%}
313
+ {{- format_tool_response_block(ns_tname.name, tool_body) -}}
314
+ {%- endif -%}
315
+ {%- set ns_tr_out.flag = true -%}
316
+ {%- set ns.prev_message_type = 'tool_response' -%}
317
+ {%- endif -%}
318
+ {%- endfor -%}
319
+ {%- endif -%}
320
+
321
+ {%- set captured_content -%}
322
+ {%- if message.get('content') is string -%}
323
+ {%- if role == 'model' -%}
324
+ {{- strip_thinking(message['content']) -}}
325
+ {%- else -%}
326
+ {{- message['content'] | trim -}}
327
+ {%- endif -%}
328
+ {%- elif message.get('content') is sequence -%}
329
+ {%- for item in message['content'] -%}
330
+ {%- if item.get('type') == 'text' -%}
331
+ {%- if role == 'model' -%}
332
+ {{- strip_thinking(item['text']) -}}
333
+ {%- else -%}
334
+ {{- item['text'] | trim -}}
335
+ {%- endif -%}
336
+ {%- elif item.get('type') in ['image', 'image_url'] -%}
337
+ {{- '<|image|>' -}}
338
+ {%- elif item.get('type') in ['audio', 'input_audio'] -%}
339
+ {{- '<|audio|>' -}}
340
+ {%- elif item.get('type') == 'video' -%}
341
+ {{- '<|video|>' -}}
342
+ {%- endif -%}
343
+ {%- endfor -%}
344
+ {%- endif -%}
345
+ {%- endset -%}
346
+
347
+ {{- captured_content -}}
348
+ {%- set has_content = captured_content | trim | length > 0 -%}
349
+
350
+ {#- Forward-scan: find next non-tool message role for continuation detection -#}
351
+ {%- set next_nt = namespace(role=None, found=false) -%}
352
+ {%- for j in range(loop.index0 + 1, loop_messages | length) -%}
353
+ {%- if not next_nt.found -%}
354
+ {%- if loop_messages[j]['role'] != 'tool' -%}
355
+ {%- set next_nt.role = loop_messages[j]['role'] -%}
356
+ {%- set next_nt.found = true -%}
357
+ {%- endif -%}
358
+ {%- endif -%}
359
+ {%- endfor -%}
360
+
361
+ {%- set continues_into_next = (
362
+ role == 'model'
363
+ and next_nt.role == 'assistant'
364
+ and (not message.get('tool_calls') or ns_tr_out.flag)
365
+ ) -%}
366
+
367
+ {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
368
+ {{- '<|tool_response>' -}}
369
+ {%- elif continues_into_next -%}
370
+ {%- elif not (ns_tr_out.flag and not has_content and not next_nt.found) -%}
371
+ {{- '<turn|>\n' -}}
372
+ {%- endif -%}
373
+
374
+ {#- Track previous non-tool role for next iteration (avoids O(n) backward scan) -#}
375
+ {%- set ns.prev_non_tool_role = message['role'] -%}
376
+ {%- endif -%}
377
+ {%- endfor -%}
378
+
379
+ {%- if add_generation_prompt -%}
380
+ {%- if ns.prev_message_type != 'tool_response' and ns.prev_message_type != 'tool_call' -%}
381
+ {{- '<|turn>model\n' -}}
382
+ {%- elif ns.prev_message_type == 'tool_response' and enable_thinking -%}
383
+ {{- '<|channel>thought\n' -}}
384
+ {%- endif -%}
385
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Gemma4ForConditionalGeneration"
4
+ ],
5
+ "audio_config": {
6
+ "_name_or_path": "",
7
+ "architectures": null,
8
+ "attention_chunk_size": 12,
9
+ "attention_context_left": 13,
10
+ "attention_context_right": 0,
11
+ "attention_invalid_logits_value": -1000000000.0,
12
+ "attention_logit_cap": 50.0,
13
+ "chunk_size_feed_forward": 0,
14
+ "conv_kernel_size": 5,
15
+ "torch_dtype": "bfloat16",
16
+ "gradient_clipping": 10000000000.0,
17
+ "hidden_act": "silu",
18
+ "hidden_size": 1024,
19
+ "id2label": {
20
+ "0": "LABEL_0",
21
+ "1": "LABEL_1"
22
+ },
23
+ "initializer_range": 0.02,
24
+ "is_encoder_decoder": false,
25
+ "label2id": {
26
+ "LABEL_0": 0,
27
+ "LABEL_1": 1
28
+ },
29
+ "model_type": "gemma4_audio",
30
+ "num_attention_heads": 8,
31
+ "num_hidden_layers": 12,
32
+ "output_attentions": false,
33
+ "output_hidden_states": false,
34
+ "output_proj_dims": 1536,
35
+ "problem_type": null,
36
+ "residual_weight": 0.5,
37
+ "return_dict": true,
38
+ "rms_norm_eps": 1e-06,
39
+ "subsampling_conv_channels": [
40
+ 128,
41
+ 32
42
+ ],
43
+ "use_clipped_linears": true
44
+ },
45
+ "audio_token_id": 258881,
46
+ "boa_token_id": 256000,
47
+ "boi_token_id": 255999,
48
+ "bos_token_id": 2,
49
+ "torch_dtype": "bfloat16",
50
+ "eoa_token_id": 258883,
51
+ "eoa_token_index": 258883,
52
+ "eoi_token_id": 258882,
53
+ "eos_token_id": 1,
54
+ "image_token_id": 258880,
55
+ "initializer_range": 0.02,
56
+ "model_name": "Puujeeeeeeeeeeee/cpt-round4",
57
+ "model_type": "gemma4",
58
+ "pad_token_id": 0,
59
+ "text_config": {
60
+ "attention_bias": false,
61
+ "attention_dropout": 0.0,
62
+ "attention_k_eq_v": false,
63
+ "bos_token_id": 2,
64
+ "torch_dtype": "bfloat16",
65
+ "enable_moe_block": false,
66
+ "eos_token_id": 1,
67
+ "expert_intermediate_size": null,
68
+ "final_logit_softcapping": 30.0,
69
+ "global_head_dim": 512,
70
+ "head_dim": 256,
71
+ "hidden_activation": "gelu_pytorch_tanh",
72
+ "hidden_size": 2560,
73
+ "hidden_size_per_layer_input": 256,
74
+ "initializer_range": 0.02,
75
+ "intermediate_size": 10240,
76
+ "layer_types": [
77
+ "sliding_attention",
78
+ "sliding_attention",
79
+ "sliding_attention",
80
+ "sliding_attention",
81
+ "sliding_attention",
82
+ "full_attention",
83
+ "sliding_attention",
84
+ "sliding_attention",
85
+ "sliding_attention",
86
+ "sliding_attention",
87
+ "sliding_attention",
88
+ "full_attention",
89
+ "sliding_attention",
90
+ "sliding_attention",
91
+ "sliding_attention",
92
+ "sliding_attention",
93
+ "sliding_attention",
94
+ "full_attention",
95
+ "sliding_attention",
96
+ "sliding_attention",
97
+ "sliding_attention",
98
+ "sliding_attention",
99
+ "sliding_attention",
100
+ "full_attention",
101
+ "sliding_attention",
102
+ "sliding_attention",
103
+ "sliding_attention",
104
+ "sliding_attention",
105
+ "sliding_attention",
106
+ "full_attention",
107
+ "sliding_attention",
108
+ "sliding_attention",
109
+ "sliding_attention",
110
+ "sliding_attention",
111
+ "sliding_attention",
112
+ "full_attention",
113
+ "sliding_attention",
114
+ "sliding_attention",
115
+ "sliding_attention",
116
+ "sliding_attention",
117
+ "sliding_attention",
118
+ "full_attention"
119
+ ],
120
+ "max_position_embeddings": 131072,
121
+ "model_type": "gemma4_text",
122
+ "moe_intermediate_size": null,
123
+ "num_attention_heads": 8,
124
+ "num_experts": null,
125
+ "num_global_key_value_heads": null,
126
+ "num_hidden_layers": 42,
127
+ "num_key_value_heads": 2,
128
+ "num_kv_shared_layers": 18,
129
+ "pad_token_id": 0,
130
+ "rms_norm_eps": 1e-06,
131
+ "rope_parameters": {
132
+ "full_attention": {
133
+ "partial_rotary_factor": 0.25,
134
+ "rope_theta": 1000000.0,
135
+ "rope_type": "proportional"
136
+ },
137
+ "sliding_attention": {
138
+ "rope_theta": 10000.0,
139
+ "rope_type": "default"
140
+ }
141
+ },
142
+ "sliding_window": 512,
143
+ "tie_word_embeddings": true,
144
+ "top_k_experts": null,
145
+ "use_bidirectional_attention": null,
146
+ "use_cache": false,
147
+ "use_double_wide_mlp": false,
148
+ "vocab_size": 262144,
149
+ "vocab_size_per_layer_input": 262144
150
+ },
151
+ "tie_word_embeddings": true,
152
+ "unsloth_fixed": true,
153
+ "unsloth_version": "2026.6.9",
154
+ "use_cache": false,
155
+ "video_token_id": 258884,
156
+ "vision_config": {
157
+ "_name_or_path": "",
158
+ "architectures": null,
159
+ "attention_bias": false,
160
+ "attention_dropout": 0.0,
161
+ "chunk_size_feed_forward": 0,
162
+ "default_output_length": 280,
163
+ "torch_dtype": "bfloat16",
164
+ "global_head_dim": 64,
165
+ "head_dim": 64,
166
+ "hidden_activation": "gelu_pytorch_tanh",
167
+ "hidden_size": 768,
168
+ "id2label": {
169
+ "0": "LABEL_0",
170
+ "1": "LABEL_1"
171
+ },
172
+ "initializer_range": 0.02,
173
+ "intermediate_size": 3072,
174
+ "is_encoder_decoder": false,
175
+ "label2id": {
176
+ "LABEL_0": 0,
177
+ "LABEL_1": 1
178
+ },
179
+ "max_position_embeddings": 131072,
180
+ "model_type": "gemma4_vision",
181
+ "num_attention_heads": 12,
182
+ "num_hidden_layers": 16,
183
+ "num_key_value_heads": 12,
184
+ "output_attentions": false,
185
+ "output_hidden_states": false,
186
+ "patch_size": 16,
187
+ "pooling_kernel_size": 3,
188
+ "position_embedding_size": 10240,
189
+ "problem_type": null,
190
+ "return_dict": true,
191
+ "rms_norm_eps": 1e-06,
192
+ "rope_parameters": {
193
+ "rope_theta": 100.0,
194
+ "rope_type": "default"
195
+ },
196
+ "standardize": false,
197
+ "use_clipped_linears": true
198
+ },
199
+ "vision_soft_tokens_per_image": 280
200
+ }
generation_config.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 2,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 1
6
+ ],
7
+ "pad_token_id": 0,
8
+ "temperature": 1.0,
9
+ "top_k": 64,
10
+ "top_p": 0.95,
11
+ "transformers_version": "5.13.0"
12
+ }
processor_config.json ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "audio_ms_per_token": 40,
3
+ "audio_seq_length": 750,
4
+ "feature_extractor": {
5
+ "dither": 0.0,
6
+ "feature_extractor_type": "Gemma4AudioFeatureExtractor",
7
+ "feature_size": 128,
8
+ "fft_length": 512,
9
+ "fft_overdrive": false,
10
+ "frame_length": 320,
11
+ "hop_length": 160,
12
+ "input_scale_factor": 1.0,
13
+ "max_frequency": 8000.0,
14
+ "mel_floor": 0.001,
15
+ "min_frequency": 0.0,
16
+ "padding_side": "right",
17
+ "padding_value": 0.0,
18
+ "per_bin_mean": null,
19
+ "per_bin_stddev": null,
20
+ "preemphasis": 0.0,
21
+ "preemphasis_htk_flavor": true,
22
+ "return_attention_mask": true,
23
+ "sampling_rate": 16000
24
+ },
25
+ "image_processor": {
26
+ "do_convert_rgb": true,
27
+ "do_normalize": false,
28
+ "do_rescale": true,
29
+ "do_resize": true,
30
+ "image_mean": [
31
+ 0.0,
32
+ 0.0,
33
+ 0.0
34
+ ],
35
+ "image_processor_type": "Gemma4ImageProcessor",
36
+ "image_seq_length": 280,
37
+ "image_std": [
38
+ 1.0,
39
+ 1.0,
40
+ 1.0
41
+ ],
42
+ "max_soft_tokens": 280,
43
+ "patch_size": 16,
44
+ "pooling_kernel_size": 3,
45
+ "resample": 3,
46
+ "rescale_factor": 0.00392156862745098
47
+ },
48
+ "image_seq_length": 280,
49
+ "processor_class": "Gemma4Processor",
50
+ "video_processor": {
51
+ "do_convert_rgb": true,
52
+ "do_normalize": true,
53
+ "do_rescale": true,
54
+ "do_resize": true,
55
+ "do_sample_frames": true,
56
+ "image_mean": [
57
+ 0.0,
58
+ 0.0,
59
+ 0.0
60
+ ],
61
+ "image_std": [
62
+ 1.0,
63
+ 1.0,
64
+ 1.0
65
+ ],
66
+ "max_soft_tokens": 70,
67
+ "num_frames": 32,
68
+ "patch_size": 16,
69
+ "pooling_kernel_size": 3,
70
+ "resample": 3,
71
+ "rescale_factor": 0.00392156862745098,
72
+ "return_metadata": false,
73
+ "video_processor_type": "Gemma4VideoProcessor"
74
+ }
75
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cc8d3a0ce36466ccc1278bf987df5f71db1719b9ca6b4118264f45cb627bfe0f
3
+ size 32169626
tokenizer_config.json ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "audio_token": "<|audio|>",
3
+ "backend": "tokenizers",
4
+ "boa_token": "<|audio>",
5
+ "boi_token": "<|image>",
6
+ "bos_token": "<bos>",
7
+ "eoa_token": "<audio|>",
8
+ "eoc_token": "<channel|>",
9
+ "eoi_token": "<image|>",
10
+ "eos_token": "<eos>",
11
+ "eot_token": "<turn|>",
12
+ "escape_token": "<|\"|>",
13
+ "etc_token": "<tool_call|>",
14
+ "etd_token": "<tool|>",
15
+ "etr_token": "<tool_response|>",
16
+ "extra_special_tokens": [
17
+ "<|video|>"
18
+ ],
19
+ "image_token": "<|image|>",
20
+ "is_local": false,
21
+ "local_files_only": false,
22
+ "mask_token": "<mask>",
23
+ "max_length": 1024,
24
+ "model_max_length": 131072,
25
+ "model_specific_special_tokens": {
26
+ "audio_token": "<|audio|>",
27
+ "boa_token": "<|audio>",
28
+ "boi_token": "<|image>",
29
+ "eoa_token": "<audio|>",
30
+ "eoc_token": "<channel|>",
31
+ "eoi_token": "<image|>",
32
+ "eot_token": "<turn|>",
33
+ "escape_token": "<|\"|>",
34
+ "etc_token": "<tool_call|>",
35
+ "etd_token": "<tool|>",
36
+ "etr_token": "<tool_response|>",
37
+ "image_token": "<|image|>",
38
+ "soc_token": "<|channel>",
39
+ "sot_token": "<|turn>",
40
+ "stc_token": "<|tool_call>",
41
+ "std_token": "<|tool>",
42
+ "str_token": "<|tool_response>",
43
+ "think_token": "<|think|>"
44
+ },
45
+ "pad_token": "<pad>",
46
+ "padding_side": "right",
47
+ "processor_class": "Gemma4Processor",
48
+ "soc_token": "<|channel>",
49
+ "sot_token": "<|turn>",
50
+ "stc_token": "<|tool_call>",
51
+ "std_token": "<|tool>",
52
+ "str_token": "<|tool_response>",
53
+ "stride": 0,
54
+ "think_token": "<|think|>",
55
+ "tokenizer_class": "GemmaTokenizer",
56
+ "truncation_side": "right",
57
+ "truncation_strategy": "longest_first",
58
+ "unk_token": "<unk>",
59
+ "added_tokens_decoder": {
60
+ "0": {
61
+ "content": "<pad>",
62
+ "single_word": false,
63
+ "lstrip": false,
64
+ "rstrip": false,
65
+ "normalized": false,
66
+ "special": true
67
+ },
68
+ "1": {
69
+ "content": "<eos>",
70
+ "single_word": false,
71
+ "lstrip": false,
72
+ "rstrip": false,
73
+ "normalized": false,
74
+ "special": true
75
+ },
76
+ "2": {
77
+ "content": "<bos>",
78
+ "single_word": false,
79
+ "lstrip": false,
80
+ "rstrip": false,
81
+ "normalized": false,
82
+ "special": true
83
+ },
84
+ "3": {
85
+ "content": "<unk>",
86
+ "single_word": false,
87
+ "lstrip": false,
88
+ "rstrip": false,
89
+ "normalized": false,
90
+ "special": true
91
+ },
92
+ "4": {
93
+ "content": "<mask>",
94
+ "single_word": false,
95
+ "lstrip": false,
96
+ "rstrip": false,
97
+ "normalized": false,
98
+ "special": true
99
+ },
100
+ "46": {
101
+ "content": "<|tool>",
102
+ "single_word": false,
103
+ "lstrip": false,
104
+ "rstrip": false,
105
+ "normalized": false,
106
+ "special": true
107
+ },
108
+ "47": {
109
+ "content": "<tool|>",
110
+ "single_word": false,
111
+ "lstrip": false,
112
+ "rstrip": false,
113
+ "normalized": false,
114
+ "special": true
115
+ },
116
+ "48": {
117
+ "content": "<|tool_call>",
118
+ "single_word": false,
119
+ "lstrip": false,
120
+ "rstrip": false,
121
+ "normalized": false,
122
+ "special": true
123
+ },
124
+ "49": {
125
+ "content": "<tool_call|>",
126
+ "single_word": false,
127
+ "lstrip": false,
128
+ "rstrip": false,
129
+ "normalized": false,
130
+ "special": true
131
+ },
132
+ "50": {
133
+ "content": "<|tool_response>",
134
+ "single_word": false,
135
+ "lstrip": false,
136
+ "rstrip": false,
137
+ "normalized": false,
138
+ "special": true
139
+ },
140
+ "51": {
141
+ "content": "<tool_response|>",
142
+ "single_word": false,
143
+ "lstrip": false,
144
+ "rstrip": false,
145
+ "normalized": false,
146
+ "special": true
147
+ },
148
+ "52": {
149
+ "content": "<|\"|>",
150
+ "single_word": false,
151
+ "lstrip": false,
152
+ "rstrip": false,
153
+ "normalized": false,
154
+ "special": true
155
+ },
156
+ "98": {
157
+ "content": "<|think|>",
158
+ "single_word": false,
159
+ "lstrip": false,
160
+ "rstrip": false,
161
+ "normalized": false,
162
+ "special": true
163
+ },
164
+ "100": {
165
+ "content": "<|channel>",
166
+ "single_word": false,
167
+ "lstrip": false,
168
+ "rstrip": false,
169
+ "normalized": false,
170
+ "special": true
171
+ },
172
+ "101": {
173
+ "content": "<channel|>",
174
+ "single_word": false,
175
+ "lstrip": false,
176
+ "rstrip": false,
177
+ "normalized": false,
178
+ "special": true
179
+ },
180
+ "105": {
181
+ "content": "<|turn>",
182
+ "single_word": false,
183
+ "lstrip": false,
184
+ "rstrip": false,
185
+ "normalized": false,
186
+ "special": true
187
+ },
188
+ "106": {
189
+ "content": "<turn|>",
190
+ "single_word": false,
191
+ "lstrip": false,
192
+ "rstrip": false,
193
+ "normalized": false,
194
+ "special": true
195
+ },
196
+ "255999": {
197
+ "content": "<|image>",
198
+ "single_word": false,
199
+ "lstrip": false,
200
+ "rstrip": false,
201
+ "normalized": false,
202
+ "special": true
203
+ },
204
+ "256000": {
205
+ "content": "<|audio>",
206
+ "single_word": false,
207
+ "lstrip": false,
208
+ "rstrip": false,
209
+ "normalized": false,
210
+ "special": true
211
+ },
212
+ "258880": {
213
+ "content": "<|image|>",
214
+ "single_word": false,
215
+ "lstrip": false,
216
+ "rstrip": false,
217
+ "normalized": false,
218
+ "special": true
219
+ },
220
+ "258881": {
221
+ "content": "<|audio|>",
222
+ "single_word": false,
223
+ "lstrip": false,
224
+ "rstrip": false,
225
+ "normalized": false,
226
+ "special": true
227
+ },
228
+ "258882": {
229
+ "content": "<image|>",
230
+ "single_word": false,
231
+ "lstrip": false,
232
+ "rstrip": false,
233
+ "normalized": false,
234
+ "special": true
235
+ },
236
+ "258883": {
237
+ "content": "<audio|>",
238
+ "single_word": false,
239
+ "lstrip": false,
240
+ "rstrip": false,
241
+ "normalized": false,
242
+ "special": true
243
+ },
244
+ "258884": {
245
+ "content": "<|video|>",
246
+ "single_word": false,
247
+ "lstrip": false,
248
+ "rstrip": false,
249
+ "normalized": false,
250
+ "special": true
251
+ }
252
+ },
253
+ "chat_template": "{%- macro format_parameters(properties, required, filter_keys=false) -%}\n {%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%}\n {%- set ns = namespace(found_first=false) -%}\n {%- for key, value in properties | dictsort -%}\n {%- set add_comma = false -%}\n {%- if not filter_keys or key not in standard_keys -%}\n {%- if ns.found_first %},{% endif -%}\n {%- set ns.found_first = true -%}\n {{ key }}:{\n {%- if value['description'] -%}\n description:<|\"|>{{ value['description'] }}<|\"|>\n {%- set add_comma = true -%}\n {%- endif -%}\n {%- if value['type'] | upper == 'STRING' -%}\n {%- if value['enum'] -%}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n enum:{{ format_argument(value['enum']) }}\n {%- endif -%}\n {%- elif value['type'] | upper == 'ARRAY' -%}\n {%- if value['items'] is mapping and value['items'] -%}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n items:{\n {%- set ns_items = namespace(found_first=false) -%}\n {%- for item_key, item_value in value['items'] | dictsort -%}\n {%- if item_value is not none -%}\n {%- if ns_items.found_first %},{% endif -%}\n {%- set ns_items.found_first = true -%}\n {%- if item_key == 'properties' -%}\n properties:{\n {%- if item_value is mapping -%}\n {{- format_parameters(item_value, value['items']['required'] | default([])) -}}\n {%- endif -%}\n }\n {%- elif item_key == 'required' -%}\n required:[\n {%- for req_item in item_value -%}\n <|\"|>{{- req_item -}}<|\"|>\n {%- if not loop.last %},{% endif -%}\n {%- endfor -%}\n ]\n {%- elif item_key == 'type' -%}\n {%- if item_value is string -%}\n type:{{ format_argument(item_value | upper) }}\n {%- else -%}\n type:{{ format_argument(item_value | map('upper') | list) }}\n {%- endif -%}\n {%- else -%}\n {{ item_key }}:{{ format_argument(item_value) }}\n {%- endif -%}\n {%- endif -%}\n {%- endfor -%}\n }\n {%- endif -%}\n {%- endif -%}\n {%- if value['nullable'] %}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n nullable:true\n {%- endif -%}\n {%- if value['type'] | upper == 'OBJECT' -%}\n {%- if value['properties'] is defined and value['properties'] is mapping -%}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n properties:{\n {{- format_parameters(value['properties'], value['required'] | default([])) -}}\n }\n {%- elif value is mapping -%}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n properties:{\n {{- format_parameters(value, value['required'] | default([]), filter_keys=true) -}}\n }\n {%- endif -%}\n {%- if value['required'] -%}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n required:[\n {%- for item in value['required'] | default([]) -%}\n <|\"|>{{- item -}}<|\"|>\n {%- if not loop.last %},{% endif -%}\n {%- endfor -%}\n ]\n {%- endif -%}\n {%- endif -%}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n type:<|\"|>{{ value['type'] | upper }}<|\"|>}\n {%- endif -%}\n {%- endfor -%}\n{%- endmacro -%}\n{%- macro format_function_declaration(tool_data) -%}\n declaration:{{- tool_data['function']['name'] -}}{description:<|\"|>{{- tool_data['function']['description'] -}}<|\"|>\n {%- set params = tool_data['function']['parameters'] -%}\n {%- if params -%}\n ,parameters:{\n {%- if params['properties'] -%}\n properties:{ {{- format_parameters(params['properties'], params['required']) -}} },\n {%- endif -%}\n {%- if params['required'] -%}\n required:[\n {%- for item in params['required'] -%}\n <|\"|>{{- item -}}<|\"|>\n {{- ',' if not loop.last -}}\n {%- endfor -%}\n ],\n {%- endif -%}\n {%- if params['type'] -%}\n type:<|\"|>{{- params['type'] | upper -}}<|\"|>}\n {%- endif -%}\n {%- endif -%}\n {%- if 'response' in tool_data['function'] -%}\n {%- set response_declaration = tool_data['function']['response'] -%}\n ,response:{\n {%- if response_declaration['description'] -%}\n description:<|\"|>{{- response_declaration['description'] -}}<|\"|>,\n {%- endif -%}\n {%- if response_declaration['type'] | upper == 'OBJECT' -%}\n type:<|\"|>{{- response_declaration['type'] | upper -}}<|\"|>}\n {%- endif -%}\n {%- endif -%}\n }\n{%- endmacro -%}\n{%- macro format_argument(argument, escape_keys=True) -%}\n {%- if argument is none -%}\n {{- 'null' -}}\n {%- elif argument is string -%}\n {{- '<|\"|>' + argument + '<|\"|>' -}}\n {%- elif argument is boolean -%}\n {{- 'true' if argument else 'false' -}}\n {%- elif argument is mapping -%}\n {{- '{' -}}\n {%- set ns = namespace(found_first=false) -%}\n {%- for key, value in argument | dictsort -%}\n {%- if ns.found_first %},{% endif -%}\n {%- set ns.found_first = true -%}\n {%- if escape_keys -%}\n {{- '<|\"|>' + key + '<|\"|>' -}}\n {%- else -%}\n {{- key -}}\n {%- endif -%}\n :{{- format_argument(value, escape_keys=escape_keys) -}}\n {%- endfor -%}\n {{- '}' -}}\n {%- elif argument is sequence -%}\n {{- '[' -}}\n {%- for item in argument -%}\n {{- format_argument(item, escape_keys=escape_keys) -}}\n {%- if not loop.last %},{% endif -%}\n {%- endfor -%}\n {{- ']' -}}\n {%- else -%}\n {{- argument -}}\n {%- endif -%}\n{%- endmacro -%}\n{%- macro strip_thinking(text) -%}\n {%- set ns = namespace(result='') -%}\n {%- for part in text.split('<channel|>') -%}\n {%- if '<|channel>' in part -%}\n {%- set ns.result = ns.result + part.split('<|channel>')[0] -%}\n {%- else -%}\n {%- set ns.result = ns.result + part -%}\n {%- endif -%}\n {%- endfor -%}\n {{- ns.result | trim -}}\n{%- endmacro -%}\n\n{%- macro format_tool_response_block(tool_name, response) -%}\n {{- '<|tool_response>' -}}\n {%- if response is mapping -%}\n {{- 'response:' + tool_name + '{' -}}\n {%- for key, value in response | dictsort -%}\n {{- key -}}:{{- format_argument(value, escape_keys=False) -}}\n {%- if not loop.last %},{% endif -%}\n {%- endfor -%}\n {{- '}' -}}\n {%- else -%}\n {{- 'response:' + tool_name + '{value:' + format_argument(response, escape_keys=False) + '}' -}}\n {%- endif -%}\n {{- '<tool_response|>' -}}\n{%- endmacro -%}\n\n{#- ===== SETUP ===== -#}\n{%- set ns = namespace(prev_message_type=None, prev_non_tool_role=None) -%}\n{%- set loop_messages = messages -%}\n{%- set enable_thinking = enable_thinking | default(false) -%}\n{%- set preserve_thinking = preserve_thinking | default(false) -%}\n{{- bos_token -}}\n{#- Handle System/Tool Definitions Block -#}\n{%- if enable_thinking or tools or (messages and messages[0]['role'] in ['system', 'developer']) -%}\n {{- '<|turn>system\\n' -}}\n {#- Inject Thinking token at the very top of the FIRST system turn -#}\n {%- if enable_thinking -%}\n {{- '<|think|>\\n' -}}\n {%- set ns.prev_message_type = 'think' -%}\n {%- endif -%}\n {%- if messages and messages[0]['role'] in ['system', 'developer'] -%}\n {%- if messages[0]['content'] is string -%}\n {{- messages[0]['content'] | trim -}}\n {%- elif messages[0]['content'] is sequence -%}\n {%- for item in messages[0]['content'] -%}\n {{- item['text'] | trim + ' '-}}\n {%- endfor -%}\n {%- endif -%}\n {%- set loop_messages = messages[1:] -%}\n {%- endif -%}\n {%- if tools -%}\n {%- for tool in tools %}\n {{- '<|tool>' -}}\n {{- format_function_declaration(tool) | trim -}}\n {{- '<tool|>' -}}\n {%- endfor %}\n {%- set ns.prev_message_type = 'tool' -%}\n {%- endif -%}\n {{- '<turn|>\\n' -}}\n{%- endif %}\n\n{#- Pre-scan: find last user message index for reasoning guard -#}\n{%- set ns_turn = namespace(last_user_idx=-1) -%}\n{%- for i in range(loop_messages | length) -%}\n {%- if loop_messages[i]['role'] == 'user' -%}\n {%- set ns_turn.last_user_idx = i -%}\n {%- endif -%}\n{%- endfor -%}\n\n{#- Loop through messages -#}\n{%- for message in loop_messages -%}\n {%- if message['role'] != 'tool' -%}\n {%- set ns.prev_message_type = None -%}\n {%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}\n {#- Detect continuation using tracked state — O(1) instead of O(n) backward scan -#}\n {%- set continue_same_model_turn = (role == 'model' and ns.prev_non_tool_role == 'assistant') -%}\n {%- if not continue_same_model_turn -%}\n {{- '<|turn>' + role + '\\n' }}\n {%- endif -%}\n\n {#- Render reasoning/reasoning_content as thinking channel -#}\n {%- set thinking_text = message.get('reasoning') or message.get('reasoning_content') -%}\n {%- set thinking_gate = (loop.index0 > ns_turn.last_user_idx) or (preserve_thinking and message.get('tool_calls')) -%}\n {%- if thinking_text and thinking_gate -%}\n {{- '<|channel>thought\\n' + thinking_text + '\\n<channel|>' -}}\n {%- endif -%}\n\n {%- if message.get('tool_calls') -%}\n {%- for tool_call in message.get('tool_calls') -%}\n {%- set function = tool_call['function'] -%}\n {{- '<|tool_call>call:' + function['name'] + '{' -}}\n {%- if function['arguments'] is mapping -%}\n {%- set ns_args = namespace(found_first=false) -%}\n {%- for key, value in function['arguments'] | dictsort -%}\n {%- if ns_args.found_first %},{% endif -%}\n {%- set ns_args.found_first = true -%}\n {{- key -}}:{{- format_argument(value, escape_keys=False) -}}\n {%- endfor -%}\n {%- elif function['arguments'] is none -%}\n {%- elif function['arguments'] is string -%}\n {#- Pre-serialized args (e.g. an OpenAI JSON string). We cannot JSON-parse\n portably in-template, so render non-fatally instead of erroring. Strip an\n outer {...} so it composes with the DSL braces rather than double-wrapping.\n Prefer passing arguments as a mapping for exact Gemma DSL. -#}\n {%- set argstr = function['arguments'] | trim -%}\n {%- if argstr[:1] == '{' and argstr[-1:] == '}' -%}\n {{- argstr[1:-1] -}}\n {%- else -%}\n {{- function['arguments'] -}}\n {%- endif -%}\n {%- endif -%}\n {{- '}<tool_call|>' -}}\n {%- endfor -%}\n {%- set ns.prev_message_type = 'tool_call' -%}\n {%- endif -%}\n\n {%- set ns_tr_out = namespace(flag=false) -%}\n {%- if message.get('tool_responses') -%}\n {#- Legacy: tool_responses embedded on the assistant message (Google/Gemma native) -#}\n {%- for tool_response in message.get('tool_responses') -%}\n {{- format_tool_response_block(tool_response['name'] | default('unknown', true), tool_response['response']) -}}\n {%- set ns_tr_out.flag = true -%}\n {%- set ns.prev_message_type = 'tool_response' -%}\n {%- endfor -%}\n {%- elif message.get('tool_calls') -%}\n {#- OpenAI Chat Completions: forward-scan consecutive role:tool messages -#}\n {%- set ns_tool_scan = namespace(stopped=false) -%}\n {%- for k in range(loop.index0 + 1, loop_messages | length) -%}\n {%- if ns_tool_scan.stopped -%}\n {%- elif loop_messages[k]['role'] != 'tool' -%}\n {%- set ns_tool_scan.stopped = true -%}\n {%- else -%}\n {%- set follow = loop_messages[k] -%}\n {#- Resolve tool_call_id to function name -#}\n {%- set ns_tname = namespace(name=follow.get('name') or 'unknown') -%}\n {%- for tc in message.get('tool_calls') -%}\n {%- if tc.get('id') == follow.get('tool_call_id') -%}\n {%- set ns_tname.name = tc['function']['name'] -%}\n {%- endif -%}\n {%- endfor -%}\n {#- Handle content as string or content-parts array -#}\n {%- set tool_body = follow.get('content') -%}\n {%- if tool_body is string -%}\n {{- format_tool_response_block(ns_tname.name, tool_body) -}}\n {%- elif tool_body is sequence and tool_body is not string -%}\n {%- set ns_txt = namespace(s='') -%}\n {%- for part in tool_body -%}\n {%- if part.get('type') == 'text' -%}\n {%- set ns_txt.s = ns_txt.s + (part.get('text') | default('')) -%}\n {%- endif -%}\n {%- endfor -%}\n {{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}\n {%- for part in tool_body -%}\n {%- if part.get('type') in ['image', 'image_url'] -%}\n {{- '<|image|>' -}}\n {%- elif part.get('type') in ['audio', 'input_audio'] -%}\n {{- '<|audio|>' -}}\n {%- elif part.get('type') == 'video' -%}\n {{- '<|video|>' -}}\n {%- endif -%}\n {%- endfor -%}\n {%- else -%}\n {{- format_tool_response_block(ns_tname.name, tool_body) -}}\n {%- endif -%}\n {%- set ns_tr_out.flag = true -%}\n {%- set ns.prev_message_type = 'tool_response' -%}\n {%- endif -%}\n {%- endfor -%}\n {%- endif -%}\n\n {%- set captured_content -%}\n {%- if message.get('content') is string -%}\n {%- if role == 'model' -%}\n {{- strip_thinking(message['content']) -}}\n {%- else -%}\n {{- message['content'] | trim -}}\n {%- endif -%}\n {%- elif message.get('content') is sequence -%}\n {%- for item in message['content'] -%}\n {%- if item.get('type') == 'text' -%}\n {%- if role == 'model' -%}\n {{- strip_thinking(item['text']) -}}\n {%- else -%}\n {{- item['text'] | trim -}}\n {%- endif -%}\n {%- elif item.get('type') in ['image', 'image_url'] -%}\n {{- '<|image|>' -}}\n {%- elif item.get('type') in ['audio', 'input_audio'] -%}\n {{- '<|audio|>' -}}\n {%- elif item.get('type') == 'video' -%}\n {{- '<|video|>' -}}\n {%- endif -%}\n {%- endfor -%}\n {%- endif -%}\n {%- endset -%}\n\n {{- captured_content -}}\n {%- set has_content = captured_content | trim | length > 0 -%}\n\n {#- Forward-scan: find next non-tool message role for continuation detection -#}\n {%- set next_nt = namespace(role=None, found=false) -%}\n {%- for j in range(loop.index0 + 1, loop_messages | length) -%}\n {%- if not next_nt.found -%}\n {%- if loop_messages[j]['role'] != 'tool' -%}\n {%- set next_nt.role = loop_messages[j]['role'] -%}\n {%- set next_nt.found = true -%}\n {%- endif -%}\n {%- endif -%}\n {%- endfor -%}\n\n {%- set continues_into_next = (\n role == 'model'\n and next_nt.role == 'assistant'\n and (not message.get('tool_calls') or ns_tr_out.flag)\n ) -%}\n\n {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}\n {{- '<|tool_response>' -}}\n {%- elif continues_into_next -%}\n {%- elif not (ns_tr_out.flag and not has_content and not next_nt.found) -%}\n {{- '<turn|>\\n' -}}\n {%- endif -%}\n\n {#- Track previous non-tool role for next iteration (avoids O(n) backward scan) -#}\n {%- set ns.prev_non_tool_role = message['role'] -%}\n {%- endif -%}\n{%- endfor -%}\n\n{%- if add_generation_prompt -%}\n {%- if ns.prev_message_type != 'tool_response' and ns.prev_message_type != 'tool_call' -%}\n {{- '<|turn>model\\n' -}}\n {%- elif ns.prev_message_type == 'tool_response' and enable_thinking -%}\n {{- '<|channel>thought\\n' -}}\n {%- endif -%}\n{%- endif -%}\n"
254
+ }