cagataydev commited on
Commit
9426377
·
verified ·
1 Parent(s): 7c2a09a

Upload folder using huggingface_hub

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,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: google/gemma-4-E2B-it-qat-mobile-transformers
3
+ library_name: peft
4
+ license: gemma
5
+ pipeline_tag: text-generation
6
+ language: [en]
7
+ tags:
8
+ - lora
9
+ - peft
10
+ - strands-agents
11
+ - code
12
+ - gemma-4
13
+ - domain-adaptation
14
+ ---
15
+
16
+ # strands-gemma4-e2b — Strands Agents expert (Gemma 4 E2B LoRA)
17
+
18
+ LoRA adapter that post-tunes **google/gemma-4-E2B-it-qat-mobile-transformers** on the
19
+ full **Strands Agents / Strands Robots** codebase + docs corpus, turning the mobile-class
20
+ Gemma 4 E2B into a Strands-Agents domain expert.
21
+
22
+ Sister models: [cagataydev/strands-qwen3-vl-2b](https://huggingface.co/cagataydev/strands-qwen3-vl-2b)
23
+ (same corpus, Qwen3-VL-2B backbone). Part of the self-learning-model research project
24
+ ([github.com/cagataycali/slm](https://github.com/cagataycali/slm)).
25
+
26
+ ## Results
27
+
28
+ | Metric | Before | After | Δ |
29
+ |---|---|---|---|
30
+ | Holdout NLL (strands corpus) | **2.689** | **1.260** | **−1.43 (−53%)** |
31
+ | Train loss (600 steps) | 3.07 | 0.96 | |
32
+
33
+ ## Training
34
+
35
+ - **Corpus**: 2,288 documents (~5M tokens) — strands-agents SDK source, strands-tools,
36
+ strands-robots, docs, examples, and Golden-200 Q&A pairs
37
+ - **Method**: QAT checkpoint dequantized to bf16, then LoRA on all language-model
38
+ attention + MLP projections (`q,k,v,o,gate,up,down_proj`), vision tower untouched
39
+ - **Config**: r=32, alpha=64, dropout=0.05, 600 steps, bs 2 × accum 4, lr 1e-4 cosine,
40
+ block 1024, AdamW, gradient checkpointing
41
+ - **Trainable**: 48.3M params (adapter only; base frozen)
42
+ - **Hardware**: 1× NVIDIA L40S, ~2,570 tok/s
43
+
44
+ ## Usage
45
+
46
+ ```python
47
+ import torch
48
+ from transformers import AutoModelForCausalLM, AutoTokenizer
49
+ from peft import PeftModel
50
+
51
+ BASE = "google/gemma-4-E2B-it-qat-mobile-transformers"
52
+ tok = AutoTokenizer.from_pretrained(BASE)
53
+ model = AutoModelForCausalLM.from_pretrained(BASE, dtype=torch.bfloat16, device_map="auto")
54
+ model = PeftModel.from_pretrained(model, "cagataydev/strands-gemma4-e2b")
55
+
56
+ msgs = [{"role": "user", "content": "How do I create a custom tool in Strands Agents?"}]
57
+ ids = tok.apply_chat_template(msgs, add_generation_prompt=True, return_tensors="pt").to(model.device)
58
+ out = model.generate(ids, max_new_tokens=256)
59
+ print(tok.decode(out[0, ids.shape[1]:], skip_special_tokens=True))
60
+ ```
61
+
62
+ > Note: the base is a QAT (quantization-aware-training) checkpoint. Training was done on
63
+ > the dequantized bf16 weights; for training-compatible loading, dequantize QAT wrappers
64
+ > or load in bf16 as above.
65
+
66
+ ## Intended use & limitations
67
+
68
+ - Domain expert for the Strands Agents ecosystem (SDK APIs, tools, patterns, robots).
69
+ - Inherits Gemma 4 license/usage terms. Not evaluated for general-purpose safety beyond base.
70
+ - Trained on a code corpus snapshot (July 2026); APIs may drift.
71
+
72
+ ## Reproducibility
73
+
74
+ Training script: `strands_tune/train_lora_any.py` in the research repo
75
+ (`--dequant-qat --targets attn_mlp --steps 600 --bs 2 --accum 4 --lr 1e-4 --r 32`).
76
+ Full step log in `train_log.json` in this repo.
adapter_config.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": null,
6
+ "base_model_name_or_path": "google/gemma-4-E2B-it-qat-mobile-transformers",
7
+ "bias": "none",
8
+ "corda_config": null,
9
+ "ensure_weight_tying": false,
10
+ "eva_config": null,
11
+ "exclude_modules": null,
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,
18
+ "loftq_config": {},
19
+ "lora_alpha": 64,
20
+ "lora_bias": false,
21
+ "lora_dropout": 0.05,
22
+ "megatron_config": null,
23
+ "megatron_core": "megatron.core",
24
+ "modules_to_save": null,
25
+ "peft_type": "LORA",
26
+ "peft_version": "0.18.1",
27
+ "qalora_group_size": 16,
28
+ "r": 32,
29
+ "rank_pattern": {},
30
+ "revision": null,
31
+ "target_modules": ".*language_model.*(q_proj|k_proj|v_proj|o_proj|gate_proj|up_proj|down_proj)$",
32
+ "target_parameters": null,
33
+ "task_type": "CAUSAL_LM",
34
+ "trainable_token_indices": null,
35
+ "use_dora": false,
36
+ "use_qalora": false,
37
+ "use_rslora": false
38
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c66496a2c0f91df635a14f703cf25ceae5e58e3392e2b1a2f1b2b03b46ed5b1c
3
+ size 193326648
chat_template.jinja ADDED
@@ -0,0 +1,360 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 string -%}
120
+ {{- '<|"|>' + argument + '<|"|>' -}}
121
+ {%- elif argument is boolean -%}
122
+ {{- 'true' if argument else 'false' -}}
123
+ {%- elif argument is mapping -%}
124
+ {{- '{' -}}
125
+ {%- set ns = namespace(found_first=false) -%}
126
+ {%- for key, value in argument | dictsort -%}
127
+ {%- if ns.found_first %},{% endif -%}
128
+ {%- set ns.found_first = true -%}
129
+ {%- if escape_keys -%}
130
+ {{- '<|"|>' + key + '<|"|>' -}}
131
+ {%- else -%}
132
+ {{- key -}}
133
+ {%- endif -%}
134
+ :{{- format_argument(value, escape_keys=escape_keys) -}}
135
+ {%- endfor -%}
136
+ {{- '}' -}}
137
+ {%- elif argument is sequence -%}
138
+ {{- '[' -}}
139
+ {%- for item in argument -%}
140
+ {{- format_argument(item, escape_keys=escape_keys) -}}
141
+ {%- if not loop.last %},{% endif -%}
142
+ {%- endfor -%}
143
+ {{- ']' -}}
144
+ {%- else -%}
145
+ {{- argument -}}
146
+ {%- endif -%}
147
+ {%- endmacro -%}
148
+ {%- macro strip_thinking(text) -%}
149
+ {%- set ns = namespace(result='') -%}
150
+ {%- for part in text.split('<channel|>') -%}
151
+ {%- if '<|channel>' in part -%}
152
+ {%- set ns.result = ns.result + part.split('<|channel>')[0] -%}
153
+ {%- else -%}
154
+ {%- set ns.result = ns.result + part -%}
155
+ {%- endif -%}
156
+ {%- endfor -%}
157
+ {{- ns.result | trim -}}
158
+ {%- endmacro -%}
159
+
160
+ {%- macro format_tool_response_block(tool_name, response) -%}
161
+ {{- '<|tool_response>' -}}
162
+ {%- if response is mapping -%}
163
+ {{- 'response:' + tool_name + '{' -}}
164
+ {%- for key, value in response | dictsort -%}
165
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
166
+ {%- if not loop.last %},{% endif -%}
167
+ {%- endfor -%}
168
+ {{- '}' -}}
169
+ {%- else -%}
170
+ {{- 'response:' + tool_name + '{value:' + format_argument(response, escape_keys=False) + '}' -}}
171
+ {%- endif -%}
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 -%}
190
+ {%- for item in messages[0]['content'] -%}
191
+ {{- item['text'] | trim + ' '-}}
192
+ {%- endfor -%}
193
+ {%- endif -%}
194
+ {%- set loop_messages = messages[1:] -%}
195
+ {%- endif -%}
196
+ {%- if tools -%}
197
+ {%- for tool in tools %}
198
+ {{- '<|tool>' -}}
199
+ {{- format_function_declaration(tool) | trim -}}
200
+ {{- '<tool|>' -}}
201
+ {%- endfor %}
202
+ {%- set ns.prev_message_type = 'tool' -%}
203
+ {%- endif -%}
204
+ {{- '<turn|>\n' -}}
205
+ {%- endif %}
206
+
207
+ {#- Pre-scan: find last user message index for reasoning guard -#}
208
+ {%- set ns_turn = namespace(last_user_idx=-1) -%}
209
+ {%- for i in range(loop_messages | length) -%}
210
+ {%- if loop_messages[i]['role'] == 'user' -%}
211
+ {%- set ns_turn.last_user_idx = i -%}
212
+ {%- endif -%}
213
+ {%- endfor -%}
214
+
215
+ {#- Loop through messages -#}
216
+ {%- for message in loop_messages -%}
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 -%}
248
+ {%- set ns_args = namespace(found_first=false) -%}
249
+ {%- for key, value in function['arguments'] | dictsort -%}
250
+ {%- if ns_args.found_first %},{% endif -%}
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 -%}
259
+ {%- set ns.prev_message_type = 'tool_call' -%}
260
+ {%- endif -%}
261
+
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 -%}
270
+ {%- elif message.get('tool_calls') -%}
271
+ {#- OpenAI Chat Completions: forward-scan consecutive role:tool messages -#}
272
+ {%- set ns_tool_scan = namespace(stopped=false) -%}
273
+ {%- for k in range(loop.index0 + 1, loop_messages | length) -%}
274
+ {%- if ns_tool_scan.stopped -%}
275
+ {%- elif loop_messages[k]['role'] != 'tool' -%}
276
+ {%- set ns_tool_scan.stopped = true -%}
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 -%}
285
+ {%- endfor -%}
286
+ {#- Handle content as string or content-parts array -#}
287
+ {%- set tool_body = follow.get('content') -%}
288
+ {%- if tool_body is string -%}
289
+ {{- format_tool_response_block(ns_tname.name, tool_body) -}}
290
+ {%- elif tool_body is sequence and tool_body is not string -%}
291
+ {%- set ns_txt = namespace(s='') -%}
292
+ {%- for part in tool_body -%}
293
+ {%- if part.get('type') == 'text' -%}
294
+ {%- set ns_txt.s = ns_txt.s + (part.get('text') | default('')) -%}
295
+ {%- 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|>' -}}
305
+ {%- endif -%}
306
+ {%- endfor -%}
307
+ {%- else -%}
308
+ {{- format_tool_response_block(ns_tname.name, tool_body) -}}
309
+ {%- endif -%}
310
+ {%- set ns_tr_out.flag = true -%}
311
+ {%- set ns.prev_message_type = 'tool_response' -%}
312
+ {%- endif -%}
313
+ {%- endfor -%}
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 -%}
343
+ {%- endset -%}
344
+
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 -%}
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:55e53b7789842253453fe481c7b5c4ce98cd61654cb333bb39a78e9ed824871d
3
+ size 32169725
tokenizer_config.json ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "model_max_length": 1000000000000000019884624838656,
24
+ "model_specific_special_tokens": {
25
+ "audio_token": "<|audio|>",
26
+ "boa_token": "<|audio>",
27
+ "boi_token": "<|image>",
28
+ "eoa_token": "<audio|>",
29
+ "eoc_token": "<channel|>",
30
+ "eoi_token": "<image|>",
31
+ "eot_token": "<turn|>",
32
+ "escape_token": "<|\"|>",
33
+ "etc_token": "<tool_call|>",
34
+ "etd_token": "<tool|>",
35
+ "etr_token": "<tool_response|>",
36
+ "image_token": "<|image|>",
37
+ "soc_token": "<|channel>",
38
+ "sot_token": "<|turn>",
39
+ "stc_token": "<|tool_call>",
40
+ "std_token": "<|tool>",
41
+ "str_token": "<|tool_response>",
42
+ "think_token": "<|think|>"
43
+ },
44
+ "pad_token": "<pad>",
45
+ "padding_side": "left",
46
+ "processor_class": "Gemma4Processor",
47
+ "response_schema": {
48
+ "properties": {
49
+ "content": {
50
+ "type": "string"
51
+ },
52
+ "role": {
53
+ "const": "assistant"
54
+ },
55
+ "thinking": {
56
+ "type": "string"
57
+ },
58
+ "tool_calls": {
59
+ "items": {
60
+ "properties": {
61
+ "function": {
62
+ "properties": {
63
+ "arguments": {
64
+ "additionalProperties": {},
65
+ "type": "object",
66
+ "x-parser": "gemma4-tool-call"
67
+ },
68
+ "name": {
69
+ "type": "string"
70
+ }
71
+ },
72
+ "type": "object",
73
+ "x-regex": "call\\:(?P<name>\\w+)(?P<arguments>\\{.*\\})"
74
+ },
75
+ "type": {
76
+ "const": "function"
77
+ }
78
+ },
79
+ "type": "object"
80
+ },
81
+ "type": "array",
82
+ "x-regex-iterator": "<\\|tool_call>(.*?)<tool_call\\|>"
83
+ }
84
+ },
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>",
91
+ "std_token": "<|tool>",
92
+ "str_token": "<|tool_response>",
93
+ "think_token": "<|think|>",
94
+ "tokenizer_class": "GemmaTokenizer",
95
+ "unk_token": "<unk>"
96
+ }
train_log.json ADDED
@@ -0,0 +1,387 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model": "google/gemma-4-E2B-it-qat-mobile-transformers",
3
+ "args": {
4
+ "model": "google/gemma-4-E2B-it-qat-mobile-transformers",
5
+ "steps": 600,
6
+ "bs": 2,
7
+ "accum": 4,
8
+ "lr": 0.0001,
9
+ "r": 32,
10
+ "block": 1024,
11
+ "load_4bit": false,
12
+ "dequant_qat": true,
13
+ "targets": "attn_mlp",
14
+ "corpus": "/home/ubuntu/self-learning-model/strands_tune/corpus.jsonl",
15
+ "out": "artifacts/strands_gemma4_e2b_lora"
16
+ },
17
+ "nll_before": 2.68935369849205,
18
+ "nll_after": 1.2602788805961609,
19
+ "log": [
20
+ {
21
+ "step": 1,
22
+ "loss": 3.0693,
23
+ "lr": 9.999931461237134e-05,
24
+ "tok_s": 2557
25
+ },
26
+ {
27
+ "step": 10,
28
+ "loss": 1.7782,
29
+ "lr": 9.993147673772868e-05,
30
+ "tok_s": 2594
31
+ },
32
+ {
33
+ "step": 20,
34
+ "loss": 1.5848,
35
+ "lr": 9.972609476841367e-05,
36
+ "tok_s": 2583
37
+ },
38
+ {
39
+ "step": 30,
40
+ "loss": 1.7978,
41
+ "lr": 9.938441702975687e-05,
42
+ "tok_s": 2579
43
+ },
44
+ {
45
+ "step": 40,
46
+ "loss": 1.6216,
47
+ "lr": 9.890738003669028e-05,
48
+ "tok_s": 2582
49
+ },
50
+ {
51
+ "step": 50,
52
+ "loss": 1.4679,
53
+ "lr": 9.829629131445343e-05,
54
+ "tok_s": 2581
55
+ },
56
+ {
57
+ "step": 60,
58
+ "loss": 1.6909,
59
+ "lr": 9.755282581475769e-05,
60
+ "tok_s": 2578
61
+ },
62
+ {
63
+ "step": 70,
64
+ "loss": 1.0998,
65
+ "lr": 9.667902132486009e-05,
66
+ "tok_s": 2580
67
+ },
68
+ {
69
+ "step": 80,
70
+ "loss": 1.4509,
71
+ "lr": 9.567727288213006e-05,
72
+ "tok_s": 2579
73
+ },
74
+ {
75
+ "step": 90,
76
+ "loss": 1.4452,
77
+ "lr": 9.455032620941841e-05,
78
+ "tok_s": 2577
79
+ },
80
+ {
81
+ "step": 100,
82
+ "loss": 1.5662,
83
+ "lr": 9.330127018922195e-05,
84
+ "tok_s": 2579
85
+ },
86
+ {
87
+ "step": 110,
88
+ "loss": 1.3704,
89
+ "lr": 9.193352839727123e-05,
90
+ "tok_s": 2573
91
+ },
92
+ {
93
+ "step": 120,
94
+ "loss": 1.0406,
95
+ "lr": 9.045084971874741e-05,
96
+ "tok_s": 2573
97
+ },
98
+ {
99
+ "step": 130,
100
+ "loss": 1.3993,
101
+ "lr": 8.88572980728486e-05,
102
+ "tok_s": 2575
103
+ },
104
+ {
105
+ "step": 140,
106
+ "loss": 1.3269,
107
+ "lr": 8.715724127386976e-05,
108
+ "tok_s": 2574
109
+ },
110
+ {
111
+ "step": 150,
112
+ "loss": 1.462,
113
+ "lr": 8.535533905932743e-05,
114
+ "tok_s": 2573
115
+ },
116
+ {
117
+ "step": 160,
118
+ "loss": 1.2279,
119
+ "lr": 8.345653031794296e-05,
120
+ "tok_s": 2575
121
+ },
122
+ {
123
+ "step": 170,
124
+ "loss": 1.2806,
125
+ "lr": 8.146601955249193e-05,
126
+ "tok_s": 2575
127
+ },
128
+ {
129
+ "step": 180,
130
+ "loss": 1.1756,
131
+ "lr": 7.938926261462371e-05,
132
+ "tok_s": 2574
133
+ },
134
+ {
135
+ "step": 190,
136
+ "loss": 0.918,
137
+ "lr": 7.723195175075142e-05,
138
+ "tok_s": 2576
139
+ },
140
+ {
141
+ "step": 200,
142
+ "loss": 1.3074,
143
+ "lr": 7.500000000000009e-05,
144
+ "tok_s": 2575
145
+ },
146
+ {
147
+ "step": 210,
148
+ "loss": 1.3411,
149
+ "lr": 7.269952498697741e-05,
150
+ "tok_s": 2569
151
+ },
152
+ {
153
+ "step": 220,
154
+ "loss": 1.4813,
155
+ "lr": 7.033683215379006e-05,
156
+ "tok_s": 2570
157
+ },
158
+ {
159
+ "step": 230,
160
+ "loss": 1.3284,
161
+ "lr": 6.791839747726506e-05,
162
+ "tok_s": 2570
163
+ },
164
+ {
165
+ "step": 240,
166
+ "loss": 1.6288,
167
+ "lr": 6.545084971874744e-05,
168
+ "tok_s": 2570
169
+ },
170
+ {
171
+ "step": 250,
172
+ "loss": 1.7878,
173
+ "lr": 6.294095225512611e-05,
174
+ "tok_s": 2571
175
+ },
176
+ {
177
+ "step": 260,
178
+ "loss": 1.6825,
179
+ "lr": 6.039558454088805e-05,
180
+ "tok_s": 2571
181
+ },
182
+ {
183
+ "step": 270,
184
+ "loss": 1.2099,
185
+ "lr": 5.7821723252011626e-05,
186
+ "tok_s": 2570
187
+ },
188
+ {
189
+ "step": 280,
190
+ "loss": 1.3091,
191
+ "lr": 5.522642316338277e-05,
192
+ "tok_s": 2571
193
+ },
194
+ {
195
+ "step": 290,
196
+ "loss": 1.4771,
197
+ "lr": 5.261679781214727e-05,
198
+ "tok_s": 2571
199
+ },
200
+ {
201
+ "step": 300,
202
+ "loss": 1.0913,
203
+ "lr": 5.000000000000007e-05,
204
+ "tok_s": 2571
205
+ },
206
+ {
207
+ "step": 310,
208
+ "loss": 1.5202,
209
+ "lr": 4.7383202187852876e-05,
210
+ "tok_s": 2568
211
+ },
212
+ {
213
+ "step": 320,
214
+ "loss": 1.2693,
215
+ "lr": 4.477357683661741e-05,
216
+ "tok_s": 2569
217
+ },
218
+ {
219
+ "step": 330,
220
+ "loss": 1.1337,
221
+ "lr": 4.217827674798853e-05,
222
+ "tok_s": 2569
223
+ },
224
+ {
225
+ "step": 340,
226
+ "loss": 1.3723,
227
+ "lr": 3.960441545911209e-05,
228
+ "tok_s": 2569
229
+ },
230
+ {
231
+ "step": 350,
232
+ "loss": 1.3359,
233
+ "lr": 3.7059047744874025e-05,
234
+ "tok_s": 2569
235
+ },
236
+ {
237
+ "step": 360,
238
+ "loss": 1.5499,
239
+ "lr": 3.454915028125268e-05,
240
+ "tok_s": 2569
241
+ },
242
+ {
243
+ "step": 370,
244
+ "loss": 1.1808,
245
+ "lr": 3.208160252273505e-05,
246
+ "tok_s": 2569
247
+ },
248
+ {
249
+ "step": 380,
250
+ "loss": 1.389,
251
+ "lr": 2.9663167846210028e-05,
252
+ "tok_s": 2570
253
+ },
254
+ {
255
+ "step": 390,
256
+ "loss": 1.1763,
257
+ "lr": 2.73004750130227e-05,
258
+ "tok_s": 2570
259
+ },
260
+ {
261
+ "step": 400,
262
+ "loss": 1.3025,
263
+ "lr": 2.500000000000002e-05,
264
+ "tok_s": 2570
265
+ },
266
+ {
267
+ "step": 410,
268
+ "loss": 1.1334,
269
+ "lr": 2.2768048249248692e-05,
270
+ "tok_s": 2568
271
+ },
272
+ {
273
+ "step": 420,
274
+ "loss": 1.2506,
275
+ "lr": 2.0610737385376383e-05,
276
+ "tok_s": 2568
277
+ },
278
+ {
279
+ "step": 430,
280
+ "loss": 1.0039,
281
+ "lr": 1.8533980447508165e-05,
282
+ "tok_s": 2568
283
+ },
284
+ {
285
+ "step": 440,
286
+ "loss": 1.6885,
287
+ "lr": 1.6543469682057116e-05,
288
+ "tok_s": 2568
289
+ },
290
+ {
291
+ "step": 450,
292
+ "loss": 1.3592,
293
+ "lr": 1.4644660940672653e-05,
294
+ "tok_s": 2568
295
+ },
296
+ {
297
+ "step": 460,
298
+ "loss": 1.3486,
299
+ "lr": 1.2842758726130306e-05,
300
+ "tok_s": 2568
301
+ },
302
+ {
303
+ "step": 470,
304
+ "loss": 1.279,
305
+ "lr": 1.1142701927151473e-05,
306
+ "tok_s": 2569
307
+ },
308
+ {
309
+ "step": 480,
310
+ "loss": 1.339,
311
+ "lr": 9.549150281252647e-06,
312
+ "tok_s": 2569
313
+ },
314
+ {
315
+ "step": 490,
316
+ "loss": 1.0581,
317
+ "lr": 8.066471602728818e-06,
318
+ "tok_s": 2569
319
+ },
320
+ {
321
+ "step": 500,
322
+ "loss": 1.3058,
323
+ "lr": 6.69872981077809e-06,
324
+ "tok_s": 2569
325
+ },
326
+ {
327
+ "step": 510,
328
+ "loss": 1.5708,
329
+ "lr": 5.449673790581622e-06,
330
+ "tok_s": 2567
331
+ },
332
+ {
333
+ "step": 520,
334
+ "loss": 1.2886,
335
+ "lr": 4.322727117869972e-06,
336
+ "tok_s": 2567
337
+ },
338
+ {
339
+ "step": 530,
340
+ "loss": 1.3237,
341
+ "lr": 3.3209786751399204e-06,
342
+ "tok_s": 2568
343
+ },
344
+ {
345
+ "step": 540,
346
+ "loss": 1.1265,
347
+ "lr": 2.4471741852423297e-06,
348
+ "tok_s": 2568
349
+ },
350
+ {
351
+ "step": 550,
352
+ "loss": 1.3335,
353
+ "lr": 1.7037086855465882e-06,
354
+ "tok_s": 2568
355
+ },
356
+ {
357
+ "step": 560,
358
+ "loss": 1.6331,
359
+ "lr": 1.0926199633097236e-06,
360
+ "tok_s": 2568
361
+ },
362
+ {
363
+ "step": 570,
364
+ "loss": 1.3864,
365
+ "lr": 6.155829702431183e-07,
366
+ "tok_s": 2568
367
+ },
368
+ {
369
+ "step": 580,
370
+ "loss": 1.1831,
371
+ "lr": 2.7390523158633617e-07,
372
+ "tok_s": 2568
373
+ },
374
+ {
375
+ "step": 590,
376
+ "loss": 0.9576,
377
+ "lr": 6.852326227130851e-08,
378
+ "tok_s": 2568
379
+ },
380
+ {
381
+ "step": 600,
382
+ "loss": 0.9617,
383
+ "lr": 0.0,
384
+ "tok_s": 2568
385
+ }
386
+ ]
387
+ }