Nithish2410 commited on
Commit
cec0a45
·
verified ·
1 Parent(s): 38463cc

Upload folder using huggingface_hub

Browse files
OPD_LF_HL/chat_template.jinja CHANGED
@@ -1,9 +1,3 @@
1
- {#
2
- Template: Google Gemma 4 Canonical Chat Template
3
- Author: Google Gemma Engineering Team
4
- Published: 2026-07-09
5
- Context: Fixed tool-calling loops, turn closures, and thinking content-ordering.
6
- #}
7
  {%- macro format_parameters(properties, required, filter_keys=false) -%}
8
  {%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%}
9
  {%- set ns = namespace(found_first=false) -%}
@@ -122,9 +116,7 @@
122
  }
123
  {%- endmacro -%}
124
  {%- macro format_argument(argument, escape_keys=True) -%}
125
- {%- if argument is none -%}
126
- {{- 'null' -}}
127
- {%- elif argument is string -%}
128
  {{- '<|"|>' + argument + '<|"|>' -}}
129
  {%- elif argument is boolean -%}
130
  {{- 'true' if argument else 'false' -}}
@@ -180,21 +172,18 @@
180
  {{- '<tool_response|>' -}}
181
  {%- endmacro -%}
182
 
183
- {#- ===== SETUP ===== -#}
184
- {%- set ns = namespace(prev_message_type=None, prev_non_tool_role=None) -%}
185
  {%- set loop_messages = messages -%}
186
- {%- set enable_thinking = enable_thinking | default(false) -%}
187
- {%- set preserve_thinking = preserve_thinking | default(false) -%}
188
  {{- bos_token -}}
189
  {#- Handle System/Tool Definitions Block -#}
190
- {%- if enable_thinking or tools or (messages and messages[0]['role'] in ['system', 'developer']) -%}
191
  {{- '<|turn>system\n' -}}
192
  {#- Inject Thinking token at the very top of the FIRST system turn -#}
193
- {%- if enable_thinking -%}
194
  {{- '<|think|>\n' -}}
195
  {%- set ns.prev_message_type = 'think' -%}
196
  {%- endif -%}
197
- {%- if messages and messages[0]['role'] in ['system', 'developer'] -%}
198
  {%- if messages[0]['content'] is string -%}
199
  {{- messages[0]['content'] | trim -}}
200
  {%- elif messages[0]['content'] is sequence -%}
@@ -228,22 +217,31 @@
228
  {%- if message['role'] != 'tool' -%}
229
  {%- set ns.prev_message_type = None -%}
230
  {%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}
231
- {#- Detect continuation using tracked state O(1) instead of O(n) backward scan -#}
232
- {%- set continue_same_model_turn = (role == 'model' and ns.prev_non_tool_role == 'assistant') -%}
 
 
 
 
 
 
 
 
 
 
 
233
  {%- if not continue_same_model_turn -%}
234
  {{- '<|turn>' + role + '\n' }}
235
-
236
  {%- endif -%}
237
 
238
  {#- Render reasoning/reasoning_content as thinking channel -#}
239
  {%- set thinking_text = message.get('reasoning') or message.get('reasoning_content') -%}
240
- {%- set thinking_gate = (loop.index0 > ns_turn.last_user_idx) or (preserve_thinking and message.get('tool_calls')) -%}
241
- {%- if thinking_text and thinking_gate -%}
242
  {{- '<|channel>thought\n' + thinking_text + '\n<channel|>' -}}
243
  {%- endif -%}
244
 
245
- {%- if message.get('tool_calls') -%}
246
- {%- for tool_call in message.get('tool_calls') -%}
247
  {%- set function = tool_call['function'] -%}
248
  {{- '<|tool_call>call:' + function['name'] + '{' -}}
249
  {%- if function['arguments'] is mapping -%}
@@ -253,13 +251,8 @@
253
  {%- set ns_args.found_first = true -%}
254
  {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
255
  {%- endfor -%}
256
- {%- elif function['arguments'] is none -%}
257
- {%- else -%}
258
- {{- raise_exception(
259
- "chat_template: tool_calls[].function.arguments must be a "
260
- "JSON object (mapping), not a string. Deserialize arguments "
261
- "before passing to the template."
262
- ) -}}
263
  {%- endif -%}
264
  {{- '}<tool_call|>' -}}
265
  {%- endfor -%}
@@ -269,8 +262,8 @@
269
  {%- set ns_tr_out = namespace(flag=false) -%}
270
  {%- if message.get('tool_responses') -%}
271
  {#- Legacy: tool_responses embedded on the assistant message (Google/Gemma native) -#}
272
- {%- for tool_response in message.get('tool_responses') -%}
273
- {{- format_tool_response_block(tool_response['name'] | default('unknown', true), tool_response['response']) -}}
274
  {%- set ns_tr_out.flag = true -%}
275
  {%- set ns.prev_message_type = 'tool_response' -%}
276
  {%- endfor -%}
@@ -284,8 +277,8 @@
284
  {%- else -%}
285
  {%- set follow = loop_messages[k] -%}
286
  {#- Resolve tool_call_id to function name -#}
287
- {%- set ns_tname = namespace(name=follow.get('name') or 'unknown') -%}
288
- {%- for tc in message.get('tool_calls') -%}
289
  {%- if tc.get('id') == follow.get('tool_call_id') -%}
290
  {%- set ns_tname.name = tc['function']['name'] -%}
291
  {%- endif -%}
@@ -303,9 +296,9 @@
303
  {%- endfor -%}
304
  {{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
305
  {%- for part in tool_body -%}
306
- {%- if part.get('type') in ['image', 'image_url'] -%}
307
  {{- '<|image|>' -}}
308
- {%- elif part.get('type') in ['audio', 'input_audio'] -%}
309
  {{- '<|audio|>' -}}
310
  {%- elif part.get('type') == 'video' -%}
311
  {{- '<|video|>' -}}
@@ -321,26 +314,29 @@
321
  {%- endif -%}
322
 
323
  {%- set captured_content -%}
324
- {%- if message.get('content') is string -%}
325
  {%- if role == 'model' -%}
326
  {{- strip_thinking(message['content']) -}}
327
  {%- else -%}
328
  {{- message['content'] | trim -}}
329
  {%- endif -%}
330
- {%- elif message.get('content') is sequence -%}
331
  {%- for item in message['content'] -%}
332
- {%- if item.get('type') == 'text' -%}
333
  {%- if role == 'model' -%}
334
  {{- strip_thinking(item['text']) -}}
335
  {%- else -%}
336
  {{- item['text'] | trim -}}
337
  {%- endif -%}
338
- {%- elif item.get('type') in ['image', 'image_url'] -%}
339
  {{- '<|image|>' -}}
340
- {%- elif item.get('type') in ['audio', 'input_audio'] -%}
 
341
  {{- '<|audio|>' -}}
342
- {%- elif item.get('type') == 'video' -%}
 
343
  {{- '<|video|>' -}}
 
344
  {%- endif -%}
345
  {%- endfor -%}
346
  {%- endif -%}
@@ -349,42 +345,19 @@
349
  {{- captured_content -}}
350
  {%- set has_content = captured_content | trim | length > 0 -%}
351
 
352
- {#- Forward-scan: find next non-tool message role for continuation detection -#}
353
- {%- set next_nt = namespace(role=None, found=false) -%}
354
- {%- for j in range(loop.index0 + 1, loop_messages | length) -%}
355
- {%- if not next_nt.found -%}
356
- {%- if loop_messages[j]['role'] != 'tool' -%}
357
- {%- set next_nt.role = loop_messages[j]['role'] -%}
358
- {%- set next_nt.found = true -%}
359
- {%- endif -%}
360
- {%- endif -%}
361
- {%- endfor -%}
362
-
363
- {%- set continues_into_next = (
364
- role == 'model'
365
- and next_nt.role == 'assistant'
366
- and (not message.get('tool_calls') or ns_tr_out.flag)
367
- ) -%}
368
-
369
  {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
370
  {{- '<|tool_response>' -}}
371
- {%- elif continues_into_next -%}
372
- {%- elif not (ns_tr_out.flag and not has_content and not next_nt.found) -%}
373
  {{- '<turn|>\n' -}}
374
  {%- endif -%}
375
-
376
- {#- Track previous non-tool role for next iteration (avoids O(n) backward scan) -#}
377
- {%- set ns.prev_non_tool_role = message['role'] -%}
378
  {%- endif -%}
379
  {%- endfor -%}
380
 
381
  {%- if add_generation_prompt -%}
382
  {%- if ns.prev_message_type != 'tool_response' and ns.prev_message_type != 'tool_call' -%}
383
  {{- '<|turn>model\n' -}}
384
- {%- if not enable_thinking -%}
385
  {{- '<|channel>thought\n<channel|>' -}}
386
  {%- endif -%}
387
- {%- elif ns.prev_message_type == 'tool_response' and enable_thinking -%}
388
- {{- '<|channel>thought\n' -}}
389
  {%- endif -%}
390
- {%- endif -%}
 
 
 
 
 
 
 
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) -%}
 
116
  }
117
  {%- endmacro -%}
118
  {%- macro format_argument(argument, escape_keys=True) -%}
119
+ {%- if argument is string -%}
 
 
120
  {{- '<|"|>' + argument + '<|"|>' -}}
121
  {%- elif argument is boolean -%}
122
  {{- 'true' if argument else 'false' -}}
 
172
  {{- '<tool_response|>' -}}
173
  {%- endmacro -%}
174
 
175
+ {%- set ns = namespace(prev_message_type=None) -%}
 
176
  {%- set loop_messages = messages -%}
 
 
177
  {{- bos_token -}}
178
  {#- Handle System/Tool Definitions Block -#}
179
+ {%- if (enable_thinking is defined and enable_thinking) or tools or messages[0]['role'] in ['system', 'developer'] -%}
180
  {{- '<|turn>system\n' -}}
181
  {#- Inject Thinking token at the very top of the FIRST system turn -#}
182
+ {%- if enable_thinking is defined and enable_thinking -%}
183
  {{- '<|think|>\n' -}}
184
  {%- set ns.prev_message_type = 'think' -%}
185
  {%- endif -%}
186
+ {%- if messages[0]['role'] in ['system', 'developer'] -%}
187
  {%- if messages[0]['content'] is string -%}
188
  {{- messages[0]['content'] | trim -}}
189
  {%- elif messages[0]['content'] is sequence -%}
 
217
  {%- if message['role'] != 'tool' -%}
218
  {%- set ns.prev_message_type = None -%}
219
  {%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}
220
+ {#- Detect continuation: suppress duplicate <|turn>model when previous non-tool message was also assistant -#}
221
+ {%- set prev_nt = namespace(role=None, found=false) -%}
222
+ {%- if loop.index0 > 0 -%}
223
+ {%- for j in range(loop.index0 - 1, -1, -1) -%}
224
+ {%- if not prev_nt.found -%}
225
+ {%- if loop_messages[j]['role'] != 'tool' -%}
226
+ {%- set prev_nt.role = loop_messages[j]['role'] -%}
227
+ {%- set prev_nt.found = true -%}
228
+ {%- endif -%}
229
+ {%- endif -%}
230
+ {%- endfor -%}
231
+ {%- endif -%}
232
+ {%- set continue_same_model_turn = (role == 'model' and prev_nt.role == 'assistant') -%}
233
  {%- if not continue_same_model_turn -%}
234
  {{- '<|turn>' + role + '\n' }}
 
235
  {%- endif -%}
236
 
237
  {#- Render reasoning/reasoning_content as thinking channel -#}
238
  {%- set thinking_text = message.get('reasoning') or message.get('reasoning_content') -%}
239
+ {%- if thinking_text and loop.index0 > ns_turn.last_user_idx and message.get('tool_calls') -%}
 
240
  {{- '<|channel>thought\n' + thinking_text + '\n<channel|>' -}}
241
  {%- endif -%}
242
 
243
+ {%- if message['tool_calls'] -%}
244
+ {%- for tool_call in message['tool_calls'] -%}
245
  {%- set function = tool_call['function'] -%}
246
  {{- '<|tool_call>call:' + function['name'] + '{' -}}
247
  {%- if function['arguments'] is mapping -%}
 
251
  {%- set ns_args.found_first = true -%}
252
  {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
253
  {%- endfor -%}
254
+ {%- elif function['arguments'] is string -%}
255
+ {{- function['arguments'] -}}
 
 
 
 
 
256
  {%- endif -%}
257
  {{- '}<tool_call|>' -}}
258
  {%- endfor -%}
 
262
  {%- set ns_tr_out = namespace(flag=false) -%}
263
  {%- if message.get('tool_responses') -%}
264
  {#- Legacy: tool_responses embedded on the assistant message (Google/Gemma native) -#}
265
+ {%- for tool_response in message['tool_responses'] -%}
266
+ {{- format_tool_response_block(tool_response['name'] | default('unknown'), tool_response['response']) -}}
267
  {%- set ns_tr_out.flag = true -%}
268
  {%- set ns.prev_message_type = 'tool_response' -%}
269
  {%- endfor -%}
 
277
  {%- else -%}
278
  {%- set follow = loop_messages[k] -%}
279
  {#- Resolve tool_call_id to function name -#}
280
+ {%- set ns_tname = namespace(name=follow.get('name') | default('unknown')) -%}
281
+ {%- for tc in message['tool_calls'] -%}
282
  {%- if tc.get('id') == follow.get('tool_call_id') -%}
283
  {%- set ns_tname.name = tc['function']['name'] -%}
284
  {%- endif -%}
 
296
  {%- endfor -%}
297
  {{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
298
  {%- for part in tool_body -%}
299
+ {%- if part.get('type') == 'image' -%}
300
  {{- '<|image|>' -}}
301
+ {%- elif part.get('type') == 'audio' -%}
302
  {{- '<|audio|>' -}}
303
  {%- elif part.get('type') == 'video' -%}
304
  {{- '<|video|>' -}}
 
314
  {%- endif -%}
315
 
316
  {%- set captured_content -%}
317
+ {%- if message['content'] is string -%}
318
  {%- if role == 'model' -%}
319
  {{- strip_thinking(message['content']) -}}
320
  {%- else -%}
321
  {{- message['content'] | trim -}}
322
  {%- endif -%}
323
+ {%- elif message['content'] is sequence -%}
324
  {%- for item in message['content'] -%}
325
+ {%- if item['type'] == 'text' -%}
326
  {%- if role == 'model' -%}
327
  {{- strip_thinking(item['text']) -}}
328
  {%- else -%}
329
  {{- item['text'] | trim -}}
330
  {%- endif -%}
331
+ {%- elif item['type'] == 'image' -%}
332
  {{- '<|image|>' -}}
333
+ {%- set ns.prev_message_type = 'image' -%}
334
+ {%- elif item['type'] == 'audio' -%}
335
  {{- '<|audio|>' -}}
336
+ {%- set ns.prev_message_type = 'audio' -%}
337
+ {%- elif item['type'] == 'video' -%}
338
  {{- '<|video|>' -}}
339
+ {%- set ns.prev_message_type = 'video' -%}
340
  {%- endif -%}
341
  {%- endfor -%}
342
  {%- endif -%}
 
345
  {{- captured_content -}}
346
  {%- set has_content = captured_content | trim | length > 0 -%}
347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
  {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
349
  {{- '<|tool_response>' -}}
350
+ {%- elif not (ns_tr_out.flag and not has_content) -%}
 
351
  {{- '<turn|>\n' -}}
352
  {%- endif -%}
 
 
 
353
  {%- endif -%}
354
  {%- endfor -%}
355
 
356
  {%- if add_generation_prompt -%}
357
  {%- if ns.prev_message_type != 'tool_response' and ns.prev_message_type != 'tool_call' -%}
358
  {{- '<|turn>model\n' -}}
359
+ {%- if not enable_thinking | default(false) -%}
360
  {{- '<|channel>thought\n<channel|>' -}}
361
  {%- endif -%}
 
 
362
  {%- endif -%}
363
+ {%- endif -%}
OPD_LF_HL/generation_config.json CHANGED
@@ -9,7 +9,7 @@
9
  ],
10
  "pad_token_id": 0,
11
  "temperature": 1.0,
12
- "top_k": 64,
13
- "top_p": 0.95,
14
  "transformers_version": "5.5.4"
15
  }
 
9
  ],
10
  "pad_token_id": 0,
11
  "temperature": 1.0,
12
+ "top_k": 0,
13
+ "top_p": 1.0,
14
  "transformers_version": "5.5.4"
15
  }
OPD_LF_HL/model-00001-of-00002.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e5b84900c1008496bcd2d2e42c22a92d9e28392795ddd267f6c84ffa432d3ded
3
  size 49323334202
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4136331d94346ee7979c9acbb59e0cd5fc4dd9e808398279bdc40252a3b74edf
3
  size 49323334202
OPD_LF_HL/model-00002-of-00002.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:c03c091b8617d0dd57c4de400c7ac548f9709683d2477425329852fc7addc4f2
3
  size 2288675130
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bc21722749f847b4b108d29da7005be5d1edbbcc7cb3a87451b60388e4cd3001
3
  size 2288675130
OPD_LF_HL/tokenizer_config.json CHANGED
@@ -17,7 +17,8 @@
17
  "<|video|>"
18
  ],
19
  "image_token": "<|image|>",
20
- "is_local": true,
 
21
  "mask_token": "<mask>",
22
  "model_max_length": 1000000000000000019884624838656,
23
  "model_specific_special_tokens": {
@@ -41,7 +42,7 @@
41
  "think_token": "<|think|>"
42
  },
43
  "pad_token": "<pad>",
44
- "padding_side": "left",
45
  "processor_class": "Gemma4Processor",
46
  "response_schema": {
47
  "properties": {
 
17
  "<|video|>"
18
  ],
19
  "image_token": "<|image|>",
20
+ "is_local": false,
21
+ "local_files_only": false,
22
  "mask_token": "<mask>",
23
  "model_max_length": 1000000000000000019884624838656,
24
  "model_specific_special_tokens": {
 
42
  "think_token": "<|think|>"
43
  },
44
  "pad_token": "<pad>",
45
+ "padding_side": "right",
46
  "processor_class": "Gemma4Processor",
47
  "response_schema": {
48
  "properties": {