zeriworkspace commited on
Commit
6e013ad
·
verified ·
1 Parent(s): 5e770ad

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,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: ko
3
+ license: mit
4
+ tags:
5
+ - function-calling
6
+ - korean
7
+ - banking
8
+ - on-device
9
+ - onnx
10
+ - int8
11
+ - webgpu
12
+ base_model: google/functiongemma-270m-it
13
+ ---
14
+
15
+ # TransferFunctionGemma
16
+
17
+ 한국어 자연어 이체 명령을 구조화된 function call로 변환하는 경량 모델입니다.
18
+
19
+ ## Model Description
20
+
21
+ TransferFunctionGemma는 [google/functiongemma-270m-it](https://huggingface.co/google/functiongemma-270m-it)를 한국어 금융 이체 도메인에 맞게 full fine-tuning한 모델입니다. 자연어 이체 명령을 분석하여 4종류의 function call JSON으로 변환합니다.
22
+
23
+ ONNX INT8 양자화를 통해 약 418MB로 경량화되었으며, Transformers.js + WebGPU를 통해 브라우저에서 직접 추론할 수 있습니다. 서버 통신 없이 100% 클라이언트 사이드에서 동작합니다.
24
+
25
+ ### Supported Functions
26
+
27
+ | Function | 설명 | 필수 인자 |
28
+ |----------|------|-----------|
29
+ | `execute_transfer` | 수취인에게 금액을 이체합니다 | `recipient`, `amount` |
30
+ | `query_history` | 이체 내역을 조회합니다 | (없음) |
31
+ | `summarize_history` | 이체 내역을 요약합니다 | `period` |
32
+ | `confirm_transfer` | 대기 중인 이체를 확인/취소/수정합니다 | `action` |
33
+
34
+ ---
35
+
36
+ ## Intended Use
37
+
38
+ ### Primary Use Cases
39
+
40
+ - **브라우저 기반 이체 데모**: URL 접속만으로 자연어 이체 기능을 체험
41
+ - **포트폴리오 데모**: 기술 면접관/채용 담당자에게 온디바이스 AI 역량 시연
42
+ - **온디바이스 AI 레퍼런스**: FunctionGemma fine-tuning + 브라우저 배포 파이프라인 참고
43
+
44
+ ### Out-of-Scope Use
45
+
46
+ - 실제 금융 거래에 사용하면 안 됩니다 (이 모델은 데모 전용입니다)
47
+ - 이체 외의 금융 업무(대출, 투자, 보험 등)에는 학습되지 않았습니다
48
+ - 영어 등 한국어 외 언어 입력은 지원하지 않습니다
49
+
50
+ ---
51
+
52
+ ## Training Data
53
+
54
+ ### Seed Data
55
+
56
+ 각 카테고리별 5~10개, 총 약 50~80개의 시드 데이터를 수작업으로 작성했습니다.
57
+
58
+ | 카테고리 | 목표 샘플 수 | 설명 |
59
+ |----------|-------------|------|
60
+ | transfer_simple | 150 | 기본 이체 ("엄마한테 5만원 보내줘") |
61
+ | transfer_complex | 100 | 메모 포함, 복합 요청 |
62
+ | confirm_cancel_modify | 80 | 확인/취소/수정 멀티턴 |
63
+ | clarify | 80 | 정보 부족 시 자연어 되물음 |
64
+ | query_history | 80 | 내역 조회 (기간/수취인 필터) |
65
+ | summarize | 60 | 기간별 이체 요약 |
66
+ | alias_diversity | 100 | 별명 변형 (엄마/어머니/맘) |
67
+ | amount_parsing | 100 | 한국어 금액 (오만원/5만/삼백만) |
68
+ | rejection | 50 | 이체 외 요청 거절 |
69
+ | edge_cases | 50 | 오타, 비문, 혼합 요청 |
70
+
71
+ ### Data Augmentation
72
+
73
+ 시드 데이터를 Claude API로 증강하여 500~1,000개 학습 샘플을 생성했습니다. 증강 시 다음을 변형합니다:
74
+
75
+ - 말투: 존댓말/반말/줄임말
76
+ - 오타 및 비문
77
+ - 금액 표현 방식: 순한글, 숫자+한자, 혼합, 아라비아 숫자
78
+ - 별명 변형
79
+
80
+ ### Data Format
81
+
82
+ FunctionGemma chat template을 준수합니다:
83
+
84
+ ```jsonl
85
+ {
86
+ "messages": [
87
+ {
88
+ "role": "developer",
89
+ "content": "You are a model that can do function calling with the following functions",
90
+ "tool_definitions": [...]
91
+ },
92
+ {
93
+ "role": "user",
94
+ "content": "엄마한테 오만원 보내"
95
+ },
96
+ {
97
+ "role": "assistant",
98
+ "content": "",
99
+ "function_calls": [
100
+ {"name": "execute_transfer", "arguments": {"recipient": "엄마", "amount": 50000}}
101
+ ]
102
+ }
103
+ ]
104
+ }
105
+ ```
106
+
107
+ ### Validation
108
+
109
+ 모든 데이터는 자동 검증을 거칩니다:
110
+
111
+ - JSON schema 유효성 검사
112
+ - function name이 정의된 4개 중 하나인지 확인
113
+ - amount가 양의 정수인지 확인
114
+ - 한국어 금액 -> 숫자 변환 정확성 spot check
115
+
116
+ ---
117
+
118
+ ## Training Procedure
119
+
120
+ ### Base Model
121
+
122
+ - **모델**: google/functiongemma-270m-it
123
+ - **학습 방식**: Full fine-tuning (모델이 경량이므로 LoRA 없이 전체 파라미터 학습)
124
+
125
+ ### Hyperparameters
126
+
127
+ | 파라미터 | 값 |
128
+ |----------|-----|
129
+ | Epochs | 5 |
130
+ | Batch Size (per device) | 8 |
131
+ | Learning Rate | 5e-5 |
132
+ | LR Scheduler | cosine |
133
+ | Warmup Ratio | 0.1 |
134
+ | Weight Decay | 0.01 |
135
+ | Max Sequence Length | 2048 |
136
+ | Precision | bfloat16 |
137
+ | Eval Strategy | epoch |
138
+ | Save Strategy | epoch |
139
+ | Metric for Best Model | eval_loss |
140
+
141
+ ### Training Environment
142
+
143
+ - **하드웨어**: WSL (RAM 128GB / RTX 3070)
144
+ - **소프트웨어**: HuggingFace Transformers + TRL (SFTTrainer)
145
+
146
+ ### Quantization
147
+
148
+ ```bash
149
+ # Fine-tuned 모델 -> ONNX 변환 + INT8 양자화
150
+ python ml/scripts/convert_onnx.py
151
+ ```
152
+
153
+ - ONNX 변환: optimum (`optimum.exporters.onnx`)
154
+ - INT8 동적 양자화: onnxruntime (`quantize_dynamic`, `QuantType.QInt8`)
155
+ - 최종 모델 크기: **418MB** (ONNX INT8)
156
+ - 참고: INT4는 onnxruntime과 Gemma weight layout 비호환으로 INT8 사용
157
+
158
+ ---
159
+
160
+ ## Evaluation Results
161
+
162
+ ### Base Model vs Fine-tuned Model ��교
163
+
164
+ 시드 데이터 50개 기준 (학습 데이터에 포함되지 않은 원본 시드)
165
+
166
+ | 메트릭 | Base (functiongemma-270m-it) | Fine-tuned | 개선율 |
167
+ |--------|------------------------------|------------|--------|
168
+ | Intent Accuracy | 0.0% | 88.9% | +88.9%p |
169
+ | JSON Validity | 10.0% | 100.0% | +90.0%p |
170
+ | Amount Parsing | 0.0% | 100.0% | +100.0%p |
171
+ | Argument F1 (macro) | 0.0% | 57.5% | +57.5%p |
172
+ | Rejection Accuracy | 100.0% | 100.0% | +0.0%p |
173
+
174
+ #### Argument F1 세부
175
+
176
+ | 필드 | F1 |
177
+ |------|-----|
178
+ | recipient | 83.8% |
179
+ | amount | 86.1% |
180
+ | memo | 75.0% |
181
+ | period | 100.0% |
182
+ | action | 0.0% |
183
+ | new_amount | 0.0% |
184
+
185
+ > `action`/`new_amount`는 `confirm_transfer` 함수 전용 인자로, 시드 데이터 내 해당 예제 부족이 원인입니다.
186
+
187
+ ---
188
+
189
+ ## Limitations
190
+
191
+ - **도메인 제한**: 이체 관련 명령만 처리 가능합니다. 그 외 금융 업무(대출, 투자 등)나 일반 대화에는 적합하지 않습니다.
192
+ - **언어 제한**: 한국어 입력만 지원합니다.
193
+ - **브라우저 제한**: WebGPU 지원 브라우저(Chrome 113+, Edge 113+)에서만 정상 동작합니다.
194
+ - **데모 전용**: Mock Banking Engine으로 시뮬레이션만 수행하며, 실제 금융 거래를 수행하지 않습니다.
195
+ - **학습 데이터 편향**: 시드 데이터와 Claude API 증강 기반이므로, 실제 사용자 발화 패턴과 차이가 있을 수 있습니다.
196
+ - **복합 명령 제한**: "엄마한테 5만원, 아빠한테 3만원 보내줘" 같은 복합 이체 명령은 지원하지 않습니다.
197
+
198
+ ---
199
+
200
+ ## How to Use
201
+
202
+ ### With Transformers.js (Browser)
203
+
204
+ ```javascript
205
+ import { pipeline } from '@xenova/transformers';
206
+
207
+ // 모델 로드 (WebGPU 자동 감지)
208
+ const generator = await pipeline(
209
+ 'text-generation',
210
+ 'your-username/transfer-function-gemma-onnx-int4',
211
+ { device: 'webgpu' }
212
+ );
213
+
214
+ // 추론
215
+ const messages = [
216
+ {
217
+ role: 'system',
218
+ content: 'You are a model that can do function calling with the following functions: [execute_transfer, query_history, summarize_history, confirm_transfer]'
219
+ },
220
+ {
221
+ role: 'user',
222
+ content: '엄마한테 5만원 보내줘'
223
+ }
224
+ ];
225
+
226
+ const output = await generator(messages, {
227
+ max_new_tokens: 256,
228
+ temperature: 0.1,
229
+ });
230
+
231
+ console.log(output);
232
+ // => {"name": "execute_transfer", "arguments": {"recipient": "엄마", "amount": 50000}}
233
+ ```
234
+
235
+ ### With Python (HuggingFace Transformers)
236
+
237
+ ```python
238
+ from transformers import AutoModelForCausalLM, AutoTokenizer
239
+
240
+ model = AutoModelForCausalLM.from_pretrained(
241
+ "your-username/transfer-function-gemma",
242
+ torch_dtype="bfloat16",
243
+ device_map="auto"
244
+ )
245
+ tokenizer = AutoTokenizer.from_pretrained(
246
+ "your-username/transfer-function-gemma"
247
+ )
248
+
249
+ messages = [
250
+ {"role": "user", "content": "엄마한테 5만원 보내줘"}
251
+ ]
252
+
253
+ inputs = tokenizer.apply_chat_template(
254
+ messages,
255
+ return_tensors="pt",
256
+ add_generation_prompt=True
257
+ ).to(model.device)
258
+
259
+ outputs = model.generate(inputs, max_new_tokens=256, temperature=0.1)
260
+ result = tokenizer.decode(outputs[0], skip_special_tokens=True)
261
+ print(result)
262
+ ```
263
+
264
+ ---
265
+
266
+ ## Citation
267
+
268
+ ```bibtex
269
+ @misc{transfer-function-gemma-2026,
270
+ title={TransferFunctionGemma: On-Device Korean Banking Function Calling},
271
+ author={Kimin Ryu},
272
+ year={2026},
273
+ url={https://github.com/your-username/TransferFunctionGemma}
274
+ }
275
+ ```
276
+
277
+ ---
278
+
279
+ ## Acknowledgments
280
+
281
+ - [Google Gemma](https://ai.google.dev/gemma) -- Base model
282
+ - [HuggingFace Transformers](https://huggingface.co/docs/transformers) -- Training framework
283
+ - [Transformers.js](https://huggingface.co/docs/transformers.js) -- Browser inference
284
+ - [Anthropic Claude](https://anthropic.com) -- Data augmentation
chat_template.jinja ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ {%- endif -%}
143
+ {%- if tools -%}
144
+ {%- for tool in tools %}
145
+ {{- '<start_function_declaration>' -}}
146
+ {{- format_function_declaration(tool) | trim }}
147
+ {{- '<end_function_declaration>' -}}
148
+ {%- endfor %}
149
+ {%- endif -%}
150
+ {{- '<end_of_turn>\n' }}
151
+ {%- endif %}
152
+ {#- Loop through messages. -#}
153
+ {%- for message in loop_messages -%}
154
+ {%- if (message['role'] == 'assistant') -%}
155
+ {#- Rename "assistant" to "model". -#}
156
+ {%- set role = "model" -%}
157
+ {%- else -%}
158
+ {%- set role = message['role'] -%}
159
+ {%- endif -%}
160
+ {%- if role != 'tool' -%}
161
+ {%- if ns.prev_message_type != 'tool_response' -%}
162
+ {{- '<start_of_turn>' + role + '\n' }}
163
+ {%- endif -%}
164
+ {%- set ns.prev_message_type = None -%}
165
+ {%- if 'content' in message and message['content'] is not none -%}
166
+ {%- if message['content'] is string -%}
167
+ {{ message['content'] | trim }}
168
+ {%- elif message['content'] is sequence -%}
169
+ {%- for item in message['content'] -%}
170
+ {%- if item['type'] == 'image' -%}
171
+ {{ '<start_of_image>' }}
172
+ {%- elif item['type'] == 'text' -%}
173
+ {{ item['text'] | trim }}
174
+ {%- endif -%}
175
+ {%- endfor -%}
176
+ {%- else -%}
177
+ {{ raise_exception("Invalid content type in user/assistant message") }}
178
+ {%- endif -%}
179
+ {%- set ns.prev_message_type = 'content' -%}
180
+ {%- endif -%}
181
+ {%- if 'tool_calls' in message and message['tool_calls'] and message['tool_calls'] is iterable -%}
182
+ {#- Tool Calls -#}
183
+ {%- for tool_call in message['tool_calls'] -%}
184
+ {% set function = tool_call['function'] %}
185
+ {{- '<start_function_call>call:' + function['name'] + '{' -}}
186
+ {%- if 'arguments' in function -%}
187
+ {%- if function['arguments'] is mapping -%}
188
+ {%- set ns = namespace(found_first=false) -%}
189
+ {%- for key, value in function['arguments'] | dictsort -%}
190
+ {%- if ns.found_first %},{% endif -%}
191
+ {%- set ns.found_first = true -%}
192
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
193
+ {%- endfor -%}
194
+ {%- elif function['arguments'] is string -%}
195
+ {# This handles string-JSON, just in case #}
196
+ {{ function['arguments'] }}
197
+ {%- endif %}
198
+ {%- endif -%}
199
+ {{- '}<end_function_call>' -}}
200
+ {%- endfor -%}
201
+ {%- if loop.last -%}
202
+ {{ '<start_function_response>' }}
203
+ {%- endif -%}
204
+ {%- set ns.prev_message_type = 'tool_call' -%}
205
+ {%- endif -%}
206
+ {%- else -%}
207
+ {#- Tool Responses -#}
208
+ {%- if 'content' in message and message['content'] -%}
209
+ {%- if message['content'] is mapping -%}
210
+ {%- if 'name' in message['content'] and 'response' in message['content'] -%}
211
+ {{ '<start_function_response>response:' + message['content']['name'] | trim + '{' }}
212
+ {%- set response_ns = namespace(found_first=false) -%}
213
+ {%- for key, value in message['content']['response'] | dictsort -%}
214
+ {%- if response_ns.found_first %},{% endif -%}
215
+ {%- set response_ns.found_first = true -%}
216
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
217
+ {%- endfor -%}
218
+ {{- '}<end_function_response>' -}}
219
+ {%- elif 'name' in message -%}
220
+ {{ '<start_function_response>response:' + message['name'] | trim + '{' }}
221
+ {%- set response_ns = namespace(found_first=false) -%}
222
+ {%- for key, value in message['content'] | dictsort -%}
223
+ {%- if response_ns.found_first %},{% endif -%}
224
+ {%- set response_ns.found_first = true -%}
225
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
226
+ {%- endfor -%}
227
+ {{- '}<end_function_response>' -}}
228
+ {%- else -%}
229
+ {{ raise_exception("Invalid tool response mapping: must contain 'name' and 'response' keys, or 'name' must be in the message.") }}
230
+ {%- endif -%}
231
+ {%- elif message['content'] is string -%}
232
+ {%- if 'name' in message -%}
233
+ {{ '<start_function_response>response:' + message['name'] | trim + '{value:' + format_argument(message['content'], escape_keys=False) + '}<end_function_response>' }}
234
+ {%- else -%}
235
+ {{ raise_exception("Invalid tool response: 'name' must be provided.") }}
236
+ {%- endif -%}
237
+ {%- elif message['content'] is sequence -%}
238
+ {%- for item in message['content'] -%}
239
+ {%- if item is mapping -%}
240
+ {%- if 'name' in item and 'response' in item -%}
241
+ {{ '<start_function_response>response:' + item['name'] | trim + '{' }}
242
+ {%- set response_ns = namespace(found_first=false) -%}
243
+ {%- for key, value in item['response'] | dictsort -%}
244
+ {%- if response_ns.found_first %},{% endif -%}
245
+ {%- set response_ns.found_first = true -%}
246
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
247
+ {%- endfor -%}
248
+ {{- '}<end_function_response>' -}}
249
+ {%- elif 'name' in message -%}
250
+ {{ '<start_function_response>response:' + message['name'] | trim + '{' }}
251
+ {%- set response_ns = namespace(found_first=false) -%}
252
+ {%- for key, value in item | dictsort -%}
253
+ {%- if response_ns.found_first %},{% endif -%}
254
+ {%- set response_ns.found_first = true -%}
255
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
256
+ {%- endfor -%}
257
+ {{- '}<end_function_response>' -}}
258
+ {%- else -%}
259
+ {{ raise_exception("Invalid tool response mapping: must contain 'name' and 'response' keys, or 'name' must be in the message.") }}
260
+ {%- endif -%}
261
+ {%- else -%}
262
+ {{ raise_exception("Invalid tool response message: multiple responses must all be mappings") }}
263
+ {%- endif -%}
264
+ {%- endfor -%}
265
+ {%- else -%}
266
+ {{ raise_exception("Invalid content type in tool message: must be mapping, sequence of mappings, or string.") }}
267
+ {%- endif -%}
268
+ {%- endif -%}
269
+ {%- set ns.prev_message_type = 'tool_response' -%}
270
+ {%- endif -%}
271
+ {%- if ns.prev_message_type not in ['tool_call', 'tool_response'] -%}
272
+ {{ '<end_of_turn>\n' }}
273
+ {%- endif -%}
274
+ {%- endfor -%}
275
+ {%- if add_generation_prompt -%}
276
+ {%- if ns.prev_message_type != 'tool_response' -%}
277
+ {{- '<start_of_turn>model\n' -}}
278
+ {%- endif -%}
279
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_sliding_window_pattern": 6,
3
+ "architectures": [
4
+ "Gemma3ForCausalLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "attn_logit_softcapping": null,
9
+ "bos_token_id": 2,
10
+ "dtype": "float32",
11
+ "eos_token_id": 1,
12
+ "final_logit_softcapping": null,
13
+ "head_dim": 256,
14
+ "hidden_activation": "gelu_pytorch_tanh",
15
+ "hidden_size": 640,
16
+ "initializer_range": 0.02,
17
+ "intermediate_size": 2048,
18
+ "layer_types": [
19
+ "sliding_attention",
20
+ "sliding_attention",
21
+ "sliding_attention",
22
+ "sliding_attention",
23
+ "sliding_attention",
24
+ "full_attention",
25
+ "sliding_attention",
26
+ "sliding_attention",
27
+ "sliding_attention",
28
+ "sliding_attention",
29
+ "sliding_attention",
30
+ "full_attention",
31
+ "sliding_attention",
32
+ "sliding_attention",
33
+ "sliding_attention",
34
+ "sliding_attention",
35
+ "sliding_attention",
36
+ "full_attention"
37
+ ],
38
+ "max_position_embeddings": 32768,
39
+ "model_type": "gemma3_text",
40
+ "num_attention_heads": 4,
41
+ "num_hidden_layers": 18,
42
+ "num_key_value_heads": 1,
43
+ "pad_token_id": 0,
44
+ "query_pre_attn_scalar": 256,
45
+ "rms_norm_eps": 1e-06,
46
+ "rope_local_base_freq": 10000.0,
47
+ "rope_scaling": null,
48
+ "rope_theta": 1000000.0,
49
+ "sliding_window": 512,
50
+ "transformers_version": "4.57.6",
51
+ "use_bidirectional_attention": false,
52
+ "use_cache": false,
53
+ "vocab_size": 262144
54
+ }
generation_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 2,
3
+ "cache_implementation": "hybrid",
4
+ "do_sample": true,
5
+ "eos_token_id": [
6
+ 1,
7
+ 1,
8
+ 50,
9
+ 106
10
+ ],
11
+ "pad_token_id": 0,
12
+ "top_k": 64,
13
+ "top_p": 0.95,
14
+ "transformers_version": "4.57.6"
15
+ }
model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8dd65ffb9408225f5d3b509bc527268746505f8283920df2c3d20422334ae660
3
+ size 437499316
special_tokens_map.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "boi_token": "<start_of_image>",
3
+ "bos_token": {
4
+ "content": "<bos>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false
9
+ },
10
+ "eoi_token": "<end_of_image>",
11
+ "eos_token": {
12
+ "content": "<eos>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false
17
+ },
18
+ "image_token": "<image_soft_token>",
19
+ "pad_token": {
20
+ "content": "<pad>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false
25
+ },
26
+ "sfr_token": "<start_function_response>",
27
+ "unk_token": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false
33
+ }
34
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b6b09a0b4a803ad453063ca4bb49a784540e8120004e2450e025df2b27d41fb2
3
+ size 33384899
tokenizer_config.json ADDED
The diff for this file is too large to render. See raw diff