dancinlife commited on
Commit
0200469
·
verified ·
1 Parent(s): 328d74f

Add MLX-4bit (weights + SEO card)

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,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: gemma
3
+ license_link: https://ai.google.dev/gemma/terms
4
+ library_name: mlx
5
+ pipeline_tag: text-generation
6
+ base_model: Jiunsong/supergemma4-e4b-abliterated
7
+ base_model_relation: quantized
8
+ language:
9
+ - en
10
+ - ko
11
+ tags:
12
+ - gemma
13
+ - gemma-4
14
+ - gemma4
15
+ - abliterated
16
+ - uncensored
17
+ - uncensored-llm
18
+ - no-refusal
19
+ - mlx
20
+ - apple-silicon
21
+ - m-series
22
+ - mac
23
+ - quantized
24
+ - conversational
25
+ - roleplay
26
+ - text-generation
27
+ quantized_by: dancinlab
28
+ inference: false
29
+ ---
30
+
31
+ # Uncensored Gemma 4 (SuperGemma4 E4B Abliterated) — MLX for Apple Silicon
32
+
33
+ **Uncensored / abliterated Gemma-4** for Apple Silicon — MLX builds that
34
+ **actually load on stock `mlx-lm`**. Most community MLX uploads of this base
35
+ fail with `Missing 963 parameters`; this repo's conversion fixes both root
36
+ causes so it loads and generates on a clean `pip install mlx-lm`.
37
+
38
+ ```bash
39
+ pip install -U mlx-lm # needs mlx-lm >= 0.31.3 (native gemma4 arch)
40
+
41
+ # 4-bit — recommended for 16 GB / 24 GB Macs
42
+ mlx_lm.generate --model dancinlab/supergemma4-e4b-abliterated-MLX-4bit \
43
+ --prompt "안녕? 너는 누구야?" --max-tokens 60
44
+
45
+ # interactive chat
46
+ mlx_lm.chat --model dancinlab/supergemma4-e4b-abliterated-MLX-4bit
47
+ ```
48
+
49
+ ## Builds (3 separate repos)
50
+
51
+ | Repo | Size | Peak RAM | tok/s (M-series) | Use |
52
+ |---|---:|---:|---:|---|
53
+ | **`-MLX-4bit`** | 3.9 GB | 5.4 GB | ~11 | **recommended** — 16 GB / 24 GB Mac |
54
+ | `-MLX-8bit` | 7.4 GB | 9.1 GB | ~6 | 32 GB+ Mac, higher fidelity |
55
+ | `-MLX-bf16` | 14 GB | 8.6 GB | ~3 | reference, full precision |
56
+
57
+ Verified: both `안녕? 너는 누구야?` (coherent Korean) and `2+2=` (→ 4) on
58
+ stock `mlx-lm==0.31.3`. **Text-only** — the upstream abliterated safetensors
59
+ contain no vision/audio tower weights, so multimodal MLX is upstream-blocked,
60
+ not a tooling limitation.
61
+
62
+ ## Why community MLX builds fail (and how this one is fixed)
63
+
64
+ `Gemma4ForConditionalGeneration` is multimodal (text + vision + audio). Two
65
+ independent problems break naive conversion:
66
+
67
+ 1. **963-tensor multimodal/text mismatch.** `mlx-vlm` always instantiates all
68
+ three towers (1682 tensors); the abliterated text-only release has 719
69
+ (missing = audio 751 + vision 210 + embed 2). **Fixed by stock code** —
70
+ `mlx-lm >= 0.31.3` ships a native `gemma4`/`gemma4_text` arch whose
71
+ `sanitize` strips vision/audio/embed and remaps `model.language_model.*`.
72
+ No patch needed for this part.
73
+
74
+ 2. **54-tensor KV-shared residue.** Gemma-4 e4b shares K/V across the last 18
75
+ layers (24–41), but the upstream safetensors physically still carry the
76
+ dropped `k_proj`/`v_proj`/`k_norm` for those layers → strict-load failure.
77
+ This fix landed on `mlx-lm` `main` **after** the 0.31.3 tag
78
+ (`ml-explore/mlx-lm#1240`), so it is **not in any pip release yet**. This
79
+ repo applies the #1240 `sanitize` logic as a **convert-time monkey-patch**
80
+ (no mlx-lm / mlx-vlm / transformers fork). Effect: 719 → 665 tensors
81
+ (exactly 54 stripped).
82
+
83
+ The patch is needed **only at conversion time**. The shipped weights here
84
+ load on plain stock `mlx-lm>=0.31.3` with no patch on your side — that is the
85
+ gap that makes other MLX uploads of this model unusable.
86
+
87
+ > Note: `mlx-lm` 0.29.1 (common on Python 3.9) has **no gemma4 arch at all** —
88
+ > you need 0.31.3+. On Python 3.9 mlx wheels cap at 0.29.3, so use a
89
+ > Python 3.11+/3.13 environment.
90
+
91
+ ## Why abliterated
92
+
93
+ Upstream `Jiunsong/supergemma4-e4b-abliterated` removes refusal directions
94
+ from the residual stream of `google/gemma-4-E4B-it`. Upstream release-card
95
+ numbers (vs Google base):
96
+
97
+ | Metric | Google base | SuperGemma4 E4B Abliterated |
98
+ |---|---:|---:|
99
+ | Release quality | 77.46 | 92.34 |
100
+ | Exact overall | 83.50 | 98.50 |
101
+ | JSON exact | 50.0 | 100.0 |
102
+
103
+ Source: [`Jiunsong/supergemma4-e4b-abliterated`](https://huggingface.co/Jiunsong/supergemma4-e4b-abliterated) model card.
104
+
105
+ ## What "abliterated" means and doesn't mean
106
+
107
+ - **Does:** reduces reflexive refusals; answers borderline-but-legal requests directly.
108
+ - **Does not:** remove confabulation; alter base knowledge / biases; replace
109
+ your own safety layer at the application boundary.
110
+
111
+ ## License — Gemma Terms of Use (must read)
112
+
113
+ Derivative of `google/gemma-4-E4B-it`, governed by the **Gemma Terms of Use**
114
+ (`license: gemma`):
115
+
116
+ - License: https://ai.google.dev/gemma/terms
117
+ - Prohibited use policy: https://ai.google.dev/gemma/prohibited_use_policy
118
+
119
+ By downloading or using these MLX builds you agree to the Gemma Terms of Use
120
+ and Prohibited Use Policy. Redistribution must include the same license terms.
121
+
122
+ ## Lineage
123
+
124
+ ```
125
+ google/gemma-4-E4B-it
126
+ └── Jiunsong/supergemma4-e4b-abliterated (abliteration + tuning)
127
+ └── dancinlab/supergemma4-e4b-abliterated-MLX-{bf16,4bit,8bit}
128
+ ```
129
+
130
+ Conversion: stock `mlx-lm==0.31.3` on Apple Silicon + a convert-time
131
+ `gemma4_text.sanitize` monkey-patch (verbatim `ml-explore/mlx-lm#1240`).
132
+ No mlx-lm / mlx-vlm / transformers fork.
133
+
134
+ ## Credits
135
+
136
+ - Upstream model: [`Jiunsong`](https://huggingface.co/Jiunsong)
137
+ - Original base: [`google/gemma-4-E4B-it`](https://huggingface.co/google/gemma-4-E4B-it)
138
+ - MLX conversion + packaging: [`dancinlab`](https://huggingface.co/dancinlab)
139
+
140
+ Everywhere else (llama.cpp / Ollama / LM Studio): [`dancinlab/supergemma4-e4b-abliterated-GGUF`](https://huggingface.co/dancinlab/supergemma4-e4b-abliterated-GGUF) — Q2_K → BF16 + imatrix IQ.
141
+
142
+ Collection: [`dancinlab/uncensored`](https://huggingface.co/collections/dancinlab/uncensored-6a080743e6774450ba77a427).
chat_template.jinja ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ {%- set add_comma = false -%}
6
+ {%- if 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([])) -}}
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
+ {%- set default_response_contract -%}
178
+ You are a precise coding assistant.
179
+ - When the user asks for raw JSON or a JSON tool call, return raw JSON only with no markdown fences or commentary.
180
+ - When the user asks for code only, return concise runnable code only with no explanation or docstring unless explicitly requested.
181
+ - Prefer the shortest valid answer that satisfies the requested schema or signature.
182
+ {%- endset -%}
183
+ {{- bos_token -}}
184
+ {#- Handle System/Tool Definitions Block -#}
185
+ {%- if true -%}
186
+ {{- '<|turn>system\n' -}}
187
+
188
+ {#- Inject Thinking token at the very top of the FIRST system turn -#}
189
+ {%- if enable_thinking is defined and enable_thinking -%}
190
+ {{- '<|think|>\n' -}}
191
+ {%- set ns.prev_message_type = 'think' -%}
192
+ {%- endif -%}
193
+
194
+ {{- default_response_contract | trim -}}
195
+ {%- if messages[0]['role'] in ['system', 'developer'] -%}
196
+ {{- '\n\n' -}}
197
+ {{- messages[0]['content'] | trim -}}
198
+ {%- set loop_messages = messages[1:] -%}
199
+ {%- endif -%}
200
+
201
+ {%- if tools -%}
202
+ {%- for tool in tools %}
203
+ {{- '<|tool>' -}}
204
+ {{- format_function_declaration(tool) | trim -}}
205
+ {{- '<tool|>' -}}
206
+ {%- endfor %}
207
+ {%- set ns.prev_message_type = 'tool' -%}
208
+ {%- endif -%}
209
+
210
+ {{- '<turn|>\n' -}}
211
+ {%- endif %}
212
+
213
+ {#- Pre-scan: find last user message index for reasoning guard -#}
214
+ {%- set ns_turn = namespace(last_user_idx=-1) -%}
215
+ {%- for i in range(loop_messages | length) -%}
216
+ {%- if loop_messages[i]['role'] == 'user' -%}
217
+ {%- set ns_turn.last_user_idx = i -%}
218
+ {%- endif -%}
219
+ {%- endfor -%}
220
+
221
+ {#- Loop through messages -#}
222
+ {%- for message in loop_messages -%}
223
+ {%- if message['role'] != 'tool' -%}
224
+ {%- set ns.prev_message_type = None -%}
225
+ {%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}
226
+ {#- Detect continuation: suppress duplicate <|turn>model when previous non-tool message was also assistant -#}
227
+ {%- set prev_nt = namespace(role=None, found=false) -%}
228
+ {%- if loop.index0 > 0 -%}
229
+ {%- for j in range(loop.index0 - 1, -1, -1) -%}
230
+ {%- if not prev_nt.found -%}
231
+ {%- if loop_messages[j]['role'] != 'tool' -%}
232
+ {%- set prev_nt.role = loop_messages[j]['role'] -%}
233
+ {%- set prev_nt.found = true -%}
234
+ {%- endif -%}
235
+ {%- endif -%}
236
+ {%- endfor -%}
237
+ {%- endif -%}
238
+ {%- set continue_same_model_turn = (role == 'model' and prev_nt.role == 'assistant') -%}
239
+ {%- if not continue_same_model_turn -%}
240
+ {{- '<|turn>' + role + '\n' }}
241
+ {%- endif -%}
242
+
243
+ {#- Render reasoning/reasoning_content as thinking channel -#}
244
+ {%- set thinking_text = message.get('reasoning') or message.get('reasoning_content') -%}
245
+ {%- if thinking_text and loop.index0 > ns_turn.last_user_idx and message.get('tool_calls') -%}
246
+ {{- '<|channel>thought\n' + thinking_text + '\n<channel|>' -}}
247
+ {%- endif -%}
248
+
249
+ {%- if message['tool_calls'] -%}
250
+ {%- for tool_call in message['tool_calls'] -%}
251
+ {%- set function = tool_call['function'] -%}
252
+ {{- '<|tool_call>call:' + function['name'] + '{' -}}
253
+ {%- if function['arguments'] is mapping -%}
254
+ {%- set ns_args = namespace(found_first=false) -%}
255
+ {%- for key, value in function['arguments'] | dictsort -%}
256
+ {%- if ns_args.found_first %},{% endif -%}
257
+ {%- set ns_args.found_first = true -%}
258
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
259
+ {%- endfor -%}
260
+ {%- elif function['arguments'] is string -%}
261
+ {{- function['arguments'] -}}
262
+ {%- endif -%}
263
+ {{- '}<tool_call|>' -}}
264
+ {%- endfor -%}
265
+ {%- set ns.prev_message_type = 'tool_call' -%}
266
+ {%- endif -%}
267
+
268
+ {%- set ns_tr_out = namespace(flag=false) -%}
269
+ {%- if message.get('tool_responses') -%}
270
+ {#- Legacy: tool_responses embedded on the assistant message (Google/Gemma native) -#}
271
+ {%- for tool_response in message['tool_responses'] -%}
272
+ {{- format_tool_response_block(tool_response['name'] | default('unknown'), tool_response['response']) -}}
273
+ {%- set ns_tr_out.flag = true -%}
274
+ {%- set ns.prev_message_type = 'tool_response' -%}
275
+ {%- endfor -%}
276
+ {%- elif message.get('tool_calls') -%}
277
+ {#- OpenAI Chat Completions: forward-scan consecutive role:tool messages -#}
278
+ {%- set ns_tool_scan = namespace(stopped=false) -%}
279
+ {%- for k in range(loop.index0 + 1, loop_messages | length) -%}
280
+ {%- if ns_tool_scan.stopped -%}
281
+ {%- elif loop_messages[k]['role'] != 'tool' -%}
282
+ {%- set ns_tool_scan.stopped = true -%}
283
+ {%- else -%}
284
+ {%- set follow = loop_messages[k] -%}
285
+ {#- Resolve tool_call_id to function name -#}
286
+ {%- set ns_tname = namespace(name=follow.get('name') | default('unknown')) -%}
287
+ {%- for tc in message['tool_calls'] -%}
288
+ {%- if tc.get('id') == follow.get('tool_call_id') -%}
289
+ {%- set ns_tname.name = tc['function']['name'] -%}
290
+ {%- endif -%}
291
+ {%- endfor -%}
292
+ {#- Handle content as string or content-parts array -#}
293
+ {%- set tool_body = follow.get('content') -%}
294
+ {%- if tool_body is string -%}
295
+ {{- format_tool_response_block(ns_tname.name, tool_body) -}}
296
+ {%- elif tool_body is sequence and tool_body is not string -%}
297
+ {%- set ns_txt = namespace(s='') -%}
298
+ {%- for part in tool_body -%}
299
+ {%- if part.get('type') == 'text' -%}
300
+ {%- set ns_txt.s = ns_txt.s + (part.get('text') | default('')) -%}
301
+ {%- endif -%}
302
+ {%- endfor -%}
303
+ {{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
304
+ {%- else -%}
305
+ {{- format_tool_response_block(ns_tname.name, tool_body) -}}
306
+ {%- endif -%}
307
+ {%- set ns_tr_out.flag = true -%}
308
+ {%- set ns.prev_message_type = 'tool_response' -%}
309
+ {%- endif -%}
310
+ {%- endfor -%}
311
+ {%- endif -%}
312
+
313
+ {%- if message['content'] is string -%}
314
+ {%- if role == 'model' -%}
315
+ {{- strip_thinking(message['content']) -}}
316
+ {%- else -%}
317
+ {{- message['content'] | trim -}}
318
+ {%- endif -%}
319
+ {%- elif message['content'] is sequence -%}
320
+ {%- for item in message['content'] -%}
321
+ {%- if item['type'] == 'text' -%}
322
+ {%- if role == 'model' -%}
323
+ {{- strip_thinking(item['text']) -}}
324
+ {%- else -%}
325
+ {{- item['text'] | trim -}}
326
+ {%- endif -%}
327
+ {%- elif item['type'] == 'image' -%}
328
+ {{- '<|image|>' -}}
329
+ {%- set ns.prev_message_type = 'image' -%}
330
+ {%- elif item['type'] == 'audio' -%}
331
+ {{- '<|audio|>' -}}
332
+ {%- set ns.prev_message_type = 'audio' -%}
333
+ {%- elif item['type'] == 'video' -%}
334
+ {{- '<|video|>' -}}
335
+ {%- set ns.prev_message_type = 'video' -%}
336
+ {%- endif -%}
337
+ {%- endfor -%}
338
+ {%- endif -%}
339
+
340
+ {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
341
+ {{- '<|tool_response>' -}}
342
+ {%- elif not (ns_tr_out.flag and not message.get('content')) -%}
343
+ {{- '<turn|>\n' -}}
344
+ {%- endif -%}
345
+ {%- endif -%}
346
+ {%- endfor -%}
347
+
348
+ {%- if add_generation_prompt -%}
349
+ {%- if ns.prev_message_type != 'tool_response' and ns.prev_message_type != 'tool_call' -%}
350
+ {{- '<|turn>model\n' -}}
351
+ {%- endif -%}
352
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Gemma4ForConditionalGeneration"
4
+ ],
5
+ "audio_config": {
6
+ "_name_or_path": "",
7
+ "architectures": null,
8
+ "attention_chunk_size": 12,
9
+ "attention_context_left": 13,
10
+ "attention_context_right": 0,
11
+ "attention_invalid_logits_value": -1000000000.0,
12
+ "attention_logit_cap": 50.0,
13
+ "chunk_size_feed_forward": 0,
14
+ "conv_kernel_size": 5,
15
+ "dtype": "bfloat16",
16
+ "gradient_clipping": 10000000000.0,
17
+ "hidden_act": "silu",
18
+ "hidden_size": 1024,
19
+ "id2label": {
20
+ "0": "LABEL_0",
21
+ "1": "LABEL_1"
22
+ },
23
+ "initializer_range": 0.02,
24
+ "is_encoder_decoder": false,
25
+ "label2id": {
26
+ "LABEL_0": 0,
27
+ "LABEL_1": 1
28
+ },
29
+ "model_type": "gemma4_audio",
30
+ "num_attention_heads": 8,
31
+ "num_hidden_layers": 12,
32
+ "output_attentions": false,
33
+ "output_hidden_states": false,
34
+ "output_proj_dims": 1536,
35
+ "problem_type": null,
36
+ "residual_weight": 0.5,
37
+ "return_dict": true,
38
+ "rms_norm_eps": 1e-06,
39
+ "subsampling_conv_channels": [
40
+ 128,
41
+ 32
42
+ ],
43
+ "use_clipped_linears": true
44
+ },
45
+ "audio_token_id": 258881,
46
+ "boa_token_id": 256000,
47
+ "boi_token_id": 255999,
48
+ "dtype": "bfloat16",
49
+ "eoa_token_id": 258883,
50
+ "eoa_token_index": 258883,
51
+ "eoi_token_id": 258882,
52
+ "eos_token_id": [
53
+ 1,
54
+ 106,
55
+ 50
56
+ ],
57
+ "image_token_id": 258880,
58
+ "initializer_range": 0.02,
59
+ "model_type": "gemma4",
60
+ "quantization": {
61
+ "group_size": 64,
62
+ "bits": 4,
63
+ "mode": "affine"
64
+ },
65
+ "quantization_config": {
66
+ "group_size": 64,
67
+ "bits": 4,
68
+ "mode": "affine"
69
+ },
70
+ "text_config": {
71
+ "attention_bias": false,
72
+ "attention_dropout": 0.0,
73
+ "attention_k_eq_v": false,
74
+ "bos_token_id": 2,
75
+ "dtype": "bfloat16",
76
+ "enable_moe_block": false,
77
+ "eos_token_id": 1,
78
+ "expert_intermediate_size": null,
79
+ "final_logit_softcapping": 30.0,
80
+ "global_head_dim": 512,
81
+ "head_dim": 256,
82
+ "hidden_activation": "gelu_pytorch_tanh",
83
+ "hidden_size": 2560,
84
+ "hidden_size_per_layer_input": 256,
85
+ "initializer_range": 0.02,
86
+ "intermediate_size": 10240,
87
+ "layer_types": [
88
+ "sliding_attention",
89
+ "sliding_attention",
90
+ "sliding_attention",
91
+ "sliding_attention",
92
+ "sliding_attention",
93
+ "full_attention",
94
+ "sliding_attention",
95
+ "sliding_attention",
96
+ "sliding_attention",
97
+ "sliding_attention",
98
+ "sliding_attention",
99
+ "full_attention",
100
+ "sliding_attention",
101
+ "sliding_attention",
102
+ "sliding_attention",
103
+ "sliding_attention",
104
+ "sliding_attention",
105
+ "full_attention",
106
+ "sliding_attention",
107
+ "sliding_attention",
108
+ "sliding_attention",
109
+ "sliding_attention",
110
+ "sliding_attention",
111
+ "full_attention",
112
+ "sliding_attention",
113
+ "sliding_attention",
114
+ "sliding_attention",
115
+ "sliding_attention",
116
+ "sliding_attention",
117
+ "full_attention",
118
+ "sliding_attention",
119
+ "sliding_attention",
120
+ "sliding_attention",
121
+ "sliding_attention",
122
+ "sliding_attention",
123
+ "full_attention",
124
+ "sliding_attention",
125
+ "sliding_attention",
126
+ "sliding_attention",
127
+ "sliding_attention",
128
+ "sliding_attention",
129
+ "full_attention"
130
+ ],
131
+ "max_position_embeddings": 131072,
132
+ "model_type": "gemma4_text",
133
+ "num_attention_heads": 8,
134
+ "num_experts": null,
135
+ "num_global_key_value_heads": null,
136
+ "num_hidden_layers": 42,
137
+ "num_key_value_heads": 2,
138
+ "num_kv_shared_layers": 18,
139
+ "pad_token_id": 0,
140
+ "rms_norm_eps": 1e-06,
141
+ "rope_parameters": {
142
+ "full_attention": {
143
+ "partial_rotary_factor": 0.25,
144
+ "rope_theta": 1000000.0,
145
+ "rope_type": "proportional"
146
+ },
147
+ "sliding_attention": {
148
+ "rope_theta": 10000.0,
149
+ "rope_type": "default"
150
+ }
151
+ },
152
+ "sliding_window": 512,
153
+ "tie_word_embeddings": true,
154
+ "top_k_experts": null,
155
+ "use_bidirectional_attention": null,
156
+ "use_cache": true,
157
+ "use_double_wide_mlp": false,
158
+ "vocab_size": 262144,
159
+ "vocab_size_per_layer_input": 262144
160
+ },
161
+ "tie_word_embeddings": true,
162
+ "transformers_version": "5.5.0.dev0",
163
+ "video_token_id": 258884,
164
+ "vision_soft_tokens_per_image": 280
165
+ }
generation_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 2,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 1,
6
+ 106,
7
+ 50
8
+ ],
9
+ "pad_token_id": 0,
10
+ "temperature": 1.0,
11
+ "top_k": 64,
12
+ "top_p": 0.95,
13
+ "transformers_version": "5.5.0.dev0"
14
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:990227d544b52fb21811a42b9d697f54e361752b8beb140c8c7d16a36bfc5ecd
3
+ size 4198925877
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cc8d3a0ce36466ccc1278bf987df5f71db1719b9ca6b4118264f45cb627bfe0f
3
+ size 32169626
tokenizer_config.json ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": true,
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<content>(?:(?!\\<\\|tool_call\\>)(?!\\<turn\\|\\>).)+)?(?P<tool_calls>\\<\\|tool_call\\>.*\\<tool_call\\|\\>)?(?:\\<turn\\|\\>)?"
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
+ "tool_parser_type": "gemma4",
96
+ "unk_token": "<unk>"
97
+ }