essobi commited on
Commit
2f47925
·
verified ·
1 Parent(s): b6e6477

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +262 -13
README.md CHANGED
@@ -1,21 +1,270 @@
1
  ---
2
- base_model: unsloth/functiongemma-270m-it
 
3
  tags:
4
- - text-generation-inference
5
- - transformers
6
- - unsloth
7
- - gemma3_text
8
- license: apache-2.0
 
 
 
 
 
9
  language:
10
- - en
11
  ---
12
 
13
- # Uploaded finetuned model
14
 
15
- - **Developed by:** essobi
16
- - **License:** apache-2.0
17
- - **Finetuned from model :** unsloth/functiongemma-270m-it
18
 
19
- This gemma3_text model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
20
 
21
- [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: gemma
3
+ library_name: transformers
4
  tags:
5
+ - function-calling
6
+ - tool-use
7
+ - mobile
8
+ - gemma
9
+ - unsloth
10
+ - fine-tuned
11
+ base_model: google/gemma-3-1b-it
12
+ datasets:
13
+ - google/mobile-actions
14
+ pipeline_tag: text-generation
15
  language:
16
+ - en
17
  ---
18
 
19
+ # FunctionGemma Mobile Actions v5
20
 
21
+ A fine-tuned version of [FunctionGemma 270M](https://huggingface.co/google/gemma-3-1b-it) optimized for mobile device function calling. This model excels at understanding natural language commands and mapping them to structured function calls for common mobile actions.
 
 
22
 
23
+ ## Model Description
24
 
25
+ - **Base Model:** google/gemma-3-1b-it (270M parameters)
26
+ - **Fine-tuning Method:** LoRA (r=128, alpha=128)
27
+ - **Training Data:** [google/mobile-actions](https://huggingface.co/datasets/google/mobile-actions) + synthetic augmentation
28
+ - **Optimized For:** Mobile assistant function calling
29
+
30
+ ## Supported Functions
31
+
32
+ | Function | Description | Example Input |
33
+ |----------|-------------|---------------|
34
+ | `set_alarm` | Set alarms | "Wake me up at 7am" |
35
+ | `create_reminder` | Create reminders | "Remind me to buy milk" |
36
+ | `set_timer` | Set countdown timers | "Timer for 10 minutes" |
37
+ | `make_call` | Make phone calls | "Call Mom" |
38
+ | `send_message` | Send text messages | "Text John I'm running late" |
39
+ | `create_calendar_event` | Schedule events | "Schedule meeting at 3pm" |
40
+ | `play_music` | Play music | "Play some jazz" |
41
+ | `get_weather` | Get weather info | "What's the weather like?" |
42
+ | `open_app` | Open applications | "Open the camera" |
43
+ | `navigate` | Get directions | "Navigate to the airport" |
44
+ | `set_volume` | Adjust volume | "Turn the volume up" |
45
+ | `calculator` | Math calculations | "What's 15 times 23?" |
46
+
47
+ ## Usage with vLLM
48
+
49
+ ### Installation
50
+
51
+ ```bash
52
+ pip install vllm
53
+ ```
54
+
55
+ ### Basic Inference
56
+
57
+ ```python
58
+ from vllm import LLM, SamplingParams
59
+ from datetime import datetime
60
+
61
+ # Load model
62
+ llm = LLM(
63
+ model="essobi/functiongemma-mobile-actions-v5-16bit",
64
+ trust_remote_code=True,
65
+ max_model_len=4096,
66
+ )
67
+
68
+ # Define available tools
69
+ tools = [
70
+ {
71
+ "function": {
72
+ "name": "set_alarm",
73
+ "description": "Sets an alarm for a specific time.",
74
+ "parameters": {
75
+ "type": "OBJECT",
76
+ "properties": {
77
+ "datetime": {"type": "STRING", "description": "The time for the alarm."},
78
+ "title": {"type": "STRING", "description": "Optional label for the alarm."},
79
+ },
80
+ "required": ["datetime"]
81
+ }
82
+ }
83
+ },
84
+ {
85
+ "function": {
86
+ "name": "create_reminder",
87
+ "description": "Creates a reminder with text and optional time.",
88
+ "parameters": {
89
+ "type": "OBJECT",
90
+ "properties": {
91
+ "body": {"type": "STRING", "description": "The reminder text."},
92
+ "datetime": {"type": "STRING", "description": "When to remind."},
93
+ },
94
+ "required": ["body"]
95
+ }
96
+ }
97
+ },
98
+ {
99
+ "function": {
100
+ "name": "send_message",
101
+ "description": "Sends a text message to a contact.",
102
+ "parameters": {
103
+ "type": "OBJECT",
104
+ "properties": {
105
+ "to": {"type": "STRING", "description": "Contact name or phone number."},
106
+ "body": {"type": "STRING", "description": "Message content."},
107
+ },
108
+ "required": ["to", "body"]
109
+ }
110
+ }
111
+ },
112
+ # Add more tools as needed...
113
+ ]
114
+
115
+ # Build prompt using the training format
116
+ def build_prompt(user_input: str, tools: list) -> str:
117
+ now = datetime.now()
118
+ dt_str = now.strftime("%Y-%m-%dT%H:%M:%S")
119
+ day = now.strftime("%A")
120
+
121
+ # Build function declarations
122
+ func_decls = ""
123
+ for tool in tools:
124
+ func = tool["function"]
125
+ props = func["parameters"].get("properties", {})
126
+ required = func["parameters"].get("required", [])
127
+
128
+ props_str = ""
129
+ for pname, pinfo in props.items():
130
+ desc = pinfo.get("description", "")
131
+ ptype = pinfo.get("type", "STRING")
132
+ props_str += f"{pname}:{{description:<escape>{desc}<escape>,type:<escape>{ptype}<escape>}},"
133
+ props_str = props_str.rstrip(",")
134
+
135
+ req_str = ",".join([f"<escape>{r}<escape>" for r in required])
136
+
137
+ func_decls += f"<start_function_declaration>declaration:{func['name']}{{description:<escape>{func['description']}<escape>,parameters:{{properties:{{{props_str}}},required:[{req_str}],type:<escape>OBJECT<escape>}}}}<end_function_declaration>"
138
+
139
+ return f"""<start_of_turn>developer
140
+ Current date and time given in YYYY-MM-DDTHH:MM:SS format: {dt_str}
141
+ Day of week is {day}
142
+ You are a model that can do function calling with the following functions{func_decls}<end_of_turn>
143
+ <start_of_turn>user
144
+ {user_input}<end_of_turn>
145
+ <start_of_turn>model
146
+ """
147
+
148
+ # Generate
149
+ prompt = build_prompt("Set an alarm for 7am tomorrow", tools)
150
+ sampling_params = SamplingParams(temperature=0.1, max_tokens=150)
151
+ outputs = llm.generate([prompt], sampling_params)
152
+
153
+ print(outputs[0].outputs[0].text)
154
+ # Output: <start_function_call>call:set_alarm{datetime:<escape>7am tomorrow<escape>}<end_function_call>
155
+ ```
156
+
157
+ ### vLLM OpenAI-Compatible Server
158
+
159
+ ```bash
160
+ # Start the server
161
+ python -m vllm.entrypoints.openai.api_server \
162
+ --model essobi/functiongemma-mobile-actions-v5-16bit \
163
+ --port 8000
164
+ ```
165
+
166
+ ```python
167
+ from openai import OpenAI
168
+
169
+ client = OpenAI(base_url="http://localhost:8000/v1", api_key="dummy")
170
+
171
+ response = client.chat.completions.create(
172
+ model="essobi/functiongemma-mobile-actions-v5-16bit",
173
+ messages=[
174
+ {"role": "user", "content": "Remind me to call the dentist tomorrow"}
175
+ ],
176
+ max_tokens=150,
177
+ temperature=0.1,
178
+ )
179
+
180
+ print(response.choices[0].message.content)
181
+ ```
182
+
183
+ ## Usage with Transformers
184
+
185
+ ```python
186
+ from transformers import AutoTokenizer, AutoModelForCausalLM
187
+ import torch
188
+
189
+ model_id = "essobi/functiongemma-mobile-actions-v5-16bit"
190
+
191
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
192
+ model = AutoModelForCausalLM.from_pretrained(
193
+ model_id,
194
+ torch_dtype=torch.float16,
195
+ device_map="auto",
196
+ )
197
+
198
+ # Use the same prompt building function as above
199
+ prompt = build_prompt("What's the weather like?", tools)
200
+
201
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
202
+ outputs = model.generate(**inputs, max_new_tokens=150, temperature=0.1, do_sample=True)
203
+ response = tokenizer.decode(outputs[0], skip_special_tokens=False)
204
+
205
+ print(response)
206
+ ```
207
+
208
+ ## Output Format
209
+
210
+ The model outputs function calls in this format:
211
+
212
+ ```
213
+ <start_function_call>call:function_name{param1:<escape>value1<escape>,param2:<escape>value2<escape>}<end_function_call>
214
+ ```
215
+
216
+ ### Parsing Function Calls
217
+
218
+ ```python
219
+ import re
220
+
221
+ def parse_function_call(text: str) -> dict | None:
222
+ """Parse function call from model output."""
223
+ match = re.search(
224
+ r'<start_function_call>call:(\w+)\{([^}]*)\}<end_function_call>',
225
+ text
226
+ )
227
+ if not match:
228
+ return None
229
+
230
+ func_name = match.group(1)
231
+ args_str = match.group(2)
232
+
233
+ # Parse arguments
234
+ args = {}
235
+ for param_match in re.finditer(r'(\w+):<escape>([^<]*)<escape>', args_str):
236
+ args[param_match.group(1)] = param_match.group(2)
237
+
238
+ return {"name": func_name, "arguments": args}
239
+
240
+ # Example
241
+ output = "<start_function_call>call:set_alarm{datetime:<escape>7am<escape>,title:<escape>Wake up<escape>}<end_function_call>"
242
+ parsed = parse_function_call(output)
243
+ print(parsed)
244
+ # {'name': 'set_alarm', 'arguments': {'datetime': '7am', 'title': 'Wake up'}}
245
+ ```
246
+
247
+ ## Training Details
248
+
249
+ - **Hardware:** 8x Tesla V100-SXM2-32GB
250
+ - **Training Time:** ~48 minutes
251
+ - **Epochs:** 3
252
+ - **Batch Size:** 64 effective (4 per device × 2 grad accum × 8 GPUs)
253
+ - **Learning Rate:** 1e-5 with linear schedule
254
+ - **Gradient Clipping:** max_grad_norm=1.0
255
+
256
+ ## Limitations
257
+
258
+ - Optimized for English only
259
+ - Best for single-turn function calling (not multi-turn conversations)
260
+ - May struggle with highly ambiguous requests
261
+ - Calendar vs Reminder distinction can be tricky for edge cases
262
+
263
+ ## License
264
+
265
+ This model is released under the [Gemma License](https://ai.google.dev/gemma/terms).
266
+
267
+ ## Acknowledgments
268
+
269
+ - Google for the [Gemma](https://ai.google.dev/gemma) model family and [mobile-actions](https://huggingface.co/datasets/google/mobile-actions) dataset
270
+ - [Unsloth](https://github.com/unslothai/unsloth) for efficient fine-tuning tools