yujiepan commited on
Commit
9e03cdd
·
verified ·
1 Parent(s): dba39e7

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
.meta.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "source_model": {
3
+ "name": "google/diffusiongemma-26B-A4B-it",
4
+ "commit_id": "f7f5b7f5fa82ffc52addd066915886d497f5517b"
5
+ },
6
+ "env": {
7
+ "python": "3.12.13",
8
+ "packages": {
9
+ "Pillow": "13.0.0",
10
+ "huggingface_hub": "2.3.0",
11
+ "numpy": "2.3.5",
12
+ "safetensors": "0.8.0",
13
+ "tokenizers": "0.23.3",
14
+ "torch": "2.13.0",
15
+ "transformers": "5.19.0"
16
+ },
17
+ "cuda": "13.0"
18
+ }
19
+ }
README.md ADDED
@@ -0,0 +1,463 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ base_model:
4
+ - google/diffusiongemma-26B-A4B-it
5
+ ---
6
+
7
+ This tiny model is intended for debugging. It is randomly initialized using the configuration adapted from [google/diffusiongemma-26B-A4B-it](https://huggingface.co/google/diffusiongemma-26B-A4B-it).
8
+
9
+ Structural comparison with `google/diffusiongemma-26B-A4B-it`:
10
+
11
+ | Feature | Source | Tiny |
12
+ |---|---:|---:|
13
+ | Input modalities | text, image, video | same |
14
+ | Vocabulary / tied embeddings | 262,144 / yes | same |
15
+ | Text layers | 30 | 12; two 5-sliding + 1-full cycles |
16
+ | Text width / local head dimension | 2,816 / 256 | 16 / 32 |
17
+ | Full-attention head dimension | 512 | 64 |
18
+ | MoE experts / active experts | 128 / 8 | 32 / 8 |
19
+ | Vision layers / width | 27 / 1,152 | 2 / 64 |
20
+ | Canvas length and self-conditioning | 256 / present | same |
21
+ | Stored precision | BF16 | BF16 |
22
+
23
+ The encoder/decoder weight sharing and the decoder self-conditioning branch are
24
+ provided by the native `DiffusionGemmaForBlockDiffusion` implementation rather
25
+ than serialized as independent copies.
26
+
27
+ | File path | Size |
28
+ |------|------|
29
+ | model.safetensors | 12.6MB |
30
+
31
+
32
+ ### Example usage:
33
+
34
+ - Transformers (✅ verified)
35
+
36
+ ```python
37
+ import numpy as np
38
+ import torch
39
+ from PIL import Image
40
+ from transformers import AutoProcessor, DiffusionGemmaForBlockDiffusion
41
+ from transformers.video_utils import VideoMetadata
42
+
43
+ model_id = "tiny-random/diffusiongemma-moe"
44
+ device = "cuda" if torch.cuda.is_available() else "cpu"
45
+ dtype = torch.bfloat16 if device == "cuda" else torch.float32
46
+ model = DiffusionGemmaForBlockDiffusion.from_pretrained(model_id, dtype=dtype).to(device)
47
+ processor = AutoProcessor.from_pretrained(model_id)
48
+ image = Image.new("RGB", (64, 64), "red")
49
+ video = np.stack([np.asarray(Image.new("RGB", (64, 64), color)) for color in ("red", "green", "blue", "yellow")])
50
+ messages = [{"role": "user", "content": [
51
+ {"type": "image", "image": image},
52
+ {"type": "video", "video": video},
53
+ {"type": "text", "text": "Describe the image and video."},
54
+ ]}]
55
+ inputs = processor.apply_chat_template(
56
+ messages, tokenize=True, add_generation_prompt=True, return_dict=True, return_tensors="pt",
57
+ do_sample_frames=False,
58
+ video_metadata=[VideoMetadata(total_num_frames=4, fps=2, frames_indices=[0, 1, 2, 3])],
59
+ ).to(device)
60
+ output = model.generate(**inputs, max_new_tokens=10, max_denoising_steps=2)
61
+ print(processor.decode(output.sequences[0], skip_special_tokens=True)[-500:])
62
+ ```
63
+
64
+ ### Codes to create this repo (✅ verified):
65
+
66
+ <details><summary>Click to expand</summary>
67
+
68
+ ```python
69
+ import json
70
+ from pathlib import Path
71
+ from shutil import copyfile
72
+
73
+ import torch
74
+ from huggingface_hub import hf_hub_download, list_repo_files
75
+ from transformers import AutoConfig, DiffusionGemmaForBlockDiffusion, set_seed
76
+
77
+ source_model_id = "google/diffusiongemma-26B-A4B-it"
78
+ save_folder = "/tmp/tiny-random/diffusiongemma-moe"
79
+ source_revision = "f7f5b7f5fa82ffc52addd066915886d497f5517b"
80
+ set_seed(42)
81
+ folder = Path(save_folder)
82
+ folder.mkdir(parents=True, exist_ok=True)
83
+ raw = json.loads(Path(hf_hub_download(source_model_id, "config.json", revision=source_revision)).read_text())
84
+ text = raw["text_config"]
85
+ text.update(
86
+ hidden_size=16, head_dim=32, num_attention_heads=1, num_key_value_heads=1,
87
+ intermediate_size=64, moe_intermediate_size=32, num_experts=32, top_k_experts=8,
88
+ num_hidden_layers=12,
89
+ layer_types=["sliding_attention"] * 5 + ["full_attention"] + ["sliding_attention"] * 5 + ["full_attention"],
90
+ per_layer_config={"5": {"head_dim": 64, "num_key_value_heads": 1}, "11": {"head_dim": 64, "num_key_value_heads": 1}},
91
+ )
92
+ raw["vision_config"].update(
93
+ hidden_size=64, intermediate_size=128, num_hidden_layers=2,
94
+ num_attention_heads=2, num_key_value_heads=2, head_dim=32,
95
+ )
96
+ (folder / "config.json").write_text(json.dumps(raw, indent=2), encoding="utf-8")
97
+ config = AutoConfig.from_pretrained(folder)
98
+ model = DiffusionGemmaForBlockDiffusion(config).to(torch.bfloat16)
99
+ with torch.no_grad():
100
+ for name, parameter in sorted(model.named_parameters()):
101
+ if not parameter.is_floating_point():
102
+ continue
103
+ if name.endswith("norm.weight"):
104
+ parameter.fill_(1)
105
+ else:
106
+ torch.nn.init.normal_(parameter, mean=0, std=0.02)
107
+ model.save_pretrained(folder, safe_serialization=True)
108
+ assets = {"chat_template.jinja", "generation_config.json", "model_index.json", "processor_config.json", "scheduler/scheduler_config.json", "tokenizer.json", "tokenizer_config.json"}
109
+ for filename in sorted(set(list_repo_files(source_model_id, revision=source_revision)) & assets):
110
+ destination = folder / filename
111
+ destination.parent.mkdir(parents=True, exist_ok=True)
112
+ copyfile(hf_hub_download(source_model_id, filename, revision=source_revision), destination)
113
+ ```
114
+
115
+ </details>
116
+
117
+ ### Printing the model:
118
+
119
+ <details><summary>Click to expand</summary>
120
+
121
+ ```text
122
+ DiffusionGemmaForBlockDiffusion(
123
+ (model): DiffusionGemmaModel(
124
+ (encoder): DiffusionGemmaEncoderModel(
125
+ (language_model): DiffusionGemmaEncoderTextModel(
126
+ (embed_tokens): DiffusionGemmaTextScaledWordEmbedding(262144, 16, padding_idx=0)
127
+ (layers): ModuleList(
128
+ (0-4): 5 x DiffusionGemmaEncoderTextLayer(
129
+ (self_attn): DiffusionGemmaEncoderTextAttention(
130
+ (q_proj): Linear(in_features=16, out_features=32, bias=False)
131
+ (k_proj): Linear(in_features=16, out_features=32, bias=False)
132
+ (v_proj): Linear(in_features=16, out_features=32, bias=False)
133
+ (o_proj): Linear(in_features=32, out_features=16, bias=False)
134
+ (q_norm): DiffusionGemmaRMSNorm()
135
+ (k_norm): DiffusionGemmaRMSNorm()
136
+ (v_norm): DiffusionGemmaRMSNorm()
137
+ )
138
+ (mlp): DiffusionGemmaText4MLP(
139
+ (gate_proj): Linear(in_features=16, out_features=64, bias=False)
140
+ (up_proj): Linear(in_features=16, out_features=64, bias=False)
141
+ (down_proj): Linear(in_features=64, out_features=16, bias=False)
142
+ (act_fn): GELUTanh()
143
+ )
144
+ (input_layernorm): DiffusionGemmaRMSNorm()
145
+ (post_attention_layernorm): DiffusionGemmaRMSNorm()
146
+ (pre_feedforward_layernorm): DiffusionGemmaRMSNorm()
147
+ (post_feedforward_layernorm): DiffusionGemmaRMSNorm()
148
+ (router): DiffusionGemmaTextRouter(
149
+ (norm): DiffusionGemmaRMSNorm()
150
+ (proj): Linear(in_features=16, out_features=32, bias=False)
151
+ )
152
+ (experts): DiffusionGemmaTextExperts(
153
+ (act_fn): GELUTanh()
154
+ )
155
+ (post_feedforward_layernorm_1): DiffusionGemmaRMSNorm()
156
+ (post_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
157
+ (pre_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
158
+ )
159
+ (5): DiffusionGemmaEncoderTextLayer(
160
+ (self_attn): DiffusionGemmaEncoderTextAttention(
161
+ (q_proj): Linear(in_features=16, out_features=64, bias=False)
162
+ (k_proj): Linear(in_features=16, out_features=64, bias=False)
163
+ (o_proj): Linear(in_features=64, out_features=16, bias=False)
164
+ (q_norm): DiffusionGemmaRMSNorm()
165
+ (k_norm): DiffusionGemmaRMSNorm()
166
+ (v_norm): DiffusionGemmaRMSNorm()
167
+ )
168
+ (mlp): DiffusionGemmaText4MLP(
169
+ (gate_proj): Linear(in_features=16, out_features=64, bias=False)
170
+ (up_proj): Linear(in_features=16, out_features=64, bias=False)
171
+ (down_proj): Linear(in_features=64, out_features=16, bias=False)
172
+ (act_fn): GELUTanh()
173
+ )
174
+ (input_layernorm): DiffusionGemmaRMSNorm()
175
+ (post_attention_layernorm): DiffusionGemmaRMSNorm()
176
+ (pre_feedforward_layernorm): DiffusionGemmaRMSNorm()
177
+ (post_feedforward_layernorm): DiffusionGemmaRMSNorm()
178
+ (router): DiffusionGemmaTextRouter(
179
+ (norm): DiffusionGemmaRMSNorm()
180
+ (proj): Linear(in_features=16, out_features=32, bias=False)
181
+ )
182
+ (experts): DiffusionGemmaTextExperts(
183
+ (act_fn): GELUTanh()
184
+ )
185
+ (post_feedforward_layernorm_1): DiffusionGemmaRMSNorm()
186
+ (post_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
187
+ (pre_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
188
+ )
189
+ (6-10): 5 x DiffusionGemmaEncoderTextLayer(
190
+ (self_attn): DiffusionGemmaEncoderTextAttention(
191
+ (q_proj): Linear(in_features=16, out_features=32, bias=False)
192
+ (k_proj): Linear(in_features=16, out_features=32, bias=False)
193
+ (v_proj): Linear(in_features=16, out_features=32, bias=False)
194
+ (o_proj): Linear(in_features=32, out_features=16, bias=False)
195
+ (q_norm): DiffusionGemmaRMSNorm()
196
+ (k_norm): DiffusionGemmaRMSNorm()
197
+ (v_norm): DiffusionGemmaRMSNorm()
198
+ )
199
+ (mlp): DiffusionGemmaText4MLP(
200
+ (gate_proj): Linear(in_features=16, out_features=64, bias=False)
201
+ (up_proj): Linear(in_features=16, out_features=64, bias=False)
202
+ (down_proj): Linear(in_features=64, out_features=16, bias=False)
203
+ (act_fn): GELUTanh()
204
+ )
205
+ (input_layernorm): DiffusionGemmaRMSNorm()
206
+ (post_attention_layernorm): DiffusionGemmaRMSNorm()
207
+ (pre_feedforward_layernorm): DiffusionGemmaRMSNorm()
208
+ (post_feedforward_layernorm): DiffusionGemmaRMSNorm()
209
+ (router): DiffusionGemmaTextRouter(
210
+ (norm): DiffusionGemmaRMSNorm()
211
+ (proj): Linear(in_features=16, out_features=32, bias=False)
212
+ )
213
+ (experts): DiffusionGemmaTextExperts(
214
+ (act_fn): GELUTanh()
215
+ )
216
+ (post_feedforward_layernorm_1): DiffusionGemmaRMSNorm()
217
+ (post_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
218
+ (pre_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
219
+ )
220
+ (11): DiffusionGemmaEncoderTextLayer(
221
+ (self_attn): DiffusionGemmaEncoderTextAttention(
222
+ (q_proj): Linear(in_features=16, out_features=64, bias=False)
223
+ (k_proj): Linear(in_features=16, out_features=64, bias=False)
224
+ (o_proj): Linear(in_features=64, out_features=16, bias=False)
225
+ (q_norm): DiffusionGemmaRMSNorm()
226
+ (k_norm): DiffusionGemmaRMSNorm()
227
+ (v_norm): DiffusionGemmaRMSNorm()
228
+ )
229
+ (mlp): DiffusionGemmaText4MLP(
230
+ (gate_proj): Linear(in_features=16, out_features=64, bias=False)
231
+ (up_proj): Linear(in_features=16, out_features=64, bias=False)
232
+ (down_proj): Linear(in_features=64, out_features=16, bias=False)
233
+ (act_fn): GELUTanh()
234
+ )
235
+ (input_layernorm): DiffusionGemmaRMSNorm()
236
+ (post_attention_layernorm): DiffusionGemmaRMSNorm()
237
+ (pre_feedforward_layernorm): DiffusionGemmaRMSNorm()
238
+ (post_feedforward_layernorm): DiffusionGemmaRMSNorm()
239
+ (router): DiffusionGemmaTextRouter(
240
+ (norm): DiffusionGemmaRMSNorm()
241
+ (proj): Linear(in_features=16, out_features=32, bias=False)
242
+ )
243
+ (experts): DiffusionGemmaTextExperts(
244
+ (act_fn): GELUTanh()
245
+ )
246
+ (post_feedforward_layernorm_1): DiffusionGemmaRMSNorm()
247
+ (post_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
248
+ (pre_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
249
+ )
250
+ )
251
+ (norm): DiffusionGemmaRMSNorm()
252
+ (rotary_emb): DiffusionGemmaTextRotaryEmbedding()
253
+ )
254
+ (vision_tower): Gemma4VisionModel(
255
+ (patch_embedder): Gemma4VisionPatchEmbedder(
256
+ (input_proj): Linear(in_features=768, out_features=64, bias=False)
257
+ )
258
+ (encoder): Gemma4VisionEncoder(
259
+ (rotary_emb): Gemma4VisionRotaryEmbedding()
260
+ (layers): ModuleList(
261
+ (0-1): 2 x Gemma4VisionEncoderLayer(
262
+ (self_attn): Gemma4VisionAttention(
263
+ (q_proj): Gemma4ClippableLinear(
264
+ (linear): Linear(in_features=64, out_features=64, bias=False)
265
+ )
266
+ (k_proj): Gemma4ClippableLinear(
267
+ (linear): Linear(in_features=64, out_features=64, bias=False)
268
+ )
269
+ (v_proj): Gemma4ClippableLinear(
270
+ (linear): Linear(in_features=64, out_features=64, bias=False)
271
+ )
272
+ (o_proj): Gemma4ClippableLinear(
273
+ (linear): Linear(in_features=64, out_features=64, bias=False)
274
+ )
275
+ (q_norm): Gemma4RMSNorm()
276
+ (k_norm): Gemma4RMSNorm()
277
+ (v_norm): Gemma4RMSNorm()
278
+ )
279
+ (mlp): Gemma4VisionMLP(
280
+ (gate_proj): Gemma4ClippableLinear(
281
+ (linear): Linear(in_features=64, out_features=128, bias=False)
282
+ )
283
+ (up_proj): Gemma4ClippableLinear(
284
+ (linear): Linear(in_features=64, out_features=128, bias=False)
285
+ )
286
+ (down_proj): Gemma4ClippableLinear(
287
+ (linear): Linear(in_features=128, out_features=64, bias=False)
288
+ )
289
+ (act_fn): GELUTanh()
290
+ )
291
+ (input_layernorm): Gemma4RMSNorm()
292
+ (post_attention_layernorm): Gemma4RMSNorm()
293
+ (pre_feedforward_layernorm): Gemma4RMSNorm()
294
+ (post_feedforward_layernorm): Gemma4RMSNorm()
295
+ )
296
+ )
297
+ )
298
+ (pooler): Gemma4VisionPooler()
299
+ )
300
+ (embed_vision): DiffusionGemmaMultimodalEmbedder(
301
+ (embedding_projection): Linear(in_features=64, out_features=16, bias=False)
302
+ (embedding_pre_projection_norm): DiffusionGemmaRMSNorm()
303
+ )
304
+ )
305
+ (decoder): DiffusionGemmaDecoderModel(
306
+ (embed_tokens): DiffusionGemmaTextScaledWordEmbedding(262144, 16, padding_idx=0)
307
+ (layers): ModuleList(
308
+ (0-4): 5 x DiffusionGemmaDecoderTextLayer(
309
+ (self_attn): DiffusionGemmaDecoderTextAttention(
310
+ (q_proj): Linear(in_features=16, out_features=32, bias=False)
311
+ (k_proj): Linear(in_features=16, out_features=32, bias=False)
312
+ (v_proj): Linear(in_features=16, out_features=32, bias=False)
313
+ (o_proj): Linear(in_features=32, out_features=16, bias=False)
314
+ (q_norm): DiffusionGemmaRMSNorm()
315
+ (k_norm): DiffusionGemmaRMSNorm()
316
+ (v_norm): DiffusionGemmaRMSNorm()
317
+ )
318
+ (mlp): DiffusionGemmaText4MLP(
319
+ (gate_proj): Linear(in_features=16, out_features=64, bias=False)
320
+ (up_proj): Linear(in_features=16, out_features=64, bias=False)
321
+ (down_proj): Linear(in_features=64, out_features=16, bias=False)
322
+ (act_fn): GELUTanh()
323
+ )
324
+ (input_layernorm): DiffusionGemmaRMSNorm()
325
+ (post_attention_layernorm): DiffusionGemmaRMSNorm()
326
+ (pre_feedforward_layernorm): DiffusionGemmaRMSNorm()
327
+ (post_feedforward_layernorm): DiffusionGemmaRMSNorm()
328
+ (router): DiffusionGemmaTextRouter(
329
+ (norm): DiffusionGemmaRMSNorm()
330
+ (proj): Linear(in_features=16, out_features=32, bias=False)
331
+ )
332
+ (experts): DiffusionGemmaTextExperts(
333
+ (act_fn): GELUTanh()
334
+ )
335
+ (post_feedforward_layernorm_1): DiffusionGemmaRMSNorm()
336
+ (post_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
337
+ (pre_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
338
+ )
339
+ (5): DiffusionGemmaDecoderTextLayer(
340
+ (self_attn): DiffusionGemmaDecoderTextAttention(
341
+ (q_proj): Linear(in_features=16, out_features=64, bias=False)
342
+ (k_proj): Linear(in_features=16, out_features=64, bias=False)
343
+ (o_proj): Linear(in_features=64, out_features=16, bias=False)
344
+ (q_norm): DiffusionGemmaRMSNorm()
345
+ (k_norm): DiffusionGemmaRMSNorm()
346
+ (v_norm): DiffusionGemmaRMSNorm()
347
+ )
348
+ (mlp): DiffusionGemmaText4MLP(
349
+ (gate_proj): Linear(in_features=16, out_features=64, bias=False)
350
+ (up_proj): Linear(in_features=16, out_features=64, bias=False)
351
+ (down_proj): Linear(in_features=64, out_features=16, bias=False)
352
+ (act_fn): GELUTanh()
353
+ )
354
+ (input_layernorm): DiffusionGemmaRMSNorm()
355
+ (post_attention_layernorm): DiffusionGemmaRMSNorm()
356
+ (pre_feedforward_layernorm): DiffusionGemmaRMSNorm()
357
+ (post_feedforward_layernorm): DiffusionGemmaRMSNorm()
358
+ (router): DiffusionGemmaTextRouter(
359
+ (norm): DiffusionGemmaRMSNorm()
360
+ (proj): Linear(in_features=16, out_features=32, bias=False)
361
+ )
362
+ (experts): DiffusionGemmaTextExperts(
363
+ (act_fn): GELUTanh()
364
+ )
365
+ (post_feedforward_layernorm_1): DiffusionGemmaRMSNorm()
366
+ (post_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
367
+ (pre_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
368
+ )
369
+ (6-10): 5 x DiffusionGemmaDecoderTextLayer(
370
+ (self_attn): DiffusionGemmaDecoderTextAttention(
371
+ (q_proj): Linear(in_features=16, out_features=32, bias=False)
372
+ (k_proj): Linear(in_features=16, out_features=32, bias=False)
373
+ (v_proj): Linear(in_features=16, out_features=32, bias=False)
374
+ (o_proj): Linear(in_features=32, out_features=16, bias=False)
375
+ (q_norm): DiffusionGemmaRMSNorm()
376
+ (k_norm): DiffusionGemmaRMSNorm()
377
+ (v_norm): DiffusionGemmaRMSNorm()
378
+ )
379
+ (mlp): DiffusionGemmaText4MLP(
380
+ (gate_proj): Linear(in_features=16, out_features=64, bias=False)
381
+ (up_proj): Linear(in_features=16, out_features=64, bias=False)
382
+ (down_proj): Linear(in_features=64, out_features=16, bias=False)
383
+ (act_fn): GELUTanh()
384
+ )
385
+ (input_layernorm): DiffusionGemmaRMSNorm()
386
+ (post_attention_layernorm): DiffusionGemmaRMSNorm()
387
+ (pre_feedforward_layernorm): DiffusionGemmaRMSNorm()
388
+ (post_feedforward_layernorm): DiffusionGemmaRMSNorm()
389
+ (router): DiffusionGemmaTextRouter(
390
+ (norm): DiffusionGemmaRMSNorm()
391
+ (proj): Linear(in_features=16, out_features=32, bias=False)
392
+ )
393
+ (experts): DiffusionGemmaTextExperts(
394
+ (act_fn): GELUTanh()
395
+ )
396
+ (post_feedforward_layernorm_1): DiffusionGemmaRMSNorm()
397
+ (post_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
398
+ (pre_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
399
+ )
400
+ (11): DiffusionGemmaDecoderTextLayer(
401
+ (self_attn): DiffusionGemmaDecoderTextAttention(
402
+ (q_proj): Linear(in_features=16, out_features=64, bias=False)
403
+ (k_proj): Linear(in_features=16, out_features=64, bias=False)
404
+ (o_proj): Linear(in_features=64, out_features=16, bias=False)
405
+ (q_norm): DiffusionGemmaRMSNorm()
406
+ (k_norm): DiffusionGemmaRMSNorm()
407
+ (v_norm): DiffusionGemmaRMSNorm()
408
+ )
409
+ (mlp): DiffusionGemmaText4MLP(
410
+ (gate_proj): Linear(in_features=16, out_features=64, bias=False)
411
+ (up_proj): Linear(in_features=16, out_features=64, bias=False)
412
+ (down_proj): Linear(in_features=64, out_features=16, bias=False)
413
+ (act_fn): GELUTanh()
414
+ )
415
+ (input_layernorm): DiffusionGemmaRMSNorm()
416
+ (post_attention_layernorm): DiffusionGemmaRMSNorm()
417
+ (pre_feedforward_layernorm): DiffusionGemmaRMSNorm()
418
+ (post_feedforward_layernorm): DiffusionGemmaRMSNorm()
419
+ (router): DiffusionGemmaTextRouter(
420
+ (norm): DiffusionGemmaRMSNorm()
421
+ (proj): Linear(in_features=16, out_features=32, bias=False)
422
+ )
423
+ (experts): DiffusionGemmaTextExperts(
424
+ (act_fn): GELUTanh()
425
+ )
426
+ (post_feedforward_layernorm_1): DiffusionGemmaRMSNorm()
427
+ (post_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
428
+ (pre_feedforward_layernorm_2): DiffusionGemmaRMSNorm()
429
+ )
430
+ )
431
+ (norm): DiffusionGemmaRMSNorm()
432
+ (rotary_emb): DiffusionGemmaTextRotaryEmbedding()
433
+ (self_conditioning): DiffusionGemmaSelfConditioning(
434
+ (pre_norm): DiffusionGemmaRMSNorm()
435
+ (post_norm): DiffusionGemmaRMSNorm()
436
+ (gate_proj): Linear(in_features=16, out_features=64, bias=False)
437
+ (up_proj): Linear(in_features=16, out_features=64, bias=False)
438
+ (down_proj): Linear(in_features=64, out_features=16, bias=False)
439
+ (act_fn): GELUTanh()
440
+ )
441
+ )
442
+ )
443
+ (lm_head): Linear(in_features=16, out_features=262144, bias=False)
444
+ )
445
+ ```
446
+
447
+ </details>
448
+
449
+ ### Test environment:
450
+
451
+ - Pillow: 13.0.0
452
+ - huggingface_hub: 2.3.0
453
+ - numpy: 2.3.5
454
+ - safetensors: 0.8.0
455
+ - tokenizers: 0.23.3
456
+ - torch: 2.13.0
457
+ - transformers: 5.19.0
458
+
459
+ ### Change log:
460
+
461
+ - 2026-10-23: Initial version.
462
+
463
+ This repo is generated by GPT-6.1-Sol
chat_template.jinja ADDED
@@ -0,0 +1,387 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {#
2
+ Template: Google Gemma 4 Canonical Chat Template
3
+ Author: Google Gemma Engineering Team
4
+ Published: 2026-07-09
5
+ Context: Fixed tool-calling loops, turn closures, and thinking content-ordering.
6
+ #}
7
+ {%- macro format_parameters(properties, required, filter_keys=false) -%}
8
+ {%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%}
9
+ {%- set ns = namespace(found_first=false) -%}
10
+ {%- for key, value in properties | dictsort -%}
11
+ {%- set add_comma = false -%}
12
+ {%- if not filter_keys or key not in standard_keys -%}
13
+ {%- if ns.found_first %},{% endif -%}
14
+ {%- set ns.found_first = true -%}
15
+ {{ key }}:{
16
+ {%- if value['description'] -%}
17
+ description:<|"|>{{ value['description'] }}<|"|>
18
+ {%- set add_comma = true -%}
19
+ {%- endif -%}
20
+ {%- if value['type'] | upper == 'STRING' -%}
21
+ {%- if value['enum'] -%}
22
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
23
+ enum:{{ format_argument(value['enum']) }}
24
+ {%- endif -%}
25
+ {%- elif value['type'] | upper == 'ARRAY' -%}
26
+ {%- if value['items'] is mapping and value['items'] -%}
27
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
28
+ items:{
29
+ {%- set ns_items = namespace(found_first=false) -%}
30
+ {%- for item_key, item_value in value['items'] | dictsort -%}
31
+ {%- if item_value is not none -%}
32
+ {%- if ns_items.found_first %},{% endif -%}
33
+ {%- set ns_items.found_first = true -%}
34
+ {%- if item_key == 'properties' -%}
35
+ properties:{
36
+ {%- if item_value is mapping -%}
37
+ {{- format_parameters(item_value, value['items']['required'] | default([])) -}}
38
+ {%- endif -%}
39
+ }
40
+ {%- elif item_key == 'required' -%}
41
+ required:[
42
+ {%- for req_item in item_value -%}
43
+ <|"|>{{- req_item -}}<|"|>
44
+ {%- if not loop.last %},{% endif -%}
45
+ {%- endfor -%}
46
+ ]
47
+ {%- elif item_key == 'type' -%}
48
+ {%- if item_value is string -%}
49
+ type:{{ format_argument(item_value | upper) }}
50
+ {%- else -%}
51
+ type:{{ format_argument(item_value | map('upper') | list) }}
52
+ {%- endif -%}
53
+ {%- else -%}
54
+ {{ item_key }}:{{ format_argument(item_value) }}
55
+ {%- endif -%}
56
+ {%- endif -%}
57
+ {%- endfor -%}
58
+ }
59
+ {%- endif -%}
60
+ {%- endif -%}
61
+ {%- if value['nullable'] %}
62
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
63
+ nullable:true
64
+ {%- endif -%}
65
+ {%- if value['type'] | upper == 'OBJECT' -%}
66
+ {%- if value['properties'] is defined and value['properties'] is mapping -%}
67
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
68
+ properties:{
69
+ {{- format_parameters(value['properties'], value['required'] | default([])) -}}
70
+ }
71
+ {%- elif value is mapping -%}
72
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
73
+ properties:{
74
+ {{- format_parameters(value, value['required'] | default([]), filter_keys=true) -}}
75
+ }
76
+ {%- endif -%}
77
+ {%- if value['required'] -%}
78
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
79
+ required:[
80
+ {%- for item in value['required'] | default([]) -%}
81
+ <|"|>{{- item -}}<|"|>
82
+ {%- if not loop.last %},{% endif -%}
83
+ {%- endfor -%}
84
+ ]
85
+ {%- endif -%}
86
+ {%- endif -%}
87
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
88
+ type:<|"|>{{ value['type'] | upper }}<|"|>}
89
+ {%- endif -%}
90
+ {%- endfor -%}
91
+ {%- endmacro -%}
92
+ {%- macro format_function_declaration(tool_data) -%}
93
+ declaration:{{- tool_data['function']['name'] -}}{description:<|"|>{{- tool_data['function']['description'] -}}<|"|>
94
+ {%- set params = tool_data['function']['parameters'] -%}
95
+ {%- if params -%}
96
+ ,parameters:{
97
+ {%- if params['properties'] -%}
98
+ properties:{ {{- format_parameters(params['properties'], params['required']) -}} },
99
+ {%- endif -%}
100
+ {%- if params['required'] -%}
101
+ required:[
102
+ {%- for item in params['required'] -%}
103
+ <|"|>{{- item -}}<|"|>
104
+ {{- ',' if not loop.last -}}
105
+ {%- endfor -%}
106
+ ],
107
+ {%- endif -%}
108
+ {%- if params['type'] -%}
109
+ type:<|"|>{{- params['type'] | upper -}}<|"|>}
110
+ {%- endif -%}
111
+ {%- endif -%}
112
+ {%- if 'response' in tool_data['function'] -%}
113
+ {%- set response_declaration = tool_data['function']['response'] -%}
114
+ ,response:{
115
+ {%- if response_declaration['description'] -%}
116
+ description:<|"|>{{- response_declaration['description'] -}}<|"|>,
117
+ {%- endif -%}
118
+ {%- if response_declaration['type'] | upper == 'OBJECT' -%}
119
+ type:<|"|>{{- response_declaration['type'] | upper -}}<|"|>}
120
+ {%- endif -%}
121
+ {%- endif -%}
122
+ }
123
+ {%- endmacro -%}
124
+ {%- macro format_argument(argument, escape_keys=True) -%}
125
+ {%- if argument is none -%}
126
+ {{- 'null' -}}
127
+ {%- elif argument is string -%}
128
+ {{- '<|"|>' + argument + '<|"|>' -}}
129
+ {%- elif argument is boolean -%}
130
+ {{- 'true' if argument else 'false' -}}
131
+ {%- elif argument is mapping -%}
132
+ {{- '{' -}}
133
+ {%- set ns = namespace(found_first=false) -%}
134
+ {%- for key, value in argument | dictsort -%}
135
+ {%- if ns.found_first %},{% endif -%}
136
+ {%- set ns.found_first = true -%}
137
+ {%- if escape_keys -%}
138
+ {{- '<|"|>' + key + '<|"|>' -}}
139
+ {%- else -%}
140
+ {{- key -}}
141
+ {%- endif -%}
142
+ :{{- format_argument(value, escape_keys=escape_keys) -}}
143
+ {%- endfor -%}
144
+ {{- '}' -}}
145
+ {%- elif argument is sequence -%}
146
+ {{- '[' -}}
147
+ {%- for item in argument -%}
148
+ {{- format_argument(item, escape_keys=escape_keys) -}}
149
+ {%- if not loop.last %},{% endif -%}
150
+ {%- endfor -%}
151
+ {{- ']' -}}
152
+ {%- else -%}
153
+ {{- argument -}}
154
+ {%- endif -%}
155
+ {%- endmacro -%}
156
+ {%- macro strip_thinking(text) -%}
157
+ {%- set ns = namespace(result='') -%}
158
+ {%- for part in text.split('<channel|>') -%}
159
+ {%- if '<|channel>' in part -%}
160
+ {%- set ns.result = ns.result + part.split('<|channel>')[0] -%}
161
+ {%- else -%}
162
+ {%- set ns.result = ns.result + part -%}
163
+ {%- endif -%}
164
+ {%- endfor -%}
165
+ {{- ns.result | trim -}}
166
+ {%- endmacro -%}
167
+
168
+ {%- macro format_tool_response_block(tool_name, response) -%}
169
+ {{- '<|tool_response>' -}}
170
+ {%- if response is mapping -%}
171
+ {{- 'response:' + tool_name + '{' -}}
172
+ {%- for key, value in response | dictsort -%}
173
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
174
+ {%- if not loop.last %},{% endif -%}
175
+ {%- endfor -%}
176
+ {{- '}' -}}
177
+ {%- else -%}
178
+ {{- 'response:' + tool_name + '{value:' + format_argument(response, escape_keys=False) + '}' -}}
179
+ {%- endif -%}
180
+ {{- '<tool_response|>' -}}
181
+ {%- endmacro -%}
182
+
183
+ {#- ===== SETUP ===== -#}
184
+ {%- set ns = namespace(prev_message_type=None, prev_non_tool_role=None) -%}
185
+ {%- set loop_messages = messages -%}
186
+ {%- set enable_thinking = enable_thinking | default(false) -%}
187
+ {%- set preserve_thinking = preserve_thinking | default(false) -%}
188
+ {{- bos_token -}}
189
+ {#- Handle System/Tool Definitions Block -#}
190
+ {%- if enable_thinking or tools or (messages and messages[0]['role'] in ['system', 'developer']) -%}
191
+ {{- '<|turn>system\n' -}}
192
+ {#- Inject Thinking token at the very top of the FIRST system turn -#}
193
+ {%- if enable_thinking -%}
194
+ {{- '<|think|>\n' -}}
195
+ {%- set ns.prev_message_type = 'think' -%}
196
+ {%- endif -%}
197
+ {%- if messages and messages[0]['role'] in ['system', 'developer'] -%}
198
+ {%- if messages[0]['content'] is string -%}
199
+ {{- messages[0]['content'] | trim -}}
200
+ {%- elif messages[0]['content'] is sequence -%}
201
+ {%- for item in messages[0]['content'] -%}
202
+ {{- item['text'] | trim + ' '-}}
203
+ {%- endfor -%}
204
+ {%- endif -%}
205
+ {%- set loop_messages = messages[1:] -%}
206
+ {%- endif -%}
207
+ {%- if tools -%}
208
+ {%- for tool in tools %}
209
+ {{- '<|tool>' -}}
210
+ {{- format_function_declaration(tool) | trim -}}
211
+ {{- '<tool|>' -}}
212
+ {%- endfor %}
213
+ {%- set ns.prev_message_type = 'tool' -%}
214
+ {%- endif -%}
215
+ {{- '<turn|>\n' -}}
216
+ {%- endif %}
217
+
218
+ {#- Pre-scan: find last user message index for reasoning guard -#}
219
+ {%- set ns_turn = namespace(last_user_idx=-1) -%}
220
+ {%- for i in range(loop_messages | length) -%}
221
+ {%- if loop_messages[i]['role'] == 'user' -%}
222
+ {%- set ns_turn.last_user_idx = i -%}
223
+ {%- endif -%}
224
+ {%- endfor -%}
225
+
226
+ {#- Loop through messages -#}
227
+ {%- for message in loop_messages -%}
228
+ {%- if message['role'] != 'tool' -%}
229
+ {%- set ns.prev_message_type = None -%}
230
+ {%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}
231
+ {#- Detect continuation using tracked state — O(1) instead of O(n) backward scan -#}
232
+ {%- set continue_same_model_turn = (role == 'model' and ns.prev_non_tool_role == 'assistant') -%}
233
+ {%- if not continue_same_model_turn -%}
234
+ {{- '<|turn>' + role + '\n' }}
235
+
236
+ {%- endif -%}
237
+
238
+ {#- Render reasoning/reasoning_content as thinking channel -#}
239
+ {%- set thinking_text = message.get('reasoning') or message.get('reasoning_content') -%}
240
+ {%- set thinking_gate = (loop.index0 > ns_turn.last_user_idx) or (preserve_thinking and message.get('tool_calls')) -%}
241
+ {%- if thinking_text and thinking_gate -%}
242
+ {{- '<|channel>thought\n' + thinking_text + '\n<channel|>' -}}
243
+ {%- endif -%}
244
+
245
+ {%- if message.get('tool_calls') -%}
246
+ {%- for tool_call in message.get('tool_calls') -%}
247
+ {%- set function = tool_call['function'] -%}
248
+ {{- '<|tool_call>call:' + function['name'] + '{' -}}
249
+ {%- if function['arguments'] is mapping -%}
250
+ {%- set ns_args = namespace(found_first=false) -%}
251
+ {%- for key, value in function['arguments'] | dictsort -%}
252
+ {%- if ns_args.found_first %},{% endif -%}
253
+ {%- set ns_args.found_first = true -%}
254
+ {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
255
+ {%- endfor -%}
256
+ {%- elif function['arguments'] is none -%}
257
+ {%- else -%}
258
+ {{- raise_exception(
259
+ "chat_template: tool_calls[].function.arguments must be a "
260
+ "JSON object (mapping), not a string. Deserialize arguments "
261
+ "before passing to the template."
262
+ ) -}}
263
+ {%- endif -%}
264
+ {{- '}<tool_call|>' -}}
265
+ {%- endfor -%}
266
+ {%- set ns.prev_message_type = 'tool_call' -%}
267
+ {%- endif -%}
268
+
269
+ {%- set ns_tr_out = namespace(flag=false) -%}
270
+ {%- if message.get('tool_responses') -%}
271
+ {#- Legacy: tool_responses embedded on the assistant message (Google/Gemma native) -#}
272
+ {%- for tool_response in message.get('tool_responses') -%}
273
+ {{- format_tool_response_block(tool_response['name'] | default('unknown', true), tool_response['response']) -}}
274
+ {%- set ns_tr_out.flag = true -%}
275
+ {%- set ns.prev_message_type = 'tool_response' -%}
276
+ {%- endfor -%}
277
+ {%- elif message.get('tool_calls') -%}
278
+ {#- OpenAI Chat Completions: forward-scan consecutive role:tool messages -#}
279
+ {%- set ns_tool_scan = namespace(stopped=false) -%}
280
+ {%- for k in range(loop.index0 + 1, loop_messages | length) -%}
281
+ {%- if ns_tool_scan.stopped -%}
282
+ {%- elif loop_messages[k]['role'] != 'tool' -%}
283
+ {%- set ns_tool_scan.stopped = true -%}
284
+ {%- else -%}
285
+ {%- set follow = loop_messages[k] -%}
286
+ {#- Resolve tool_call_id to function name -#}
287
+ {%- set ns_tname = namespace(name=follow.get('name') or 'unknown') -%}
288
+ {%- for tc in message.get('tool_calls') -%}
289
+ {%- if tc.get('id') == follow.get('tool_call_id') -%}
290
+ {%- set ns_tname.name = tc['function']['name'] -%}
291
+ {%- endif -%}
292
+ {%- endfor -%}
293
+ {#- Handle content as string or content-parts array -#}
294
+ {%- set tool_body = follow.get('content') -%}
295
+ {%- if tool_body is string -%}
296
+ {{- format_tool_response_block(ns_tname.name, tool_body) -}}
297
+ {%- elif tool_body is sequence and tool_body is not string -%}
298
+ {%- set ns_txt = namespace(s='') -%}
299
+ {%- for part in tool_body -%}
300
+ {%- if part.get('type') == 'text' -%}
301
+ {%- set ns_txt.s = ns_txt.s + (part.get('text') | default('')) -%}
302
+ {%- endif -%}
303
+ {%- endfor -%}
304
+ {{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
305
+ {%- for part in tool_body -%}
306
+ {%- if part.get('type') in ['image', 'image_url'] -%}
307
+ {{- '<|image|>' -}}
308
+ {%- elif part.get('type') in ['audio', 'input_audio'] -%}
309
+ {{- '<|audio|>' -}}
310
+ {%- elif part.get('type') == 'video' -%}
311
+ {{- '<|video|>' -}}
312
+ {%- endif -%}
313
+ {%- endfor -%}
314
+ {%- else -%}
315
+ {{- format_tool_response_block(ns_tname.name, tool_body) -}}
316
+ {%- endif -%}
317
+ {%- set ns_tr_out.flag = true -%}
318
+ {%- set ns.prev_message_type = 'tool_response' -%}
319
+ {%- endif -%}
320
+ {%- endfor -%}
321
+ {%- endif -%}
322
+
323
+ {%- set captured_content -%}
324
+ {%- if message.get('content') is string -%}
325
+ {%- if role == 'model' -%}
326
+ {{- strip_thinking(message['content']) -}}
327
+ {%- else -%}
328
+ {{- message['content'] | trim -}}
329
+ {%- endif -%}
330
+ {%- elif message.get('content') is sequence -%}
331
+ {%- for item in message['content'] -%}
332
+ {%- if item.get('type') == 'text' -%}
333
+ {%- if role == 'model' -%}
334
+ {{- strip_thinking(item['text']) -}}
335
+ {%- else -%}
336
+ {{- item['text'] | trim -}}
337
+ {%- endif -%}
338
+ {%- elif item.get('type') in ['image', 'image_url'] -%}
339
+ {{- '<|image|>' -}}
340
+ {%- elif item.get('type') in ['audio', 'input_audio'] -%}
341
+ {{- '<|audio|>' -}}
342
+ {%- elif item.get('type') == 'video' -%}
343
+ {{- '<|video|>' -}}
344
+ {%- endif -%}
345
+ {%- endfor -%}
346
+ {%- endif -%}
347
+ {%- endset -%}
348
+
349
+ {{- captured_content -}}
350
+ {%- set has_content = captured_content | trim | length > 0 -%}
351
+
352
+ {#- Forward-scan: find next non-tool message role for continuation detection -#}
353
+ {%- set next_nt = namespace(role=None, found=false) -%}
354
+ {%- for j in range(loop.index0 + 1, loop_messages | length) -%}
355
+ {%- if not next_nt.found -%}
356
+ {%- if loop_messages[j]['role'] != 'tool' -%}
357
+ {%- set next_nt.role = loop_messages[j]['role'] -%}
358
+ {%- set next_nt.found = true -%}
359
+ {%- endif -%}
360
+ {%- endif -%}
361
+ {%- endfor -%}
362
+
363
+ {%- set continues_into_next = (
364
+ role == 'model'
365
+ and next_nt.role == 'assistant'
366
+ and (not message.get('tool_calls') or ns_tr_out.flag)
367
+ ) -%}
368
+
369
+ {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
370
+ {{- '<|tool_response>' -}}
371
+ {%- elif continues_into_next -%}
372
+ {%- elif not (ns_tr_out.flag and not has_content and not next_nt.found) -%}
373
+ {{- '<turn|>\n' -}}
374
+ {%- endif -%}
375
+ {%- endif -%}
376
+
377
+ {#- Track previous non-tool role for next iteration (avoids O(n) backward scan) -#}
378
+ {%- set ns.prev_non_tool_role = message['role'] -%}
379
+ {%- endfor -%}
380
+
381
+ {%- if add_generation_prompt -%}
382
+ {%- if ns.prev_message_type != 'tool_response' and ns.prev_message_type != 'tool_call' -%}
383
+ {{- '<|turn>model\n' -}}
384
+ {%- elif ns.prev_message_type == 'tool_response' and enable_thinking -%}
385
+ {{- '<|channel>thought\n' -}}
386
+ {%- endif -%}
387
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "DiffusionGemmaForBlockDiffusion"
4
+ ],
5
+ "boi_token_id": 255999,
6
+ "canvas_length": 256,
7
+ "dtype": "bfloat16",
8
+ "eoi_token_id": 258882,
9
+ "eos_token_id": [
10
+ 1,
11
+ 106
12
+ ],
13
+ "image_token_id": 258880,
14
+ "initializer_range": 0.02,
15
+ "model_type": "diffusion_gemma",
16
+ "text_config": {
17
+ "attention_bias": false,
18
+ "attention_dropout": 0.0,
19
+ "bos_token_id": 2,
20
+ "dtype": "bfloat16",
21
+ "eos_token_id": 1,
22
+ "final_logit_softcapping": 30.0,
23
+ "head_dim": 32,
24
+ "hidden_activation": "gelu_pytorch_tanh",
25
+ "hidden_size": 16,
26
+ "initializer_range": 0.02,
27
+ "intermediate_size": 64,
28
+ "layer_types": [
29
+ "sliding_attention",
30
+ "sliding_attention",
31
+ "sliding_attention",
32
+ "sliding_attention",
33
+ "sliding_attention",
34
+ "full_attention",
35
+ "sliding_attention",
36
+ "sliding_attention",
37
+ "sliding_attention",
38
+ "sliding_attention",
39
+ "sliding_attention",
40
+ "full_attention"
41
+ ],
42
+ "max_position_embeddings": 262144,
43
+ "model_type": "diffusion_gemma_text",
44
+ "moe_intermediate_size": 32,
45
+ "num_attention_heads": 1,
46
+ "num_experts": 32,
47
+ "num_hidden_layers": 12,
48
+ "num_key_value_heads": 1,
49
+ "pad_token_id": 0,
50
+ "per_layer_config": {
51
+ "05": {
52
+ "head_dim": 64
53
+ },
54
+ "11": {
55
+ "head_dim": 64
56
+ }
57
+ },
58
+ "rms_norm_eps": 1e-06,
59
+ "rope_parameters": {
60
+ "full_attention": {
61
+ "partial_rotary_factor": 0.25,
62
+ "rope_theta": 1000000.0,
63
+ "rope_type": "proportional"
64
+ },
65
+ "sliding_attention": {
66
+ "rope_theta": 10000.0,
67
+ "rope_type": "default"
68
+ }
69
+ },
70
+ "sliding_window": 1024,
71
+ "tie_word_embeddings": true,
72
+ "top_k_experts": 8,
73
+ "use_bidirectional_attention": "vision",
74
+ "vocab_size": 262144
75
+ },
76
+ "tie_word_embeddings": true,
77
+ "transformers_version": "5.19.0",
78
+ "vision_config": {
79
+ "_name_or_path": "",
80
+ "architectures": null,
81
+ "attention_bias": false,
82
+ "attention_dropout": 0.0,
83
+ "chunk_size_feed_forward": 0,
84
+ "default_output_length": 280,
85
+ "dtype": "bfloat16",
86
+ "global_head_dim": 72,
87
+ "head_dim": 32,
88
+ "hidden_activation": "gelu_pytorch_tanh",
89
+ "hidden_size": 64,
90
+ "id2label": {
91
+ "0": "LABEL_0",
92
+ "1": "LABEL_1"
93
+ },
94
+ "initializer_range": 0.02,
95
+ "intermediate_size": 128,
96
+ "is_encoder_decoder": false,
97
+ "label2id": {
98
+ "LABEL_0": 0,
99
+ "LABEL_1": 1
100
+ },
101
+ "max_position_embeddings": 131072,
102
+ "model_type": "gemma4_vision",
103
+ "num_attention_heads": 2,
104
+ "num_hidden_layers": 2,
105
+ "num_key_value_heads": 2,
106
+ "output_attentions": false,
107
+ "output_hidden_states": false,
108
+ "patch_size": 16,
109
+ "pooling_kernel_size": 3,
110
+ "position_embedding_size": 10240,
111
+ "problem_type": null,
112
+ "return_dict": true,
113
+ "rms_norm_eps": 1e-06,
114
+ "rope_parameters": {
115
+ "rope_theta": 100.0,
116
+ "rope_type": "axial"
117
+ },
118
+ "standardize": true,
119
+ "use_clipped_linears": false
120
+ },
121
+ "vision_soft_tokens_per_image": 280
122
+ }
generation_config.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "confidence_threshold": 0.005,
3
+ "eos_token_id": [
4
+ 1,
5
+ 106,
6
+ 50
7
+ ],
8
+ "max_denoising_steps": 48,
9
+ "max_new_tokens": 256,
10
+ "pad_token_id": 0,
11
+ "sampler_config": {
12
+ "_cls_name": "EntropyBoundSamplerConfig",
13
+ "entropy_bound": 0.1
14
+ },
15
+ "stability_threshold": 1,
16
+ "t_max": 0.8,
17
+ "t_min": 0.4,
18
+ "transformers_version": "5.8.0.dev0"
19
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:507f6d696d56aa68638b31200899fa4e138df38e6155301ef743bc41b56c2d33
3
+ size 12642856
model_index.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "DiffusionGemmaPipeline",
3
+ "_diffusers_version": "0.39.0.dev0",
4
+ "model": [
5
+ "transformers",
6
+ "DiffusionGemmaForBlockDiffusion"
7
+ ],
8
+ "processor": [
9
+ "transformers",
10
+ "Gemma4Processor"
11
+ ],
12
+ "scheduler": [
13
+ "diffusers",
14
+ "BlockRefinementScheduler"
15
+ ]
16
+ }
processor_config.json ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "audio_ms_per_token": 40,
3
+ "audio_seq_length": 750,
4
+ "feature_extractor": {
5
+ "dither": 0.0,
6
+ "feature_extractor_type": "Gemma4AudioFeatureExtractor",
7
+ "feature_size": 128,
8
+ "fft_length": 512,
9
+ "fft_overdrive": false,
10
+ "frame_length": 320,
11
+ "hop_length": 160,
12
+ "input_scale_factor": 1.0,
13
+ "max_frequency": 8000.0,
14
+ "mel_floor": 0.001,
15
+ "min_frequency": 0.0,
16
+ "padding_side": "right",
17
+ "padding_value": 0.0,
18
+ "per_bin_mean": null,
19
+ "per_bin_stddev": null,
20
+ "preemphasis": 0.0,
21
+ "preemphasis_htk_flavor": true,
22
+ "return_attention_mask": true,
23
+ "sampling_rate": 16000
24
+ },
25
+ "image_processor": {
26
+ "do_convert_rgb": true,
27
+ "do_normalize": false,
28
+ "do_rescale": true,
29
+ "do_resize": true,
30
+ "image_mean": [
31
+ 0.0,
32
+ 0.0,
33
+ 0.0
34
+ ],
35
+ "image_processor_type": "Gemma4ImageProcessor",
36
+ "image_seq_length": 280,
37
+ "image_std": [
38
+ 1.0,
39
+ 1.0,
40
+ 1.0
41
+ ],
42
+ "max_soft_tokens": 280,
43
+ "patch_size": 16,
44
+ "pooling_kernel_size": 3,
45
+ "resample": 3,
46
+ "rescale_factor": 0.00392156862745098
47
+ },
48
+ "image_seq_length": 280,
49
+ "processor_class": "Gemma4Processor",
50
+ "video_processor": {
51
+ "do_convert_rgb": true,
52
+ "do_normalize": true,
53
+ "do_rescale": true,
54
+ "do_resize": true,
55
+ "do_sample_frames": true,
56
+ "image_mean": [
57
+ 0.0,
58
+ 0.0,
59
+ 0.0
60
+ ],
61
+ "image_std": [
62
+ 1.0,
63
+ 1.0,
64
+ 1.0
65
+ ],
66
+ "max_soft_tokens": 70,
67
+ "num_frames": 32,
68
+ "patch_size": 16,
69
+ "pooling_kernel_size": 3,
70
+ "resample": 3,
71
+ "rescale_factor": 0.00392156862745098,
72
+ "return_metadata": false,
73
+ "video_processor_type": "Gemma4VideoProcessor"
74
+ }
75
+ }
scheduler/scheduler_config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "BlockRefinementScheduler",
3
+ "_diffusers_version": "0.39.0.dev0",
4
+ "block_length": 32,
5
+ "editing_threshold": null,
6
+ "minimal_topk": 1,
7
+ "num_inference_steps": 32,
8
+ "threshold": 0.95
9
+ }
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,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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<tool_calls>\\<\\|tool_call\\>.*\\<tool_call\\|\\>)?(?P<content>(?:(?!\\<turn\\|\\>)(?!\\<\\|tool_response\\>).)+)?(?:\\<turn\\|\\>|\\<\\|tool_response\\>)?"
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
+ "unk_token": "<unk>"
96
+ }