macmacmacmac commited on
Commit
2079dd4
·
verified ·
1 Parent(s): 809e7fb

Update README with training data and usage instructions

Browse files
Files changed (1) hide show
  1. README.md +185 -125
README.md CHANGED
@@ -1,159 +1,219 @@
1
  ---
2
  license: gemma
3
- base_model: google/functiongemma-270m-it
4
- tags:
5
- - function-calling
6
- - litert
7
- - on-device
8
- - gemma
9
- - infrastructure
10
- - LiteRT-LM
11
- datasets:
12
- - custom
13
  language:
14
  - en
 
 
15
  pipeline_tag: text-generation
 
 
 
 
 
16
  ---
17
 
18
- # FunctionGemma Infrastructure LiteRT-LM
19
 
20
- A fine-tuned [FunctionGemma-270M](https://huggingface.co/google/functiongemma-270m-it) model converted to LiteRT-LM format for on-device inference. Designed for self-healing infrastructure and automatic error remediation.
21
 
22
  ## Model Details
23
 
24
- | Property | Value |
25
- |----------|-------|
26
- | Base Model | google/functiongemma-270m-it |
27
- | Format | LiteRT-LM (.litertlm) |
28
- | Quantization | Dynamic INT8 |
29
- | File Size | 272 MB |
30
- | Parameters | 270M |
31
-
32
- ## Intended Use
33
-
34
- This model is designed for [dad-express](https://github.com/anthropics/dad-express), a self-healing gateway that monitors HTTP traffic and automatically fixes infrastructure configuration issues by calling the appropriate tools.
35
 
36
  ## Supported Tools
37
 
38
- The model was fine-tuned on 9 infrastructure tools:
39
-
40
- | Tool | Description | Parameters |
41
- |------|-------------|------------|
42
- | `addProxyRoute` | Add reverse proxy route | path, upstream, port |
43
- | `addCorsHeaders` | Configure CORS headers | origin, credentials |
44
- | `configureSsl` | Configure SSL certificate | hostname, selfSigned |
45
- | `setEnvVariable` | Set environment variable | name, value |
46
- | `exposePort` | Expose port in Docker/firewall | service, port |
47
- | `addHostEntry` | Add hostname to /etc/hosts | hostname, ip |
48
- | `restartService` | Restart a service | service |
49
- | `clearCache` | Clear cache | cacheType |
50
- | `modifyConfig` | Modify config file | file, key, value |
51
-
52
- ## Training Details
53
-
54
- ### Dataset
55
- - **Total Examples**: 10,216
56
- - **Train/Eval Split**: 90/10 (9,194 train, 1,022 eval)
57
- - **Format**: Prompt-completion pairs using FunctionGemma chat template
58
- - **Distribution**: ~1,000-1,200 examples per tool (balanced)
59
-
60
- ### Training Configuration
61
-
62
- Trained following [Google's official FunctionGemma fine-tuning notebook](https://colab.research.google.com/github/google-gemini/gemma-cookbook/blob/main/FunctionGemma/%5BFunctionGemma%5DFinetune_FunctionGemma_270M_for_Mobile_Actions_with_Hugging_Face.ipynb):
63
-
64
- ```python
65
- SFTConfig(
66
- num_train_epochs=2,
67
- per_device_train_batch_size=4,
68
- gradient_accumulation_steps=8,
69
- learning_rate=1e-5,
70
- lr_scheduler_type="cosine",
71
- gradient_checkpointing=True,
72
- packing=False,
73
- optim="adamw_torch_fused",
74
- bf16=True,
75
- completion_only_loss=True, # Critical: only train on completion tokens
76
  )
77
  ```
78
 
79
- ### Hardware
80
- - **GPU**: NVIDIA L4 (24GB)
81
- - **Training Time**: ~23 minutes
82
- - **Conversion Time**: ~10 minutes
83
-
84
- ### Performance Metrics
85
-
86
- | Metric | Value |
87
- |--------|-------|
88
- | Final Eval Loss | 0.034 |
89
- | Token Accuracy | 98.6% |
90
- | Training Steps | 576 |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
- ## LiteRT-LM Conversion
93
 
94
- Converted using [ai-edge-torch](https://github.com/google-ai-edge/ai-edge-torch):
 
95
 
96
- ```python
97
- converter.convert_to_litert(
98
- pytorch_model,
99
- prefill_seq_len=256,
100
- kv_cache_max_len=1024,
101
- quantize="dynamic_int8",
102
- output_format="litertlm",
103
- )
104
- ```
105
 
106
- ### LLM Metadata
107
- ```protobuf
108
- start_token: { token_ids: { ids: [ 2 ] } }
109
- stop_tokens: { token_str: "<end_of_turn>" }
110
- stop_tokens: { token_str: "<start_function_response>" }
111
- llm_model_type: { function_gemma: {} }
112
  ```
113
 
114
- ## Usage
115
 
116
- ### With LiteRT-LM Runtime
117
- ```typescript
118
- import { LiteRTLM } from 'litert-lm';
119
 
120
- const model = await LiteRTLM.load('functiongemma-infrastructure_q8_ekv1024.litertlm');
121
- const response = await model.generate(prompt);
122
- ```
 
 
 
 
 
 
123
 
124
- ### Example Input/Output
125
 
126
- **Input:**
127
  ```
128
- Error: CORS - No 'Access-Control-Allow-Origin' header from http://localhost:3000
 
 
 
 
 
 
129
  ```
130
 
131
- **Output:**
132
- ```
133
- <start_function_call>call:addCorsHeaders{origin:<escape>http://localhost:3000<escape>,credentials:<escape>true<escape>}<end_function_call><start_function_response>
134
- ```
135
-
136
- ## Dependencies
137
 
138
- - Python 3.11+
139
- - transformers==4.57.1
140
- - trl==0.25.1
141
- - datasets==4.4.1
142
- - ai-edge-torch-nightly
143
- - ai-edge-litert-nightly
144
 
145
  ## License
146
 
147
- This model inherits the [Gemma Terms of Use](https://ai.google.dev/gemma/terms).
148
-
149
- ## Citation
150
-
151
- ```bibtex
152
- @misc{functiongemma-infrastructure-litertlm,
153
- title={FunctionGemma Infrastructure LiteRT-LM},
154
- author={dad-express contributors},
155
- year={2024},
156
- publisher={Hugging Face},
157
- url={https://huggingface.co/macmacmacmac/functiongemma-infrastructure-litertlm}
158
- }
159
- ```
 
1
  ---
2
  license: gemma
 
 
 
 
 
 
 
 
 
 
3
  language:
4
  - en
5
+ base_model:
6
+ - google/functiongemma-270m-it
7
  pipeline_tag: text-generation
8
+ tags:
9
+ - function-calling
10
+ - infrastructure
11
+ - devops
12
+ - litertlm
13
  ---
14
 
15
+ # FunctionGemma Infrastructure Tools v8
16
 
17
+ A fine-tuned [FunctionGemma 270M](https://huggingface.co/google/functiongemma-270m-it) model for infrastructure error diagnosis and remediation. Achieves **100% accuracy** on 7 infrastructure tools when using the correct tool definitions.
18
 
19
  ## Model Details
20
 
21
+ - **Base Model**: google/functiongemma-270m-it
22
+ - **Format**: LiteRT-LM (.litertlm) - optimized for on-device inference
23
+ - **Quantization**: INT8 (Q8)
24
+ - **Size**: ~271MB
25
+ - **Training**: 50 epochs on 10,500 examples (1,500 per tool)
 
 
 
 
 
 
26
 
27
  ## Supported Tools
28
 
29
+ | Tool | Description | Use Case |
30
+ |------|-------------|----------|
31
+ | `enableCors` | Enable CORS for a specific origin | CORS policy errors, blocked cross-origin requests |
32
+ | `updateConnectionUrl` | Update service connection URL | ECONNREFUSED errors, localhost connection issues in containers |
33
+ | `setEnvVar` | Set environment variable | Missing configuration, undefined env vars |
34
+ | `addHostMapping` | Add hostname to IP mapping | DNS resolution (ENOTFOUND) errors |
35
+ | `increaseMemory` | Increase memory limit | OOMKilled errors, out of memory crashes |
36
+ | `increaseTimeout` | Increase timeout value | 504 Gateway Timeout, connection timeout errors |
37
+ | `restartService` | Restart a service | Stuck processes, stale data after deployment |
38
+
39
+ ## Usage with LiteRT-LM
40
+
41
+ ### Download the Model
42
+
43
+ ```bash
44
+ # Using huggingface-cli
45
+ huggingface-cli download macmacmacmac/functiongemma-nextjs functiongemma-infra-v8_q8_ekv1024.litertlm
46
+
47
+ # Or using Python
48
+ from huggingface_hub import hf_hub_download
49
+ model_path = hf_hub_download(
50
+ repo_id="macmacmacmac/functiongemma-nextjs",
51
+ filename="functiongemma-infra-v8_q8_ekv1024.litertlm"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  )
53
  ```
54
 
55
+ ### Required Tool Definitions
56
+
57
+ **Important**: You must use these exact tool definitions for optimal accuracy. The model was trained with these specific descriptions.
58
+
59
+ ```javascript
60
+ const tools = [
61
+ {
62
+ type: "function",
63
+ function: {
64
+ name: "enableCors",
65
+ description: "Enable CORS for a specific origin to fix blocked cross-origin requests.",
66
+ parameters: {
67
+ type: "object",
68
+ properties: {
69
+ origin: { type: "string", description: "The origin to allow (e.g., http://localhost:3000)" },
70
+ methods: { type: "string", description: "Allowed HTTP methods (e.g., GET,POST,PUT,DELETE)" }
71
+ },
72
+ required: ["origin"]
73
+ }
74
+ }
75
+ },
76
+ {
77
+ type: "function",
78
+ function: {
79
+ name: "updateConnectionUrl",
80
+ description: "Update a service connection URL to fix ECONNREFUSED errors, typically changing localhost to the correct service hostname.",
81
+ parameters: {
82
+ type: "object",
83
+ properties: {
84
+ service: { type: "string", description: "The service to update (e.g., database, redis, api)" },
85
+ hostname: { type: "string", description: "The correct hostname to connect to" },
86
+ port: { type: "integer", description: "The port number to connect to" }
87
+ },
88
+ required: ["service", "hostname", "port"]
89
+ }
90
+ }
91
+ },
92
+ {
93
+ type: "function",
94
+ function: {
95
+ name: "setEnvVar",
96
+ description: "Set an environment variable to fix missing configuration errors.",
97
+ parameters: {
98
+ type: "object",
99
+ properties: {
100
+ name: { type: "string", description: "Environment variable name (e.g., DATABASE_URL, API_KEY)" },
101
+ value: { type: "string", description: "The value to set" }
102
+ },
103
+ required: ["name", "value"]
104
+ }
105
+ }
106
+ },
107
+ {
108
+ type: "function",
109
+ function: {
110
+ name: "addHostMapping",
111
+ description: "Add a hostname to IP mapping to fix DNS resolution (ENOTFOUND) errors.",
112
+ parameters: {
113
+ type: "object",
114
+ properties: {
115
+ hostname: { type: "string", description: "The hostname to map" },
116
+ ip: { type: "string", description: "The IP address to map to" }
117
+ },
118
+ required: ["hostname", "ip"]
119
+ }
120
+ }
121
+ },
122
+ {
123
+ type: "function",
124
+ function: {
125
+ name: "increaseMemory",
126
+ description: "Increase memory limit for a service to fix OOMKilled errors.",
127
+ parameters: {
128
+ type: "object",
129
+ properties: {
130
+ service: { type: "string", description: "The service/container/pod name" },
131
+ memoryMb: { type: "integer", description: "Memory limit in megabytes" }
132
+ },
133
+ required: ["service", "memoryMb"]
134
+ }
135
+ }
136
+ },
137
+ {
138
+ type: "function",
139
+ function: {
140
+ name: "increaseTimeout",
141
+ description: "Increase timeout value to fix 504 Gateway Timeout or connection timeout errors.",
142
+ parameters: {
143
+ type: "object",
144
+ properties: {
145
+ service: { type: "string", description: "The service to configure" },
146
+ timeoutMs: { type: "integer", description: "Timeout value in milliseconds" }
147
+ },
148
+ required: ["service", "timeoutMs"]
149
+ }
150
+ }
151
+ },
152
+ {
153
+ type: "function",
154
+ function: {
155
+ name: "restartService",
156
+ description: "Restart a service to apply configuration changes or fix a stuck process.",
157
+ parameters: {
158
+ type: "object",
159
+ properties: {
160
+ service: { type: "string", description: "The service/container/pod name to restart" }
161
+ },
162
+ required: ["service"]
163
+ }
164
+ }
165
+ }
166
+ ];
167
+ ```
168
 
169
+ ### Example Usage with dad-express
170
 
171
+ ```javascript
172
+ const { FunctionGemmaEngine } = require('dad-express');
173
 
174
+ const engine = new FunctionGemmaEngine({
175
+ modelPath: './functiongemma-infra-v8_q8_ekv1024.litertlm',
176
+ tools: JSON.stringify(tools)
177
+ });
 
 
 
 
 
178
 
179
+ // Diagnose an error
180
+ const result = await engine.call('Container api was OOMKilled - out of memory');
181
+ console.log(result.tool_calls[0].function);
182
+ // { name: 'increaseMemory', arguments: { service: 'api', memoryMb: 1024 } }
 
 
183
  ```
184
 
185
+ ## Training Data
186
 
187
+ The model was trained on 10,500 synthetic examples covering common infrastructure errors:
 
 
188
 
189
+ | Error Pattern | Tool | Examples |
190
+ |--------------|------|----------|
191
+ | CORS policy errors | enableCors | 1,500 |
192
+ | ECONNREFUSED errors | updateConnectionUrl | 1,500 |
193
+ | Missing env vars | setEnvVar | 1,500 |
194
+ | DNS/ENOTFOUND errors | addHostMapping | 1,500 |
195
+ | OOMKilled errors | increaseMemory | 1,500 |
196
+ | Timeout errors | increaseTimeout | 1,500 |
197
+ | Stuck services | restartService | 1,500 |
198
 
199
+ ### Sample Training Examples
200
 
 
201
  ```
202
+ "CORS error: No 'Access-Control-Allow-Origin' header from http://localhost:3000" → enableCors
203
+ "Error: connect ECONNREFUSED 127.0.0.1:5432 - database connection failed" → updateConnectionUrl
204
+ "Missing required environment variable: DATABASE_URL" → setEnvVar
205
+ "getaddrinfo ENOTFOUND db" → addHostMapping
206
+ "Container api was OOMKilled" → increaseMemory
207
+ "504 Gateway Timeout from backend" → increaseTimeout
208
+ "nginx container is not responding" → restartService
209
  ```
210
 
211
+ ## Limitations
 
 
 
 
 
212
 
213
+ - Optimized for the 7 specific infrastructure tools listed above
214
+ - Requires exact tool definitions for best accuracy
215
+ - May not generalize well to error patterns not seen in training
 
 
 
216
 
217
  ## License
218
 
219
+ This model inherits the [Gemma license](https://ai.google.dev/gemma/terms) from the base model.