LLMWildling commited on
Commit
7602aea
·
verified ·
1 Parent(s): feb815b

Upload gemma-4-90b-a9b-coder

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
README.md ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: gemma
3
+ base_model: gemma-4
4
+ library_name: transformers
5
+ pipeline_tag: text-generation
6
+ tags:
7
+ - gemma
8
+ - gemma-4
9
+ - coder
10
+ - mixture-of-experts
11
+ - mxfp4
12
+ - thinking
13
+ - tool-use
14
+ - long-context
15
+ ---
16
+
17
+ # gemma-4-90b-a9b-coder
18
+
19
+ gemma-4-90b-a9b-coder is a Gemma 4 based coder model for software engineering, code
20
+ editing, Q/A, tool use, and long-context assistant workflows.
21
+
22
+ ## model
23
+
24
+ - Family: `gemma-4`
25
+ - Variant: `coder`
26
+ - Model type: sparse Mixture-of-Experts language model
27
+ - Total logical text parameters: approximately `90.3B`
28
+ - Active logical text parameters per token: approximately `9.1B`
29
+ - Active experts per token: `33`
30
+ - Weight format: MXFP4 expert weights with BF16 shared weights
31
+ - Context: up to `200000` tokens in the listed vLLM configuration
32
+
33
+ ## serving
34
+
35
+ ```bash
36
+ CUDA_VISIBLE_DEVICES=0,1 vllm serve /path/to/gemma-4-90b-a9b-coder \
37
+ --served-model-name vllm/doobee \
38
+ --host 0.0.0.0 \
39
+ --port 23333 \
40
+ --dtype bfloat16 \
41
+ --tensor-parallel-size 2 \
42
+ --enable-expert-parallel \
43
+ --max-model-len 200000 \
44
+ --gpu-memory-utilization 0.96 \
45
+ --trust-remote-code \
46
+ --reasoning-parser gemma4 \
47
+ --tool-call-parser gemma4 \
48
+ --enable-auto-tool-choice \
49
+ --default-chat-template-kwargs '{"enable_thinking": true}' \
50
+ --generation-config vllm \
51
+ --language-model-only \
52
+ --skip-mm-profiling \
53
+ --max-num-seqs 1 \
54
+ --max-num-batched-tokens 8192
55
+ ```
56
+
57
+ For clients that should not receive reasoning text, send
58
+ `"include_reasoning": false` in chat-completion requests.
59
+
60
+ ## files
61
+
62
+ - `config.json`
63
+ - `generation_config.json`
64
+ - `tokenizer.json`
65
+ - `tokenizer_config.json`
66
+ - `chat_template.jinja`
67
+ - `model.safetensors.index.json`
68
+ - MXFP4/BF16 safetensor shards
69
+
70
+ ## license
71
+
72
+ This model is released under the Gemma license.
chat_template.jinja ADDED
@@ -0,0 +1,408 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- macro format_parameters(properties, required) -%}
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 key not in standard_keys -%}
7
+ {%- set type_value = value['type'] -%}
8
+ {%- set type_ns = namespace(primary=type_value, nullable=false) -%}
9
+ {%- if type_value is sequence and type_value is not string -%}
10
+ {%- set type_ns.primary = none -%}
11
+ {%- for type_item in type_value -%}
12
+ {%- if type_item | lower == 'null' -%}
13
+ {%- set type_ns.nullable = true -%}
14
+ {%- elif type_ns.primary is none -%}
15
+ {%- set type_ns.primary = type_item -%}
16
+ {%- endif -%}
17
+ {%- endfor -%}
18
+ {%- if type_ns.primary is none -%}
19
+ {%- set type_ns.primary = 'null' -%}
20
+ {%- endif -%}
21
+ {%- endif -%}
22
+ {%- if ns.found_first %},{% endif -%}
23
+ {%- set ns.found_first = true -%}
24
+ {{ key }}:{
25
+ {%- if value['description'] -%}
26
+ description:<|"|>{{ value['description'] }}<|"|>
27
+ {%- set add_comma = true -%}
28
+ {%- endif -%}
29
+ {%- if type_ns.primary | upper == 'STRING' -%}
30
+ {%- if value['enum'] -%}
31
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
32
+ enum:{{ format_argument(value['enum']) }}
33
+ {%- endif -%}
34
+ {%- elif type_ns.primary | upper == 'ARRAY' -%}
35
+ {%- if value['items'] is mapping and value['items'] -%}
36
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
37
+ items:{
38
+ {%- set ns_items = namespace(found_first=false) -%}
39
+ {%- for item_key, item_value in value['items'] | dictsort -%}
40
+ {%- if item_value is not none -%}
41
+ {%- if ns_items.found_first %},{% endif -%}
42
+ {%- set ns_items.found_first = true -%}
43
+ {%- if item_key == 'properties' -%}
44
+ properties:{
45
+ {%- if item_value is mapping -%}
46
+ {{- format_parameters(item_value, value['items']['required'] | default([])) -}}
47
+ {%- endif -%}
48
+ }
49
+ {%- elif item_key == 'required' -%}
50
+ required:[
51
+ {%- for req_item in item_value -%}
52
+ <|"|>{{- req_item -}}<|"|>
53
+ {%- if not loop.last %},{% endif -%}
54
+ {%- endfor -%}
55
+ ]
56
+ {%- elif item_key == 'type' -%}
57
+ {%- if item_value is string -%}
58
+ type:{{ format_argument(item_value | upper) }}
59
+ {%- else -%}
60
+ {%- set item_type_ns = namespace(primary=none, nullable=false) -%}
61
+ {%- for item_type in item_value -%}
62
+ {%- if item_type | lower == 'null' -%}
63
+ {%- set item_type_ns.nullable = true -%}
64
+ {%- elif item_type_ns.primary is none -%}
65
+ {%- set item_type_ns.primary = item_type -%}
66
+ {%- endif -%}
67
+ {%- endfor -%}
68
+ {%- if item_type_ns.primary is none -%}
69
+ {%- set item_type_ns.primary = 'null' -%}
70
+ {%- endif -%}
71
+ type:{{ format_argument(item_type_ns.primary | upper) }}
72
+ {%- if item_type_ns.nullable -%},nullable:true{%- endif -%}
73
+ {%- endif -%}
74
+ {%- else -%}
75
+ {{ item_key }}:{{ format_argument(item_value) }}
76
+ {%- endif -%}
77
+ {%- endif -%}
78
+ {%- endfor -%}
79
+ }
80
+ {%- endif -%}
81
+ {%- endif -%}
82
+ {%- if value['nullable'] or type_ns.nullable %}
83
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
84
+ nullable:true
85
+ {%- endif -%}
86
+ {%- if type_ns.primary | upper == 'OBJECT' -%}
87
+ {%- if value['properties'] is defined and value['properties'] is mapping -%}
88
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
89
+ properties:{
90
+ {{- format_parameters(value['properties'], value['required'] | default([])) -}}
91
+ }
92
+ {%- elif value is mapping -%}
93
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
94
+ properties:{
95
+ {{- format_parameters(value, value['required'] | default([])) -}}
96
+ }
97
+ {%- endif -%}
98
+ {%- if value['required'] -%}
99
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
100
+ required:[
101
+ {%- for item in value['required'] | default([]) -%}
102
+ <|"|>{{- item -}}<|"|>
103
+ {%- if not loop.last %},{% endif -%}
104
+ {%- endfor -%}
105
+ ]
106
+ {%- endif -%}
107
+ {%- endif -%}
108
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
109
+ type:<|"|>{{ type_ns.primary | upper }}<|"|>}
110
+ {%- endif -%}
111
+ {%- endfor -%}
112
+ {%- endmacro -%}
113
+ {%- macro format_function_declaration(tool_data) -%}
114
+ declaration:{{- tool_data['function']['name'] -}}{description:<|"|>{{- tool_data['function']['description'] -}}<|"|>
115
+ {%- set params = tool_data['function']['parameters'] -%}
116
+ {%- if params -%}
117
+ ,parameters:{
118
+ {%- if params['properties'] -%}
119
+ properties:{ {{- format_parameters(params['properties'], params['required']) -}} },
120
+ {%- endif -%}
121
+ {%- if params['required'] -%}
122
+ required:[
123
+ {%- for item in params['required'] -%}
124
+ <|"|>{{- item -}}<|"|>
125
+ {{- ',' if not loop.last -}}
126
+ {%- endfor -%}
127
+ ],
128
+ {%- endif -%}
129
+ {%- if params['type'] -%}
130
+ type:<|"|>{{- params['type'] | upper -}}<|"|>}
131
+ {%- endif -%}
132
+ {%- endif -%}
133
+ {%- if 'response' in tool_data['function'] -%}
134
+ {%- set response_declaration = tool_data['function']['response'] -%}
135
+ ,response:{
136
+ {%- if response_declaration['description'] -%}
137
+ description:<|"|>{{- response_declaration['description'] -}}<|"|>,
138
+ {%- endif -%}
139
+ {%- if response_declaration['type'] | upper == 'OBJECT' -%}
140
+ type:<|"|>{{- response_declaration['type'] | upper -}}<|"|>}
141
+ {%- endif -%}
142
+ {%- endif -%}
143
+ }
144
+ {%- endmacro -%}
145
+ {%- macro format_argument(argument, escape_keys=True) -%}
146
+ {%- if argument is string -%}
147
+ {{- '<|"|>' + argument + '<|"|>' -}}
148
+ {%- elif argument is boolean -%}
149
+ {{- 'true' if argument else 'false' -}}
150
+ {%- elif argument is mapping -%}
151
+ {{- '{' -}}
152
+ {%- set ns = namespace(found_first=false) -%}
153
+ {%- for key, value in argument | dictsort -%}
154
+ {%- if ns.found_first %},{% endif -%}
155
+ {%- set ns.found_first = true -%}
156
+ {%- if escape_keys -%}
157
+ {{- '<|"|>' + key + '<|"|>' -}}
158
+ {%- else -%}
159
+ {{- key -}}
160
+ {%- endif -%}
161
+ :{{- format_argument(value, escape_keys=escape_keys) -}}
162
+ {%- endfor -%}
163
+ {{- '}' -}}
164
+ {%- elif argument is sequence -%}
165
+ {{- '[' -}}
166
+ {%- for item in argument -%}
167
+ {{- format_argument(item, escape_keys=escape_keys) -}}
168
+ {%- if not loop.last %},{% endif -%}
169
+ {%- endfor -%}
170
+ {{- ']' -}}
171
+ {%- else -%}
172
+ {{- argument -}}
173
+ {%- endif -%}
174
+ {%- endmacro -%}
175
+ {%- macro render_assistant_text(text, keep_reasoning=false) -%}
176
+ {%- set total_blocks = (text.split('<channel|>') | length) - 1 -%}
177
+ {%- set ns = namespace(result='', seen=0) -%}
178
+ {%- for part in text.split('<channel|>') -%}
179
+ {%- if '<|channel>' in part -%}
180
+ {%- set pieces = part.split('<|channel>') -%}
181
+ {%- set ns.result = ns.result + pieces[0] -%}
182
+ {%- set ns.seen = ns.seen + 1 -%}
183
+ {%- if keep_reasoning and ns.seen == total_blocks -%}
184
+ {%- set ns.result = ns.result + '<|channel>' + pieces[1] + '<channel|>' -%}
185
+ {%- endif -%}
186
+ {%- else -%}
187
+ {%- set ns.result = ns.result + part -%}
188
+ {%- endif -%}
189
+ {%- endfor -%}
190
+ {{- ns.result | trim -}}
191
+ {%- endmacro -%}
192
+
193
+ {%- macro format_tool_response_block(tool_name, response) -%}
194
+ {{- '<|tool_response>' -}}
195
+ {%- if response is mapping -%}
196
+ {{- 'response:' + tool_name + '{' -}}
197
+ {%- for key, value in response | dictsort -%}
198
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
199
+ {%- if not loop.last %},{% endif -%}
200
+ {%- endfor -%}
201
+ {{- '}' -}}
202
+ {%- else -%}
203
+ {{- 'response:' + tool_name + '{value:' + format_argument(response, escape_keys=False) + '}' -}}
204
+ {%- endif -%}
205
+ {{- '<tool_response|>' -}}
206
+ {%- endmacro -%}
207
+
208
+ {%- set ns = namespace(prev_message_type=None) -%}
209
+ {%- set loop_messages = messages -%}
210
+ {%- if enable_thinking is not defined -%}
211
+ {%- set enable_thinking = true -%}
212
+ {%- endif -%}
213
+ {{- bos_token -}}
214
+ {#- Handle System/Tool Definitions Block -#}
215
+ {%- if (enable_thinking is defined and enable_thinking) or tools or messages[0]['role'] in ['system', 'developer'] -%}
216
+ {{- '<|turn>system\n' -}}
217
+
218
+ {#- Inject Thinking token at the very top of the FIRST system turn -#}
219
+ {%- if enable_thinking is defined and enable_thinking -%}
220
+ {{- '<|think|>\n' -}}
221
+ {%- set ns.prev_message_type = 'think' -%}
222
+ {%- endif -%}
223
+
224
+ {%- if messages[0]['role'] in ['system', 'developer'] -%}
225
+ {%- set system_content = messages[0]['content'] -%}
226
+ {%- if system_content is string -%}
227
+ {{- system_content | trim -}}
228
+ {%- elif system_content is sequence -%}
229
+ {%- for item in system_content -%}
230
+ {%- if item['type'] == 'text' -%}
231
+ {{- item['text'] | trim -}}
232
+ {%- endif -%}
233
+ {%- endfor -%}
234
+ {%- endif -%}
235
+ {%- set loop_messages = messages[1:] -%}
236
+ {%- endif -%}
237
+
238
+ {%- if tools -%}
239
+ {%- for tool in tools %}
240
+ {{- '<|tool>' -}}
241
+ {{- format_function_declaration(tool) | trim -}}
242
+ {{- '<tool|>' -}}
243
+ {%- endfor %}
244
+ {%- set ns.prev_message_type = 'tool' -%}
245
+ {%- endif -%}
246
+
247
+ {{- '<turn|>\n' -}}
248
+ {%- endif %}
249
+
250
+ {#- Pre-scan: find last user and last tagged reasoning block. -#}
251
+ {%- set ns_turn = namespace(last_user_idx=-1, last_reasoning_idx=-1, reasoning_blocks=0) -%}
252
+ {%- for i in range(loop_messages | length) -%}
253
+ {%- if loop_messages[i]['role'] == 'user' -%}
254
+ {%- set ns_turn.last_user_idx = i -%}
255
+ {%- endif -%}
256
+ {%- if loop_messages[i]['role'] == 'assistant' -%}
257
+ {%- set msg_content = loop_messages[i]['content'] -%}
258
+ {%- if msg_content is string -%}
259
+ {%- set block_count = (msg_content.split('<channel|>') | length) - 1 -%}
260
+ {%- if block_count > 0 and '<|channel>' in msg_content -%}
261
+ {%- set ns_turn.reasoning_blocks = ns_turn.reasoning_blocks + block_count -%}
262
+ {%- set ns_turn.last_reasoning_idx = i -%}
263
+ {%- endif -%}
264
+ {%- elif msg_content is sequence -%}
265
+ {%- for item in msg_content -%}
266
+ {%- if item['type'] == 'text' -%}
267
+ {%- set item_text = item['text'] | default('') -%}
268
+ {%- set block_count = (item_text.split('<channel|>') | length) - 1 -%}
269
+ {%- if block_count > 0 and '<|channel>' in item_text -%}
270
+ {%- set ns_turn.reasoning_blocks = ns_turn.reasoning_blocks + block_count -%}
271
+ {%- set ns_turn.last_reasoning_idx = i -%}
272
+ {%- endif -%}
273
+ {%- endif -%}
274
+ {%- endfor -%}
275
+ {%- endif -%}
276
+ {%- endif -%}
277
+ {%- endfor -%}
278
+ {%- if keep_last_reasoning is not defined -%}
279
+ {%- set keep_last_reasoning = false -%}
280
+ {%- endif -%}
281
+
282
+ {#- Loop through messages -#}
283
+ {%- for message in loop_messages -%}
284
+ {%- if message['role'] != 'tool' -%}
285
+ {%- set ns.prev_message_type = None -%}
286
+ {%- set message_idx = loop.index0 -%}
287
+ {%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}
288
+ {#- Detect continuation: suppress duplicate <|turn>model when previous non-tool message was also assistant -#}
289
+ {%- set prev_nt = namespace(role=None, found=false) -%}
290
+ {%- if loop.index0 > 0 -%}
291
+ {%- for j in range(loop.index0 - 1, -1, -1) -%}
292
+ {%- if not prev_nt.found -%}
293
+ {%- if loop_messages[j]['role'] != 'tool' -%}
294
+ {%- set prev_nt.role = loop_messages[j]['role'] -%}
295
+ {%- set prev_nt.found = true -%}
296
+ {%- endif -%}
297
+ {%- endif -%}
298
+ {%- endfor -%}
299
+ {%- endif -%}
300
+ {%- set continue_same_model_turn = (role == 'model' and prev_nt.role == 'assistant') -%}
301
+ {%- if not continue_same_model_turn -%}
302
+ {{- '<|turn>' + role + '\n' }}
303
+ {%- endif -%}
304
+
305
+ {%- if message['tool_calls'] -%}
306
+ {%- for tool_call in message['tool_calls'] -%}
307
+ {%- set function = tool_call['function'] -%}
308
+ {{- '<|tool_call>call:' + function['name'] + '{' -}}
309
+ {%- if function['arguments'] is mapping -%}
310
+ {%- set ns_args = namespace(found_first=false) -%}
311
+ {%- for key, value in function['arguments'] | dictsort -%}
312
+ {%- if ns_args.found_first %},{% endif -%}
313
+ {%- set ns_args.found_first = true -%}
314
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
315
+ {%- endfor -%}
316
+ {%- elif function['arguments'] is string -%}
317
+ {{- function['arguments'] -}}
318
+ {%- endif -%}
319
+ {{- '}<tool_call|>' -}}
320
+ {%- endfor -%}
321
+ {%- set ns.prev_message_type = 'tool_call' -%}
322
+ {%- endif -%}
323
+
324
+ {%- set ns_tr_out = namespace(flag=false) -%}
325
+ {%- if message.get('tool_responses') -%}
326
+ {#- Legacy: tool_responses embedded on the assistant message (Google/Gemma native) -#}
327
+ {%- for tool_response in message['tool_responses'] -%}
328
+ {{- format_tool_response_block(tool_response['name'] | default('unknown'), tool_response['response']) -}}
329
+ {%- set ns_tr_out.flag = true -%}
330
+ {%- set ns.prev_message_type = 'tool_response' -%}
331
+ {%- endfor -%}
332
+ {%- elif message.get('tool_calls') -%}
333
+ {#- OpenAI Chat Completions: forward-scan consecutive role:tool messages -#}
334
+ {%- set ns_tool_scan = namespace(stopped=false) -%}
335
+ {%- for k in range(loop.index0 + 1, loop_messages | length) -%}
336
+ {%- if ns_tool_scan.stopped -%}
337
+ {%- elif loop_messages[k]['role'] != 'tool' -%}
338
+ {%- set ns_tool_scan.stopped = true -%}
339
+ {%- else -%}
340
+ {%- set follow = loop_messages[k] -%}
341
+ {#- Resolve tool_call_id to function name -#}
342
+ {%- set ns_tname = namespace(name=follow.get('name') | default('unknown')) -%}
343
+ {%- for tc in message['tool_calls'] -%}
344
+ {%- if tc.get('id') == follow.get('tool_call_id') -%}
345
+ {%- set ns_tname.name = tc['function']['name'] -%}
346
+ {%- endif -%}
347
+ {%- endfor -%}
348
+ {#- Handle content as string or content-parts array -#}
349
+ {%- set tool_body = follow.get('content') -%}
350
+ {%- if tool_body is string -%}
351
+ {{- format_tool_response_block(ns_tname.name, tool_body) -}}
352
+ {%- elif tool_body is sequence and tool_body is not string -%}
353
+ {%- set ns_txt = namespace(s='') -%}
354
+ {%- for part in tool_body -%}
355
+ {%- if part.get('type') == 'text' -%}
356
+ {%- set ns_txt.s = ns_txt.s + (part.get('text') | default('')) -%}
357
+ {%- endif -%}
358
+ {%- endfor -%}
359
+ {{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
360
+ {%- else -%}
361
+ {{- format_tool_response_block(ns_tname.name, tool_body) -}}
362
+ {%- endif -%}
363
+ {%- set ns_tr_out.flag = true -%}
364
+ {%- set ns.prev_message_type = 'tool_response' -%}
365
+ {%- endif -%}
366
+ {%- endfor -%}
367
+ {%- endif -%}
368
+
369
+ {%- if message['content'] is string -%}
370
+ {%- if role == 'model' -%}
371
+ {{- render_assistant_text(message['content'], keep_last_reasoning and message_idx == ns_turn.last_reasoning_idx) -}}
372
+ {%- else -%}
373
+ {{- message['content'] | trim -}}
374
+ {%- endif -%}
375
+ {%- elif message['content'] is sequence -%}
376
+ {%- for item in message['content'] -%}
377
+ {%- if item['type'] == 'text' -%}
378
+ {%- if role == 'model' -%}
379
+ {{- render_assistant_text(item['text'], keep_last_reasoning and message_idx == ns_turn.last_reasoning_idx) -}}
380
+ {%- else -%}
381
+ {{- item['text'] | trim -}}
382
+ {%- endif -%}
383
+ {%- elif item['type'] == 'image' -%}
384
+ {{- '<|image|>' -}}
385
+ {%- set ns.prev_message_type = 'image' -%}
386
+ {%- elif item['type'] == 'audio' -%}
387
+ {{- '<|audio|>' -}}
388
+ {%- set ns.prev_message_type = 'audio' -%}
389
+ {%- elif item['type'] == 'video' -%}
390
+ {{- '<|video|>' -}}
391
+ {%- set ns.prev_message_type = 'video' -%}
392
+ {%- endif -%}
393
+ {%- endfor -%}
394
+ {%- endif -%}
395
+
396
+ {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
397
+ {{- '<|tool_response>' -}}
398
+ {%- elif not (ns_tr_out.flag and not message.get('content')) -%}
399
+ {{- '<turn|>\n' -}}
400
+ {%- endif -%}
401
+ {%- endif -%}
402
+ {%- endfor -%}
403
+
404
+ {%- if add_generation_prompt -%}
405
+ {%- if ns.prev_message_type != 'tool_call' -%}
406
+ {{- '<|turn>model\n' -}}
407
+ {%- endif -%}
408
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Gemma4ForConditionalGeneration"
4
+ ],
5
+ "audio_config": null,
6
+ "audio_token_id": 258881,
7
+ "boa_token_id": 256000,
8
+ "boi_token_id": 255999,
9
+ "torch_dtype": "bfloat16",
10
+ "eoa_token_id": 258883,
11
+ "eoa_token_index": 258883,
12
+ "eoi_token_id": 258882,
13
+ "eos_token_id": 106,
14
+ "image_token_id": 258880,
15
+ "initializer_range": 0.02,
16
+ "model_type": "gemma4",
17
+ "pad_token_id": 0,
18
+ "text_config": {
19
+ "attention_bias": false,
20
+ "attention_dropout": 0.0,
21
+ "attention_k_eq_v": true,
22
+ "bos_token_id": 2,
23
+ "torch_dtype": "bfloat16",
24
+ "enable_moe_block": true,
25
+ "eos_token_id": 1,
26
+ "final_logit_softcapping": 30.0,
27
+ "global_head_dim": 512,
28
+ "head_dim": 256,
29
+ "hidden_activation": "gelu_pytorch_tanh",
30
+ "hidden_size": 2816,
31
+ "hidden_size_per_layer_input": 0,
32
+ "initializer_range": 0.02,
33
+ "intermediate_size": 2112,
34
+ "layer_types": [
35
+ "sliding_attention",
36
+ "sliding_attention",
37
+ "sliding_attention",
38
+ "sliding_attention",
39
+ "sliding_attention",
40
+ "full_attention",
41
+ "sliding_attention",
42
+ "sliding_attention",
43
+ "sliding_attention",
44
+ "sliding_attention",
45
+ "sliding_attention",
46
+ "full_attention",
47
+ "sliding_attention",
48
+ "sliding_attention",
49
+ "sliding_attention",
50
+ "sliding_attention",
51
+ "sliding_attention",
52
+ "full_attention",
53
+ "sliding_attention",
54
+ "sliding_attention",
55
+ "sliding_attention",
56
+ "sliding_attention",
57
+ "sliding_attention",
58
+ "full_attention",
59
+ "sliding_attention",
60
+ "sliding_attention",
61
+ "sliding_attention",
62
+ "sliding_attention",
63
+ "sliding_attention",
64
+ "full_attention"
65
+ ],
66
+ "max_position_embeddings": 262144,
67
+ "model_type": "gemma4_text",
68
+ "moe_intermediate_size": 704,
69
+ "num_attention_heads": 16,
70
+ "num_experts": 488,
71
+ "num_global_key_value_heads": 2,
72
+ "num_hidden_layers": 30,
73
+ "num_key_value_heads": 8,
74
+ "num_kv_shared_layers": 0,
75
+ "pad_token_id": 0,
76
+ "rms_norm_eps": 1e-06,
77
+ "rope_parameters": {
78
+ "full_attention": {
79
+ "partial_rotary_factor": 0.25,
80
+ "rope_theta": 1000000.0,
81
+ "rope_type": "proportional"
82
+ },
83
+ "sliding_attention": {
84
+ "rope_theta": 10000.0,
85
+ "rope_type": "default"
86
+ }
87
+ },
88
+ "sliding_window": 1024,
89
+ "tie_word_embeddings": true,
90
+ "top_k_experts": 33,
91
+ "use_bidirectional_attention": "vision",
92
+ "use_cache": true,
93
+ "use_double_wide_mlp": false,
94
+ "vocab_size": 262144,
95
+ "vocab_size_per_layer_input": 262144,
96
+ "quantization_config": {
97
+ "quant_method": "mxfp4",
98
+ "quant_type": "mxfp4",
99
+ "block_size": 32,
100
+ "quantized_tensors": "gemma4_experts_only",
101
+ "converter_layout": "vllm_fused_moe"
102
+ }
103
+ },
104
+ "tie_word_embeddings": true,
105
+ "transformers_version": "5.6.0.dev0",
106
+ "video_token_id": 258884,
107
+ "vision_config": {
108
+ "_name_or_path": "",
109
+ "architectures": null,
110
+ "attention_bias": false,
111
+ "attention_dropout": 0.0,
112
+ "chunk_size_feed_forward": 0,
113
+ "default_output_length": 280,
114
+ "torch_dtype": "bfloat16",
115
+ "global_head_dim": 72,
116
+ "head_dim": 72,
117
+ "hidden_activation": "gelu_pytorch_tanh",
118
+ "hidden_size": 1152,
119
+ "id2label": {
120
+ "0": "LABEL_0",
121
+ "1": "LABEL_1"
122
+ },
123
+ "initializer_range": 0.02,
124
+ "intermediate_size": 4304,
125
+ "is_encoder_decoder": false,
126
+ "label2id": {
127
+ "LABEL_0": 0,
128
+ "LABEL_1": 1
129
+ },
130
+ "max_position_embeddings": 131072,
131
+ "model_type": "gemma4_vision",
132
+ "num_attention_heads": 16,
133
+ "num_hidden_layers": 27,
134
+ "num_key_value_heads": 16,
135
+ "output_attentions": false,
136
+ "output_hidden_states": false,
137
+ "patch_size": 16,
138
+ "pooling_kernel_size": 3,
139
+ "position_embedding_size": 10240,
140
+ "problem_type": null,
141
+ "return_dict": true,
142
+ "rms_norm_eps": 1e-06,
143
+ "rope_parameters": {
144
+ "rope_theta": 100.0,
145
+ "rope_type": "default"
146
+ },
147
+ "standardize": true,
148
+ "use_clipped_linears": false
149
+ },
150
+ "vision_soft_tokens_per_image": 280,
151
+ "quantization_config": {
152
+ "quant_method": "mxfp4",
153
+ "quant_type": "mxfp4",
154
+ "block_size": 32,
155
+ "quantized_tensors": "gemma4_experts_only",
156
+ "converter_layout": "vllm_fused_moe"
157
+ }
158
+ }
generation_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 2,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 1,
6
+ 106,
7
+ 50
8
+ ],
9
+ "pad_token_id": 0,
10
+ "temperature": 1.0,
11
+ "top_k": 64,
12
+ "top_p": 0.95,
13
+ "transformers_version": "5.5.0.dev0"
14
+ }
model-00001.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:05a291c4dd55ba23dc952392f5044c12790b942b8ea8ed97e1b2eb01a250914e
3
+ size 4293689992
model-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65265e14ee5989b8756c6f76817135b8832b49f29206398681430e5e1605329f
3
+ size 3863405348
model-00003.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aadd3a8d6a0aba0708809c4e9c059c2afded218661f16c6060bfb2d369a97fae
3
+ size 3364062296
model-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:13a8c70a0cad7353871af43c8b79a9364a7f23f925a82b3af36379a80368a36a
3
+ size 3364062304
model-00005.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2ee820ff66b191ecf4f30c80272a1400259fb44339f0ed1d8a256adf92622fe3
3
+ size 3364062304
model-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2d2bec0cd2c38d22094f4b7ae7fc68c9e9be0f811ffc2e4e628761fb77f8b30f
3
+ size 3364062304
model-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6a72f8ceadeb28bab8b54830871ae4242d64fa8226bd6149382dcdd7a51ec7b3
3
+ size 3364062304
model-00008.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f9c870fd266b31ee4b7ef9bdbd21e07d0bcbfd98756c45c19839aa7b6760fe68
3
+ size 3364062296
model-00009.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:426ed979c619533d463cfbf723b3d5ad87e689759abbf233737269e79a0dfd84
3
+ size 3364062304
model-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca78cb047ee5548d0b6d64473259fdaca35becf21973ff8b55ce28bf6d4c774a
3
+ size 3364062304
model-00011.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:410cc16c63f3595226702b16d7c726cdcb80dab94b4fc47d20fe139b8c46f258
3
+ size 3364062304
model-00012.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0ee28a5dc3cf7d50e038e2a7fdda1ac86ab85a61dc53813b1221cce32751e47f
3
+ size 3364062304
model-00013.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:38feea268949c00d0d04407123bdf2ca1e884dd7012155720cebf3c3f7b6237f
3
+ size 3364062296
model-00014.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a3c0cea1e0251e0def56dbfe46270f0c09f1fd6bf40eeacfe4f58aaf34f1ef19
3
+ size 3364062296
model-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d5b18cf96cacc6c9253f3cf338df681e321c98f9c7ca02b58d172cdc6e19d7ba
3
+ size 3364062296
model-00016.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:901d3d9855de818b6e2a0ded5db78eda0a39e20db93cddb808e95d455b56348a
3
+ size 3364062296
model-00017.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:12e133d8f0dac6274845fe072604ff918e13c96a1fcd6969ee00a9426c8d9979
3
+ size 1203843128
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
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,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": "<turn|>",
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
+ "mask_token": "<mask>",
21
+ "model_max_length": 262144,
22
+ "model_specific_special_tokens": {
23
+ "audio_token": "<|audio|>",
24
+ "boa_token": "<|audio>",
25
+ "boi_token": "<|image>",
26
+ "eoa_token": "<audio|>",
27
+ "eoc_token": "<channel|>",
28
+ "eoi_token": "<image|>",
29
+ "eot_token": "<turn|>",
30
+ "escape_token": "<|\"|>",
31
+ "etc_token": "<tool_call|>",
32
+ "etd_token": "<tool|>",
33
+ "etr_token": "<tool_response|>",
34
+ "image_token": "<|image|>",
35
+ "soc_token": "<|channel>",
36
+ "sot_token": "<|turn>",
37
+ "stc_token": "<|tool_call>",
38
+ "std_token": "<|tool>",
39
+ "str_token": "<|tool_response>",
40
+ "think_token": "<|think|>"
41
+ },
42
+ "pad_token": "<pad>",
43
+ "padding_side": "left",
44
+ "processor_class": "Gemma4Processor",
45
+ "response_schema": {
46
+ "properties": {
47
+ "content": {
48
+ "type": "string"
49
+ },
50
+ "role": {
51
+ "const": "assistant"
52
+ },
53
+ "thinking": {
54
+ "type": "string"
55
+ },
56
+ "tool_calls": {
57
+ "items": {
58
+ "properties": {
59
+ "function": {
60
+ "properties": {
61
+ "arguments": {
62
+ "additionalProperties": {},
63
+ "type": "object",
64
+ "x-parser": "gemma4-tool-call"
65
+ },
66
+ "name": {
67
+ "type": "string"
68
+ }
69
+ },
70
+ "type": "object",
71
+ "x-regex": "call\\:(?P<name>\\w+)(?P<arguments>\\{.*\\})"
72
+ },
73
+ "type": {
74
+ "const": "function"
75
+ }
76
+ },
77
+ "type": "object"
78
+ },
79
+ "type": "array",
80
+ "x-regex-iterator": "<\\|tool_call>(.*?)<tool_call\\|>"
81
+ }
82
+ },
83
+ "type": "object",
84
+ "x-regex": "(\\<\\|channel\\>thought\\n(?P<thinking>.*?)\\<channel\\|\\>)?(?P<tool_calls>\\<\\|tool_call\\>.*\\<tool_call\\|\\>)?(?P<content>(?:(?!\\<turn\\|\\>)(?!\\<\\|tool_response\\>).)+)?(?:\\<turn\\|\\>|\\<\\|tool_response\\>)?"
85
+ },
86
+ "soc_token": "<|channel>",
87
+ "sot_token": "<|turn>",
88
+ "stc_token": "<|tool_call>",
89
+ "std_token": "<|tool>",
90
+ "str_token": "<|tool_response>",
91
+ "think_token": "<|think|>",
92
+ "tokenizer_class": "GemmaTokenizer",
93
+ "unk_token": "<unk>",
94
+ "chat_template": "{%- macro format_parameters(properties, required) -%}\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 key not in standard_keys -%}\n {%- set type_value = value['type'] -%}\n {%- set type_ns = namespace(primary=type_value, nullable=false) -%}\n {%- if type_value is sequence and type_value is not string -%}\n {%- set type_ns.primary = none -%}\n {%- for type_item in type_value -%}\n {%- if type_item | lower == 'null' -%}\n {%- set type_ns.nullable = true -%}\n {%- elif type_ns.primary is none -%}\n {%- set type_ns.primary = type_item -%}\n {%- endif -%}\n {%- endfor -%}\n {%- if type_ns.primary is none -%}\n {%- set type_ns.primary = 'null' -%}\n {%- endif -%}\n {%- endif -%}\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 type_ns.primary | 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 type_ns.primary | 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 {%- set item_type_ns = namespace(primary=none, nullable=false) -%}\n {%- for item_type in item_value -%}\n {%- if item_type | lower == 'null' -%}\n {%- set item_type_ns.nullable = true -%}\n {%- elif item_type_ns.primary is none -%}\n {%- set item_type_ns.primary = item_type -%}\n {%- endif -%}\n {%- endfor -%}\n {%- if item_type_ns.primary is none -%}\n {%- set item_type_ns.primary = 'null' -%}\n {%- endif -%}\n type:{{ format_argument(item_type_ns.primary | upper) }}\n {%- if item_type_ns.nullable -%},nullable:true{%- endif -%}\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'] or type_ns.nullable %}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n nullable:true\n {%- endif -%}\n {%- if type_ns.primary | 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([])) -}}\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:<|\"|>{{ type_ns.primary | 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 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 render_assistant_text(text, keep_reasoning=false) -%}\n {%- set total_blocks = (text.split('<channel|>') | length) - 1 -%}\n {%- set ns = namespace(result='', seen=0) -%}\n {%- for part in text.split('<channel|>') -%}\n {%- if '<|channel>' in part -%}\n {%- set pieces = part.split('<|channel>') -%}\n {%- set ns.result = ns.result + pieces[0] -%}\n {%- set ns.seen = ns.seen + 1 -%}\n {%- if keep_reasoning and ns.seen == total_blocks -%}\n {%- set ns.result = ns.result + '<|channel>' + pieces[1] + '<channel|>' -%}\n {%- endif -%}\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{%- set ns = namespace(prev_message_type=None) -%}\n{%- set loop_messages = messages -%}\n{%- if enable_thinking is not defined -%}\n {%- set enable_thinking = true -%}\n{%- endif -%}\n{{- bos_token -}}\n{#- Handle System/Tool Definitions Block -#}\n{%- if (enable_thinking is defined and enable_thinking) or tools or messages[0]['role'] in ['system', 'developer'] -%}\n {{- '<|turn>system\\n' -}}\n\n {#- Inject Thinking token at the very top of the FIRST system turn -#}\n {%- if enable_thinking is defined and enable_thinking -%}\n {{- '<|think|>\\n' -}}\n {%- set ns.prev_message_type = 'think' -%}\n {%- endif -%}\n\n {%- if messages[0]['role'] in ['system', 'developer'] -%}\n {%- set system_content = messages[0]['content'] -%}\n {%- if system_content is string -%}\n {{- system_content | trim -}}\n {%- elif system_content is sequence -%}\n {%- for item in system_content -%}\n {%- if item['type'] == 'text' -%}\n {{- item['text'] | trim -}}\n {%- endif -%}\n {%- endfor -%}\n {%- endif -%}\n {%- set loop_messages = messages[1:] -%}\n {%- endif -%}\n\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\n {{- '<turn|>\\n' -}}\n{%- endif %}\n\n{#- Pre-scan: find last user and last tagged reasoning block. -#}\n{%- set ns_turn = namespace(last_user_idx=-1, last_reasoning_idx=-1, reasoning_blocks=0) -%}\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 {%- if loop_messages[i]['role'] == 'assistant' -%}\n {%- set msg_content = loop_messages[i]['content'] -%}\n {%- if msg_content is string -%}\n {%- set block_count = (msg_content.split('<channel|>') | length) - 1 -%}\n {%- if block_count > 0 and '<|channel>' in msg_content -%}\n {%- set ns_turn.reasoning_blocks = ns_turn.reasoning_blocks + block_count -%}\n {%- set ns_turn.last_reasoning_idx = i -%}\n {%- endif -%}\n {%- elif msg_content is sequence -%}\n {%- for item in msg_content -%}\n {%- if item['type'] == 'text' -%}\n {%- set item_text = item['text'] | default('') -%}\n {%- set block_count = (item_text.split('<channel|>') | length) - 1 -%}\n {%- if block_count > 0 and '<|channel>' in item_text -%}\n {%- set ns_turn.reasoning_blocks = ns_turn.reasoning_blocks + block_count -%}\n {%- set ns_turn.last_reasoning_idx = i -%}\n {%- endif -%}\n {%- endif -%}\n {%- endfor -%}\n {%- endif -%}\n {%- endif -%}\n{%- endfor -%}\n{%- if keep_last_reasoning is not defined -%}\n {%- set keep_last_reasoning = false -%}\n{%- endif -%}\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 message_idx = loop.index0 -%}\n {%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}\n {#- Detect continuation: suppress duplicate <|turn>model when previous non-tool message was also assistant -#}\n {%- set prev_nt = namespace(role=None, found=false) -%}\n {%- if loop.index0 > 0 -%}\n {%- for j in range(loop.index0 - 1, -1, -1) -%}\n {%- if not prev_nt.found -%}\n {%- if loop_messages[j]['role'] != 'tool' -%}\n {%- set prev_nt.role = loop_messages[j]['role'] -%}\n {%- set prev_nt.found = true -%}\n {%- endif -%}\n {%- endif -%}\n {%- endfor -%}\n {%- endif -%}\n {%- set continue_same_model_turn = (role == 'model' and prev_nt.role == 'assistant') -%}\n {%- if not continue_same_model_turn -%}\n {{- '<|turn>' + role + '\\n' }}\n {%- endif -%}\n\n {%- if message['tool_calls'] -%}\n {%- for tool_call in message['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 string -%}\n {{- function['arguments'] -}}\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['tool_responses'] -%}\n {{- format_tool_response_block(tool_response['name'] | default('unknown'), 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') | default('unknown')) -%}\n {%- for tc in message['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 {%- 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 {%- if message['content'] is string -%}\n {%- if role == 'model' -%}\n {{- render_assistant_text(message['content'], keep_last_reasoning and message_idx == ns_turn.last_reasoning_idx) -}}\n {%- else -%}\n {{- message['content'] | trim -}}\n {%- endif -%}\n {%- elif message['content'] is sequence -%}\n {%- for item in message['content'] -%}\n {%- if item['type'] == 'text' -%}\n {%- if role == 'model' -%}\n {{- render_assistant_text(item['text'], keep_last_reasoning and message_idx == ns_turn.last_reasoning_idx) -}}\n {%- else -%}\n {{- item['text'] | trim -}}\n {%- endif -%}\n {%- elif item['type'] == 'image' -%}\n {{- '<|image|>' -}}\n {%- set ns.prev_message_type = 'image' -%}\n {%- elif item['type'] == 'audio' -%}\n {{- '<|audio|>' -}}\n {%- set ns.prev_message_type = 'audio' -%}\n {%- elif item['type'] == 'video' -%}\n {{- '<|video|>' -}}\n {%- set ns.prev_message_type = 'video' -%}\n {%- endif -%}\n {%- endfor -%}\n {%- endif -%}\n\n {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}\n {{- '<|tool_response>' -}}\n {%- elif not (ns_tr_out.flag and not message.get('content')) -%}\n {{- '<turn|>\\n' -}}\n {%- endif -%}\n {%- endif -%}\n{%- endfor -%}\n\n{%- if add_generation_prompt -%}\n {%- if ns.prev_message_type != 'tool_call' -%}\n {{- '<|turn>model\\n' -}}\n {%- endif -%}\n{%- endif -%}\n"
95
+ }