bebechien commited on
Commit
6a176b7
·
verified ·
1 Parent(s): 4739f84

Training in progress, epoch 1

Browse files
README.md CHANGED
@@ -20,7 +20,7 @@ It has been trained using [TRL](https://github.com/huggingface/trl).
20
  from transformers import pipeline
21
 
22
  question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
23
- generator = pipeline("text-generation", model="bebechien/gemma-text-to-sql", device="cuda")
24
  output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]
25
  print(output["generated_text"])
26
  ```
@@ -35,11 +35,11 @@ This model was trained with SFT.
35
 
36
  ### Framework versions
37
 
38
- - TRL: 1.6.0
39
- - Transformers: 5.12.0
40
- - Pytorch: 2.11.0+cu128
41
- - Datasets: 5.0.0
42
- - Tokenizers: 0.22.2
43
 
44
  ## Citations
45
 
 
20
  from transformers import pipeline
21
 
22
  question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
23
+ generator = pipeline("text-generation", model="bebechien/gemma-text-to-sql", device_map="auto")
24
  output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]
25
  print(output["generated_text"])
26
  ```
 
35
 
36
  ### Framework versions
37
 
38
+ - TRL: 1.16.0
39
+ - Transformers: 5.19.0
40
+ - Pytorch: 2.11.0+cu130
41
+ - Datasets: 4.8.5
42
+ - Tokenizers: 0.23.3
43
 
44
  ## Citations
45
 
adapter_config.json CHANGED
@@ -12,6 +12,7 @@
12
  "fan_in_fan_out": false,
13
  "inference_mode": true,
14
  "init_lora_weights": true,
 
15
  "layer_replication": null,
16
  "layers_pattern": null,
17
  "layers_to_transform": null,
@@ -26,8 +27,9 @@
26
  "embed_tokens",
27
  "model.language_model.embed_tokens"
28
  ],
 
29
  "peft_type": "LORA",
30
- "peft_version": "0.19.1",
31
  "qalora_group_size": 16,
32
  "r": 16,
33
  "rank_pattern": {},
@@ -39,5 +41,6 @@
39
  "use_bdlora": null,
40
  "use_dora": false,
41
  "use_qalora": false,
42
- "use_rslora": false
 
43
  }
 
12
  "fan_in_fan_out": false,
13
  "inference_mode": true,
14
  "init_lora_weights": true,
15
+ "kasa_config": null,
16
  "layer_replication": null,
17
  "layers_pattern": null,
18
  "layers_to_transform": null,
 
27
  "embed_tokens",
28
  "model.language_model.embed_tokens"
29
  ],
30
+ "monteclora_config": null,
31
  "peft_type": "LORA",
32
+ "peft_version": "0.21.2",
33
  "qalora_group_size": 16,
34
  "r": 16,
35
  "rank_pattern": {},
 
41
  "use_bdlora": null,
42
  "use_dora": false,
43
  "use_qalora": false,
44
+ "use_rslora": false,
45
+ "velora_config": null
46
  }
adapter_model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:0676167ae9a41f2c7b428ded3ab5ad653edaa85bfc970b0040766a445fd95b71
3
  size 1615986032
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f8c029502b8b8ffc1a5049d57a77f7bfd5b65658492a0d1e18023ca4f35a9fb8
3
  size 1615986032
chat_template.jinja CHANGED
@@ -1,3 +1,9 @@
 
 
 
 
 
 
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,7 +122,9 @@
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,18 +180,21 @@
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,31 +228,21 @@
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,8 +252,13 @@
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,8 +268,8 @@
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,8 +283,8 @@
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,9 +302,9 @@
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,29 +320,26 @@
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,16 +348,39 @@
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
  {%- endif -%}
360
- {%- endif -%}
 
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
  }
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
  {{- '<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
  {%- 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
  {%- endif -%}
236
 
237
  {#- Render reasoning/reasoning_content as thinking channel -#}
238
  {%- set thinking_text = message.get('reasoning') or message.get('reasoning_content') -%}
239
+ {%- set thinking_gate = (loop.index0 > ns_turn.last_user_idx) or (preserve_thinking and message.get('tool_calls')) -%}
240
+ {%- if thinking_text and thinking_gate -%}
241
  {{- '<|channel>thought\n' + thinking_text + '\n<channel|>' -}}
242
  {%- endif -%}
243
 
244
+ {%- if message.get('tool_calls') -%}
245
+ {%- for tool_call in message.get('tool_calls') -%}
246
  {%- set function = tool_call['function'] -%}
247
  {{- '<|tool_call>call:' + function['name'] + '{' -}}
248
  {%- if function['arguments'] is mapping -%}
 
252
  {%- set ns_args.found_first = true -%}
253
  {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
254
  {%- endfor -%}
255
+ {%- elif function['arguments'] is none -%}
256
+ {%- else -%}
257
+ {{- raise_exception(
258
+ "chat_template: tool_calls[].function.arguments must be a "
259
+ "JSON object (mapping), not a string. Deserialize arguments "
260
+ "before passing to the template."
261
+ ) -}}
262
  {%- endif -%}
263
  {{- '}<tool_call|>' -}}
264
  {%- endfor -%}
 
268
  {%- set ns_tr_out = namespace(flag=false) -%}
269
  {%- if message.get('tool_responses') -%}
270
  {#- Legacy: tool_responses embedded on the assistant message (Google/Gemma native) -#}
271
+ {%- for tool_response in message.get('tool_responses') -%}
272
+ {{- format_tool_response_block(tool_response['name'] | default('unknown', true), tool_response['response']) -}}
273
  {%- set ns_tr_out.flag = true -%}
274
  {%- set ns.prev_message_type = 'tool_response' -%}
275
  {%- endfor -%}
 
283
  {%- else -%}
284
  {%- set follow = loop_messages[k] -%}
285
  {#- Resolve tool_call_id to function name -#}
286
+ {%- set ns_tname = namespace(name=follow.get('name') or 'unknown') -%}
287
+ {%- for tc in message.get('tool_calls') -%}
288
  {%- if tc.get('id') == follow.get('tool_call_id') -%}
289
  {%- set ns_tname.name = tc['function']['name'] -%}
290
  {%- endif -%}
 
302
  {%- endfor -%}
303
  {{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
304
  {%- for part in tool_body -%}
305
+ {%- if part.get('type') in ['image', 'image_url'] -%}
306
  {{- '<|image|>' -}}
307
+ {%- elif part.get('type') in ['audio', 'input_audio'] -%}
308
  {{- '<|audio|>' -}}
309
  {%- elif part.get('type') == 'video' -%}
310
  {{- '<|video|>' -}}
 
320
  {%- endif -%}
321
 
322
  {%- set captured_content -%}
323
+ {%- if message.get('content') is string -%}
324
  {%- if role == 'model' -%}
325
  {{- strip_thinking(message['content']) -}}
326
  {%- else -%}
327
  {{- message['content'] | trim -}}
328
  {%- endif -%}
329
+ {%- elif message.get('content') is sequence -%}
330
  {%- for item in message['content'] -%}
331
+ {%- if item.get('type') == 'text' -%}
332
  {%- if role == 'model' -%}
333
  {{- strip_thinking(item['text']) -}}
334
  {%- else -%}
335
  {{- item['text'] | trim -}}
336
  {%- endif -%}
337
+ {%- elif item.get('type') in ['image', 'image_url'] -%}
338
  {{- '<|image|>' -}}
339
+ {%- elif item.get('type') in ['audio', 'input_audio'] -%}
 
340
  {{- '<|audio|>' -}}
341
+ {%- elif item.get('type') == 'video' -%}
 
342
  {{- '<|video|>' -}}
 
343
  {%- endif -%}
344
  {%- endfor -%}
345
  {%- endif -%}
 
348
  {{- captured_content -}}
349
  {%- set has_content = captured_content | trim | length > 0 -%}
350
 
351
+ {#- Forward-scan: find next non-tool message role for continuation detection -#}
352
+ {%- set next_nt = namespace(role=None, found=false) -%}
353
+ {%- for j in range(loop.index0 + 1, loop_messages | length) -%}
354
+ {%- if not next_nt.found -%}
355
+ {%- if loop_messages[j]['role'] != 'tool' -%}
356
+ {%- set next_nt.role = loop_messages[j]['role'] -%}
357
+ {%- set next_nt.found = true -%}
358
+ {%- endif -%}
359
+ {%- endif -%}
360
+ {%- endfor -%}
361
+
362
+ {%- set continues_into_next = (
363
+ role == 'model'
364
+ and next_nt.role == 'assistant'
365
+ and (not message.get('tool_calls') or ns_tr_out.flag)
366
+ ) -%}
367
+
368
  {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
369
  {{- '<|tool_response>' -}}
370
+ {%- elif continues_into_next -%}
371
+ {%- elif not (ns_tr_out.flag and not has_content and not next_nt.found) -%}
372
  {{- '<turn|>\n' -}}
373
  {%- endif -%}
374
+
375
+ {#- Track previous non-tool role for next iteration (avoids O(n) backward scan) -#}
376
+ {%- set ns.prev_non_tool_role = message['role'] -%}
377
  {%- endif -%}
378
  {%- endfor -%}
379
 
380
  {%- if add_generation_prompt -%}
381
  {%- if ns.prev_message_type != 'tool_response' and ns.prev_message_type != 'tool_call' -%}
382
  {{- '<|turn>model\n' -}}
383
+ {%- elif ns.prev_message_type == 'tool_response' and enable_thinking -%}
384
+ {{- '<|channel>thought\n' -}}
385
  {%- endif -%}
386
+ {%- endif -%}
runs/Oct17_05-34-00_f94006235310/events.out.tfevents.1792215240.f94006235310.177826.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:885f6a75763f9cbb79b2da9f5bc4e5a8e0957eeeabf7474298c976363d5c276c
3
+ size 48586
tokenizer.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:a2619fe11b50dbed06ac443c51d757b354d0b62d64baa514404d4e84e6713519
3
- size 32169780
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cc8d3a0ce36466ccc1278bf987df5f71db1719b9ca6b4118264f45cb627bfe0f
3
+ size 32169626
tokenizer_config.json CHANGED
@@ -85,6 +85,52 @@
85
  "type": "object",
86
  "x-regex": "(\\<\\|channel\\>thought\\n(?P<thinking>.*?)\\<channel\\|\\>)?(?P<tool_calls>\\<\\|tool_call\\>.*\\<tool_call\\|\\>)?(?P<content>(?:(?!\\<turn\\|\\>)(?!\\<\\|tool_response\\>).)+)?(?:\\<turn\\|\\>|\\<\\|tool_response\\>)?"
87
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  "soc_token": "<|channel>",
89
  "sot_token": "<|turn>",
90
  "stc_token": "<|tool_call>",
 
85
  "type": "object",
86
  "x-regex": "(\\<\\|channel\\>thought\\n(?P<thinking>.*?)\\<channel\\|\\>)?(?P<tool_calls>\\<\\|tool_call\\>.*\\<tool_call\\|\\>)?(?P<content>(?:(?!\\<turn\\|\\>)(?!\\<\\|tool_response\\>).)+)?(?:\\<turn\\|\\>|\\<\\|tool_response\\>)?"
87
  },
88
+ "response_template": {
89
+ "defaults": {
90
+ "role": "assistant"
91
+ },
92
+ "fields": {
93
+ "content": {
94
+ "close": [
95
+ "<turn|>",
96
+ "<|tool_response>",
97
+ "<eos>"
98
+ ],
99
+ "content": "text"
100
+ },
101
+ "thinking": {
102
+ "close": "<channel|>",
103
+ "content": "text",
104
+ "open": "<|channel>thought\n"
105
+ },
106
+ "tool_calls": {
107
+ "close": "<tool_call|>",
108
+ "content": "json",
109
+ "content_args": {
110
+ "string_delims": [
111
+ [
112
+ "<|\"|>",
113
+ "<|\"|>"
114
+ ]
115
+ ],
116
+ "unquoted_keys": true
117
+ },
118
+ "open_pattern": "<\\|tool_call>call:(?P<name>\\w+)",
119
+ "repeats": true,
120
+ "transform": {
121
+ "function": {
122
+ "arguments": "{content}",
123
+ "name": "{name}"
124
+ },
125
+ "type": "function"
126
+ }
127
+ }
128
+ },
129
+ "start_anchor": [
130
+ "<|turn>model\n",
131
+ "<tool_response|>"
132
+ ]
133
+ },
134
  "soc_token": "<|channel>",
135
  "sot_token": "<|turn>",
136
  "stc_token": "<|tool_call>",
training_args.bin CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f0913222bfaad24eda524d341943565b46e6fd10a7b6f5fa4ff28c941f0f4a42
3
- size 5649
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b330535769adcaccf406b1aea64b50c2a1c7bcc64f60ed0d33ce0b8ece90c281
3
+ size 5777