sumitagrawal commited on
Commit
21cef2d
·
verified ·
1 Parent(s): 42ed458

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,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: apache-2.0
5
+ library_name: peft
6
+ base_model: unsloth/functiongemma-270m-it
7
+ tags:
8
+ - function-calling
9
+ - tool-use
10
+ - gemma3
11
+ - lora
12
+ - peft
13
+ datasets:
14
+ - Salesforce/xlam-function-calling-60k
15
+ - MadeAgents/xlam-irrelevance-7.5k
16
+ pipeline_tag: text-generation
17
+ ---
18
+
19
+ # sumitagrawal/functiongemma-270m-tool-agent
20
+
21
+ Fine-tuned [FunctionGemma 270M](https://huggingface.co/unsloth/functiongemma-270m-it) LoRA adapter
22
+ specialized for **general tool/function calling**.
23
+
24
+ ## Benchmark Results
25
+
26
+ Evaluated using [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness) on 100 held-out general function-calling examples:
27
+
28
+ | Metric | Base | Fine-tuned | Delta |
29
+ |--------|------|-----------|-------|
30
+ | Tool Selection Acc | 49.0% | 78.0% | **+29.0%** |
31
+ | First Tool Acc | 49.0% | 88.0% | **+39.0%** |
32
+ | Negative Rejection | 100.0% | 100.0% | +0.0% |
33
+ | Param Accuracy | 49.0% | 68.9% | **+19.9%** |
34
+
35
+ ## Training
36
+
37
+ - **Base model**: `unsloth/functiongemma-270m-it`
38
+ - **Method**: LoRA (r=16, alpha=32) via PEFT + TRL SFTTrainer
39
+ - **Dataset**: 13,000 general function-calling examples
40
+ - **Epochs**: 3
41
+ - **Hardware**: NVIDIA H100 SXM 80GB
42
+
43
+ ### Data composition
44
+
45
+ | Source | Examples | Purpose |
46
+ |--------|----------|---------|
47
+ | xlam-function-calling-60k | ~10,000 | General function calling |
48
+ | xlam-irrelevance-7.5k | ~3,000 | Negative examples / refusal |
49
+ | **Total** | **~13,000** | |
50
+
51
+ ## Usage
52
+
53
+ ### With PEFT
54
+
55
+ ```python
56
+ from peft import PeftModel
57
+ from transformers import AutoModelForCausalLM, AutoTokenizer
58
+
59
+ base = AutoModelForCausalLM.from_pretrained("unsloth/functiongemma-270m-it", torch_dtype="auto")
60
+ model = PeftModel.from_pretrained(base, "sumitagrawal/functiongemma-270m-tool-agent")
61
+ tokenizer = AutoTokenizer.from_pretrained("sumitagrawal/functiongemma-270m-tool-agent")
62
+
63
+ prompt = """<start_of_turn>developer
64
+ You are a helpful assistant with access to the following tools:
65
+ - send_email(to, subject, body): Send an email
66
+ - search_contacts(query): Search contacts by name
67
+ <end_of_turn>
68
+ <start_of_turn>user
69
+ Send an email to John about the meeting tomorrow
70
+ <end_of_turn>
71
+ <start_of_turn>model
72
+ """
73
+
74
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
75
+ out = model.generate(**inputs, max_new_tokens=128, temperature=0.1)
76
+ print(tokenizer.decode(out[0], skip_special_tokens=False))
77
+ ```
78
+
79
+ ### With Ollama (GGUF)
80
+
81
+ Export to GGUF first, then:
82
+
83
+ ```bash
84
+ ollama create tool-agent -f Modelfile
85
+ ollama run tool-agent
86
+ ```
87
+
88
+ ## Output format
89
+
90
+ The model uses FunctionGemma's native control-token format:
91
+
92
+ ```
93
+ <start_function_call>call:function_name{param1:<escape>value1<escape>param2:<escape>value2<escape>}<end_function_call>
94
+ ```
95
+
96
+ ## License
97
+
98
+ Apache 2.0 (same as the base model).
adapter_config.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": null,
6
+ "base_model_name_or_path": "unsloth/functiongemma-270m-it",
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": 32,
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": 16,
29
+ "rank_pattern": {},
30
+ "revision": null,
31
+ "target_modules": [
32
+ "up_proj",
33
+ "q_proj",
34
+ "k_proj",
35
+ "gate_proj",
36
+ "v_proj",
37
+ "o_proj",
38
+ "down_proj"
39
+ ],
40
+ "target_parameters": null,
41
+ "task_type": "CAUSAL_LM",
42
+ "trainable_token_indices": null,
43
+ "use_dora": false,
44
+ "use_qalora": false,
45
+ "use_rslora": false
46
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:98bfb86398fce37bdec7d1749de4d01cee9400723a5d8566c1bcccb7c97a5417
3
+ size 15220968
chat_template.jinja ADDED
@@ -0,0 +1,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ {%- if key not in standard_keys -%}
6
+ {%- if ns.found_first %},{% endif -%}
7
+ {%- set ns.found_first = true -%}
8
+ {{- key }}:{description:<escape>{{ value['description'] }}<escape>
9
+ {%- if value['type'] | upper == 'STRING' -%}
10
+ {%- if value['enum'] -%}
11
+ ,enum:{{ format_argument(value['enum']) }}
12
+ {%- endif -%}
13
+ {%- elif value['type'] | upper == 'OBJECT' -%}
14
+ ,properties:{
15
+ {%- if value['properties'] is defined and value['properties'] is mapping -%}
16
+ {{- format_parameters(value['properties'], value['required'] | default([])) -}}
17
+ {%- elif value is mapping -%}
18
+ {{- format_parameters(value, value['required'] | default([])) -}}
19
+ {%- endif -%}
20
+ }
21
+ {%- if value['required'] -%}
22
+ ,required:[
23
+ {%- for item in value['required'] | default([]) -%}
24
+ <escape>{{- item -}}<escape>
25
+ {%- if not loop.last %},{% endif -%}
26
+ {%- endfor -%}
27
+ ]
28
+ {%- endif -%}
29
+ {%- elif value['type'] | upper == 'ARRAY' -%}
30
+ {%- if value['items'] is mapping and value['items'] -%}
31
+ ,items:{
32
+ {%- set ns_items = namespace(found_first=false) -%}
33
+ {%- for item_key, item_value in value['items'] | dictsort -%}
34
+ {%- if item_value is not none -%}
35
+ {%- if ns_items.found_first %},{% endif -%}
36
+ {%- set ns_items.found_first = true -%}
37
+ {%- if item_key == 'properties' -%}
38
+ properties:{
39
+ {%- if item_value is mapping -%}
40
+ {{- format_parameters(item_value, value['items']['required'] | default([])) -}}
41
+ {%- endif -%}
42
+ }
43
+ {%- elif item_key == 'required' -%}
44
+ required:[
45
+ {%- for req_item in item_value -%}
46
+ <escape>{{- req_item -}}<escape>
47
+ {%- if not loop.last %},{% endif -%}
48
+ {%- endfor -%}
49
+ ]
50
+ {%- elif item_key == 'type' -%}
51
+ {%- if item_value is string -%}
52
+ type:{{ format_argument(item_value | upper) }}
53
+ {%- else -%}
54
+ type:{{ format_argument(item_value | map('upper') | list) }}
55
+ {%- endif -%}
56
+ {%- else -%}
57
+ {{ item_key }}:{{ format_argument(item_value) }}
58
+ {%- endif -%}
59
+ {%- endif -%}
60
+ {%- endfor -%}
61
+ }
62
+ {%- endif -%}
63
+ {%- endif -%}
64
+ ,type:<escape>{{ value['type'] | upper }}<escape>}
65
+ {%- endif -%}
66
+ {%- endfor -%}
67
+ {%- endmacro -%}
68
+ {% macro format_function_declaration(tool_data) -%}
69
+ declaration:{{- tool_data['function']['name'] -}}
70
+ {description:<escape>{{- tool_data['function']['description'] -}}<escape>
71
+ {%- set params = tool_data['function']['parameters'] -%}
72
+ {%- if params -%}
73
+ ,parameters:{
74
+ {%- if params['properties'] -%}
75
+ properties:{ {{- format_parameters(params['properties'], params['required']) -}} },
76
+ {%- endif -%}
77
+ {%- if params['required'] -%}
78
+ required:[
79
+ {%- for item in params['required'] -%}
80
+ <escape>{{- item -}}<escape>
81
+ {{- ',' if not loop.last -}}
82
+ {%- endfor -%}
83
+ ],
84
+ {%- endif -%}
85
+ {%- if params['type'] -%}
86
+ type:<escape>{{- params['type'] | upper -}}<escape>}
87
+ {%- endif -%}
88
+ {%- endif -%}
89
+ }
90
+ {%- endmacro -%}
91
+ {% macro format_argument(argument, escape_keys=True) -%}
92
+ {%- if argument is string -%}
93
+ {{- '<escape>' + argument + '<escape>' -}}
94
+ {%- elif argument is boolean -%}
95
+ {%- if argument -%}
96
+ {{- 'true' -}}
97
+ {%- else -%}
98
+ {{- 'false' -}}
99
+ {%- endif -%}
100
+ {%- elif argument is mapping -%}
101
+ {{- '{' -}}
102
+ {%- set ns = namespace(found_first=false) -%}
103
+ {%- for key, value in argument | dictsort -%}
104
+ {%- if ns.found_first %},{% endif -%}
105
+ {%- set ns.found_first = true -%}
106
+ {%- if escape_keys -%}
107
+ {{- '<escape>' + key + '<escape>' -}}
108
+ {%- else -%}
109
+ {{- key -}}
110
+ {%- endif -%}
111
+ :{{- format_argument(value, escape_keys=escape_keys) -}}
112
+ {%- endfor -%}
113
+ {{- '}' -}}
114
+ {%- elif argument is sequence -%}
115
+ {{- '[' -}}
116
+ {%- for item in argument -%}
117
+ {{- format_argument(item, escape_keys=escape_keys) -}}
118
+ {%- if not loop.last %},{% endif -%}
119
+ {%- endfor -%}
120
+ {{- ']' -}}
121
+ {%- else -%}
122
+ {{- argument -}}
123
+ {%- endif -%}
124
+ {%- endmacro -%}
125
+ {{ bos_token }}
126
+ {%- set ns = namespace(prev_message_type=None) -%}
127
+ {#- Tool Declarations -#}
128
+ {%- set loop_messages = messages -%}
129
+ {%- if tools or messages[0]['role'] == 'system' or messages[0]['role'] == 'developer' -%}
130
+ {{- '<start_of_turn>developer\n' -}}
131
+ {%- if messages[0]['role'] == 'system' or messages[0]['role'] == 'developer' -%}
132
+ {%- if messages[0]['content'] is string -%}
133
+ {{- messages[0]['content'] | trim -}}
134
+ {%- elif messages[0]['content'] is sequence -%}
135
+ {%- for item in messages[0]['content'] -%}
136
+ {%- if item['type'] == 'text' -%}
137
+ {{- item['text'] | trim -}}
138
+ {%- endif -%}
139
+ {%- endfor -%}
140
+ {%- endif -%}
141
+ {%- set loop_messages = messages[1:] -%}
142
+ {%- else -%}
143
+ {{- 'You are a model that can do function calling with the following functions' -}}
144
+ {%- set loop_messages = messages -%}
145
+ {%- endif -%}
146
+ {%- if tools -%}
147
+ {%- for tool in tools %}
148
+ {{- '<start_function_declaration>' -}}
149
+ {{- format_function_declaration(tool) | trim }}
150
+ {{- '<end_function_declaration>' -}}
151
+ {%- endfor %}
152
+ {%- endif -%}
153
+ {{- '<end_of_turn>\n' }}
154
+ {%- endif %}
155
+ {#- Loop through messages. -#}
156
+ {%- for message in loop_messages -%}
157
+ {%- if (message['role'] == 'assistant') -%}
158
+ {#- Rename "assistant" to "model". -#}
159
+ {%- set role = "model" -%}
160
+ {%- else -%}
161
+ {%- set role = message['role'] -%}
162
+ {%- endif -%}
163
+ {%- if role != 'tool' -%}
164
+ {%- if ns.prev_message_type != 'tool_response' -%}
165
+ {{- '<start_of_turn>' + role + '\n' }}
166
+ {%- endif -%}
167
+ {%- set ns.prev_message_type = None -%}
168
+ {%- if 'content' in message and message['content'] is not none -%}
169
+ {%- if message['content'] is string -%}
170
+ {{ message['content'] | trim }}
171
+ {%- elif message['content'] is sequence -%}
172
+ {%- for item in message['content'] -%}
173
+ {%- if item['type'] == 'image' -%}
174
+ {{ '<start_of_image>' }}
175
+ {%- elif item['type'] == 'text' -%}
176
+ {{ item['text'] | trim }}
177
+ {%- endif -%}
178
+ {%- endfor -%}
179
+ {%- else -%}
180
+ {{ raise_exception("Invalid content type in user/assistant message") }}
181
+ {%- endif -%}
182
+ {%- set ns.prev_message_type = 'content' -%}
183
+ {%- endif -%}
184
+ {%- if 'tool_calls' in message and message['tool_calls'] and message['tool_calls'] is iterable -%}
185
+ {#- Tool Calls -#}
186
+ {%- for tool_call in message['tool_calls'] -%}
187
+ {% set function = tool_call['function'] %}
188
+ {{- '<start_function_call>call:' + function['name'] + '{' -}}
189
+ {%- if 'arguments' in function -%}
190
+ {%- if function['arguments'] is mapping -%}
191
+ {%- set ns = namespace(found_first=false) -%}
192
+ {%- for key, value in function['arguments'] | dictsort -%}
193
+ {%- if ns.found_first %},{% endif -%}
194
+ {%- set ns.found_first = true -%}
195
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
196
+ {%- endfor -%}
197
+ {%- elif function['arguments'] is string -%}
198
+ {# This handles string-JSON, just in case #}
199
+ {{ function['arguments'] }}
200
+ {%- endif %}
201
+ {%- endif -%}
202
+ {{- '}<end_function_call>' -}}
203
+ {%- endfor -%}
204
+ {%- if loop.last -%}
205
+ {{ '<start_function_response>' }}
206
+ {%- endif -%}
207
+ {%- set ns.prev_message_type = 'tool_call' -%}
208
+ {%- endif -%}
209
+ {%- else -%}
210
+ {#- Tool Responses -#}
211
+ {%- if 'content' in message and message['content'] -%}
212
+ {%- if message['content'] is mapping -%}
213
+ {%- if 'name' in message['content'] and 'response' in message['content'] -%}
214
+ {{ '<start_function_response>response:' + message['content']['name'] | trim + '{' }}
215
+ {%- set response_ns = namespace(found_first=false) -%}
216
+ {%- for key, value in message['content']['response'] | dictsort -%}
217
+ {%- if response_ns.found_first %},{% endif -%}
218
+ {%- set response_ns.found_first = true -%}
219
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
220
+ {%- endfor -%}
221
+ {{- '}<end_function_response>' -}}
222
+ {%- elif 'name' in message -%}
223
+ {{ '<start_function_response>response:' + message['name'] | trim + '{' }}
224
+ {%- set response_ns = namespace(found_first=false) -%}
225
+ {%- for key, value in message['content'] | dictsort -%}
226
+ {%- if response_ns.found_first %},{% endif -%}
227
+ {%- set response_ns.found_first = true -%}
228
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
229
+ {%- endfor -%}
230
+ {{- '}<end_function_response>' -}}
231
+ {%- else -%}
232
+ {{ raise_exception("Invalid tool response mapping: must contain 'name' and 'response' keys, or 'name' must be in the message.") }}
233
+ {%- endif -%}
234
+ {%- elif message['content'] is string -%}
235
+ {%- if 'name' in message -%}
236
+ {{ '<start_function_response>response:' + message['name'] | trim + '{value:' + format_argument(message['content'], escape_keys=False) + '}<end_function_response>' }}
237
+ {%- else -%}
238
+ {{ raise_exception("Invalid tool response: 'name' must be provided.") }}
239
+ {%- endif -%}
240
+ {%- elif message['content'] is sequence -%}
241
+ {%- for item in message['content'] -%}
242
+ {%- if item is mapping -%}
243
+ {%- if 'name' in item and 'response' in item -%}
244
+ {{ '<start_function_response>response:' + item['name'] | trim + '{' }}
245
+ {%- set response_ns = namespace(found_first=false) -%}
246
+ {%- for key, value in item['response'] | dictsort -%}
247
+ {%- if response_ns.found_first %},{% endif -%}
248
+ {%- set response_ns.found_first = true -%}
249
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
250
+ {%- endfor -%}
251
+ {{- '}<end_function_response>' -}}
252
+ {%- elif 'name' in message -%}
253
+ {{ '<start_function_response>response:' + message['name'] | trim + '{' }}
254
+ {%- set response_ns = namespace(found_first=false) -%}
255
+ {%- for key, value in item | dictsort -%}
256
+ {%- if response_ns.found_first %},{% endif -%}
257
+ {%- set response_ns.found_first = true -%}
258
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
259
+ {%- endfor -%}
260
+ {{- '}<end_function_response>' -}}
261
+ {%- else -%}
262
+ {{ raise_exception("Invalid tool response mapping: must contain 'name' and 'response' keys, or 'name' must be in the message.") }}
263
+ {%- endif -%}
264
+ {%- else -%}
265
+ {{ raise_exception("Invalid tool response message: multiple responses must all be mappings") }}
266
+ {%- endif -%}
267
+ {%- endfor -%}
268
+ {%- else -%}
269
+ {{ raise_exception("Invalid content type in tool message: must be mapping, sequence of mappings, or string.") }}
270
+ {%- endif -%}
271
+ {%- endif -%}
272
+ {%- set ns.prev_message_type = 'tool_response' -%}
273
+ {%- endif -%}
274
+ {%- if ns.prev_message_type not in ['tool_call', 'tool_response'] -%}
275
+ {{ '<end_of_turn>\n' }}
276
+ {%- endif -%}
277
+ {%- endfor -%}
278
+ {%- if add_generation_prompt -%}
279
+ {%- if ns.prev_message_type != 'tool_response' -%}
280
+ {{- '<start_of_turn>model\n' -}}
281
+ {%- endif -%}
282
+ {%- endif -%}
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:80d7f800b949accd7eb940bac75e642f9468e4df157403032a55bf54ed23b650
3
+ size 33384898
tokenizer_config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "boi_token": "<start_of_image>",
4
+ "bos_token": "<bos>",
5
+ "clean_up_tokenization_spaces": false,
6
+ "eoi_token": "<end_of_image>",
7
+ "eos_token": "<end_of_turn>",
8
+ "image_token": "<image_soft_token>",
9
+ "is_local": false,
10
+ "mask_token": "<mask>",
11
+ "model_max_length": 32768,
12
+ "model_specific_special_tokens": {
13
+ "boi_token": "<start_of_image>",
14
+ "eoi_token": "<end_of_image>",
15
+ "image_token": "<image_soft_token>",
16
+ "sfr_token": "<start_function_response>"
17
+ },
18
+ "pad_token": "<pad>",
19
+ "padding_side": "left",
20
+ "sfr_token": "<start_function_response>",
21
+ "sp_model_kwargs": null,
22
+ "spaces_between_special_tokens": false,
23
+ "tokenizer_class": "GemmaTokenizer",
24
+ "unk_token": "<unk>",
25
+ "use_default_system_prompt": false
26
+ }