Xenova HF Staff commited on
Commit
97927c4
·
verified ·
0 Parent(s):

Super-squash branch 'main' using huggingface_hub

Browse files
.gitattributes ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz 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
+ onnx/audio_encoder.onnx_data filter=lfs diff=lfs merge=lfs -text
37
+ onnx/decoder_model_merged.onnx_data filter=lfs diff=lfs merge=lfs -text
38
+ onnx/decoder_model_merged_fp16.onnx_data filter=lfs diff=lfs merge=lfs -text
39
+ onnx/embed_tokens.onnx_data filter=lfs diff=lfs merge=lfs -text
40
+ onnx/embed_tokens_fp16.onnx_data filter=lfs diff=lfs merge=lfs -text
41
+ onnx/embed_tokens_int8.onnx_data filter=lfs diff=lfs merge=lfs -text
42
+ onnx/embed_tokens_quantized.onnx_data filter=lfs diff=lfs merge=lfs -text
43
+ onnx/embed_tokens_quantized.onnx_data_1 filter=lfs diff=lfs merge=lfs -text
44
+ onnx/embed_tokens_uint8.onnx_data filter=lfs diff=lfs merge=lfs -text
45
+ onnx/vision_encoder.onnx_data filter=lfs diff=lfs merge=lfs -text
46
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,738 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: gemma
3
+ library_name: transformers.js
4
+ pipeline_tag: image-text-to-text
5
+ base_model: google/gemma-3n-E2B-it
6
+ tags:
7
+ - automatic-speech-recognition
8
+ - automatic-speech-translation
9
+ - audio-text-to-text
10
+ - video-text-to-text
11
+ ---
12
+
13
+ > [!Note]
14
+ > This repository corresponds to the launch version of Gemma 3n E2B IT (Instruct), to be used with Hugging Face `transformers.js`,
15
+ > supporting text, audio, and vision (image and video) inputs.
16
+ >
17
+ > Gemma 3n models have multiple architecture innovations:
18
+ > * They are available in two sizes based on [effective parameters](https://ai.google.dev/gemma/docs/gemma-3n#parameters). While the raw parameter count of this model is 6B, the architecture design allows the model to be run with a memory footprint comparable to a traditional 2B model by offloading low-utilization matrices from the accelerator.
19
+ > * They use a MatFormer architecture that allows nesting sub-models within the [E4B model](https://huggingface.co/google/gemma-3n-E4B-it). We provide one sub-model (this model repository), or you can access a spectrum of custom-sized models using the [Mix-and-Match method](https://goo.gle/gemma3n-matformer-lab).
20
+ >
21
+ > Learn more about these techniques in the [technical blog post](https://developers.googleblog.com/en/introducing-gemma-3n-developer-guide)
22
+ > and the [Gemma documentation](https://ai.google.dev/gemma/docs/gemma-3n).
23
+
24
+
25
+
26
+ # Gemma 3n model card
27
+
28
+ **Model Page**: [Gemma 3n](https://ai.google.dev/gemma/docs/gemma-3n)
29
+
30
+ **Resources and Technical Documentation**:
31
+
32
+ - [Responsible Generative AI Toolkit](https://ai.google.dev/responsible)
33
+ - [Gemma on Kaggle](https://www.kaggle.com/models/google/gemma-3n)
34
+ - [Gemma on HuggingFace](https://huggingface.co/collections/google/gemma-3n-685065323f5984ef315c93f4)
35
+ - [Gemma on Vertex Model Garden](https://console.cloud.google.com/vertex-ai/publishers/google/model-garden/gemma3n)
36
+
37
+ **Terms of Use**: [Terms](https://ai.google.dev/gemma/terms)\
38
+ **Authors**: Google DeepMind
39
+
40
+ ## Model Information
41
+
42
+ Summary description and brief definition of inputs and outputs.
43
+
44
+ ### Description
45
+
46
+ Gemma is a family of lightweight, state-of-the-art open models from Google,
47
+ built from the same research and technology used to create the Gemini models.
48
+ Gemma 3n models are designed for efficient execution on low-resource devices.
49
+ They are capable of multimodal input, handling text, image, video, and audio
50
+ input, and generating text outputs, with open weights for pre-trained and
51
+ instruction-tuned variants. These models were trained with data in over 140
52
+ spoken languages.
53
+
54
+ Gemma 3n models use selective parameter activation technology to reduce resource
55
+ requirements. This technique allows the models to operate at an effective size
56
+ of 2B and 4B parameters, which is lower than the total number of parameters they
57
+ contain. For more information on Gemma 3n's efficient parameter management
58
+ technology, see the
59
+ [Gemma 3n](https://ai.google.dev/gemma/docs/gemma-3n#parameters)
60
+ page.
61
+
62
+ ### Inputs and outputs
63
+
64
+ - **Input:**
65
+ - Text string, such as a question, a prompt, or a document to be
66
+ summarized
67
+ - Images, normalized to 256x256, 512x512, or 768x768 resolution
68
+ and encoded to 256 tokens each
69
+ - Audio data encoded to 6.25 tokens per second from a single channel
70
+ - Total input context of 32K tokens
71
+ - **Output:**
72
+ - Generated text in response to the input, such as an answer to a
73
+ question, analysis of image content, or a summary of a document
74
+ - Total output length up to 32K tokens, subtracting the request
75
+ input tokens
76
+
77
+ ### Usage
78
+
79
+ Below, there are some code snippets on how to get quickly started with running the model.
80
+ You can copy the snippet from the section that is relevant for your use case.
81
+
82
+ #### Transformers.js
83
+
84
+ First, install the [Transformers.js](https://huggingface.co/docs/transformers.js) library.
85
+ Gemma 3n is supported starting from transformers.js version 3.6.0.
86
+
87
+ ```sh
88
+ npm i @huggingface/transformers
89
+ ```
90
+
91
+ > [!WARNING]
92
+ > Due to the model's large size, we currently only support Node.js, Deno, and Bun execution.
93
+ > In-browser WebGPU support is actively being worked on, so stay tuned for an update!
94
+
95
+
96
+ **Example:** Caption an image
97
+
98
+ ```js
99
+ import {
100
+ AutoProcessor,
101
+ AutoModelForImageTextToText,
102
+ load_image,
103
+ TextStreamer,
104
+ } from "@huggingface/transformers";
105
+
106
+ // Load processor and model
107
+ const model_id = "onnx-community/gemma-3n-E2B-it-ONNX";
108
+ const processor = await AutoProcessor.from_pretrained(model_id);
109
+ const model = await AutoModelForImageTextToText.from_pretrained(model_id, {
110
+ dtype: {
111
+ embed_tokens: "q8",
112
+ audio_encoder: "q8",
113
+ vision_encoder: "fp16",
114
+ decoder_model_merged: "q4",
115
+ },
116
+ device: "cpu", // NOTE: WebGPU support coming soon!
117
+ });
118
+
119
+ // Prepare prompt
120
+ const messages = [
121
+ {
122
+ role: "user",
123
+ content: [
124
+ { type: "image" },
125
+ { type: "text", text: "Describe this image in detail." },
126
+ ],
127
+ },
128
+ ];
129
+ const prompt = processor.apply_chat_template(messages, {
130
+ add_generation_prompt: true,
131
+ });
132
+
133
+ // Prepare inputs
134
+ const url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg";
135
+ const image = await load_image(url);
136
+ const audio = null;
137
+ const inputs = await processor(prompt, image, audio, {
138
+ add_special_tokens: false,
139
+ });
140
+
141
+ // Generate output
142
+ const outputs = await model.generate({
143
+ ...inputs,
144
+ max_new_tokens: 512,
145
+ do_sample: false,
146
+ streamer: new TextStreamer(processor.tokenizer, {
147
+ skip_prompt: true,
148
+ skip_special_tokens: false,
149
+ // callback_function: (text) => { /* Do something with the streamed output */ },
150
+ }),
151
+ });
152
+
153
+ // Decode output
154
+ const decoded = processor.batch_decode(
155
+ outputs.slice(null, [inputs.input_ids.dims.at(-1), null]),
156
+ { skip_special_tokens: true },
157
+ );
158
+ console.log(decoded[0]);
159
+ ```
160
+
161
+ <details>
162
+
163
+ <summary>See example output</summary>
164
+
165
+ ```
166
+ The image is a close-up, slightly macro shot of a cluster of vibrant pink cosmos flowers in full bloom. The flowers are the focal point, with their delicate, slightly ruffled petals radiating outwards. They have a soft, almost pastel pink hue, and their edges are subtly veined.
167
+
168
+ A small, dark-colored bee is actively visiting one of the pink flowers, its body positioned near the center of the bloom. The bee appears to be collecting pollen or nectar.
169
+
170
+ The flowers are attached to slender, brownish-green stems, and some of the surrounding foliage is visible in a blurred background, suggesting a natural outdoor setting. There are also hints of other flowers in the background, including some red ones, adding a touch of contrast to the pink.
171
+
172
+ The lighting in the image seems to be natural daylight, casting soft shadows and highlighting the textures of the petals and the bee. The overall impression is one of delicate beauty and the gentle activity of nature.
173
+ ```
174
+
175
+ </details>
176
+
177
+ **Example:** Transcribe audio
178
+
179
+ ```js
180
+ import {
181
+ AutoProcessor,
182
+ AutoModelForImageTextToText,
183
+ TextStreamer,
184
+ } from "@huggingface/transformers";
185
+ import wavefile from "wavefile";
186
+
187
+ // Load processor and model
188
+ const model_id = "onnx-community/gemma-3n-E2B-it-ONNX";
189
+ const processor = await AutoProcessor.from_pretrained(model_id);
190
+ const model = await AutoModelForImageTextToText.from_pretrained(model_id, {
191
+ dtype: {
192
+ embed_tokens: "q8",
193
+ audio_encoder: "q4",
194
+ vision_encoder: "fp16",
195
+ decoder_model_merged: "q4",
196
+ },
197
+ device: "cpu", // NOTE: WebGPU support coming soon!
198
+ });
199
+
200
+ // Prepare prompt
201
+ const messages = [
202
+ {
203
+ role: "user",
204
+ content: [
205
+ { type: "audio" },
206
+ { type: "text", text: "Transcribe this audio verbatim." },
207
+ ],
208
+ },
209
+ ];
210
+ const prompt = processor.apply_chat_template(messages, {
211
+ add_generation_prompt: true,
212
+ });
213
+
214
+ // Prepare inputs
215
+ const url = "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav";
216
+ const buffer = Buffer.from(await fetch(url).then((x) => x.arrayBuffer()));
217
+ const wav = new wavefile.WaveFile(buffer);
218
+ wav.toBitDepth("32f"); // Pipeline expects input as a Float32Array
219
+ wav.toSampleRate(processor.feature_extractor.config.sampling_rate);
220
+ let audioData = wav.getSamples();
221
+ if (Array.isArray(audioData)) {
222
+ if (audioData.length > 1) {
223
+ for (let i = 0; i < audioData[0].length; ++i) {
224
+ audioData[0][i] = (Math.sqrt(2) * (audioData[0][i] + audioData[1][i])) / 2;
225
+ }
226
+ }
227
+ audioData = audioData[0];
228
+ }
229
+
230
+ const image = null;
231
+ const audio = audioData;
232
+ const inputs = await processor(prompt, image, audio, {
233
+ add_special_tokens: false,
234
+ });
235
+
236
+ // Generate output
237
+ const outputs = await model.generate({
238
+ ...inputs,
239
+ max_new_tokens: 512,
240
+ do_sample: false,
241
+ streamer: new TextStreamer(processor.tokenizer, {
242
+ skip_prompt: true,
243
+ skip_special_tokens: false,
244
+ // callback_function: (text) => { /* Do something with the streamed output */ },
245
+ }),
246
+ });
247
+
248
+ // Decode output
249
+ const decoded = processor.batch_decode(
250
+ outputs.slice(null, [inputs.input_ids.dims.at(-1), null]),
251
+ { skip_special_tokens: true },
252
+ );
253
+ console.log(decoded[0]);
254
+ ```
255
+
256
+ <details>
257
+
258
+ <summary>See example output</summary>
259
+
260
+ ```
261
+ And so, my fellow Americans, ask not what your country can do for you. Ask what you can do for your country.
262
+ ```
263
+
264
+ </details>
265
+
266
+
267
+ #### ONNXRuntime
268
+
269
+ ```py
270
+ import onnxruntime
271
+ import numpy as np
272
+ from transformers import AutoConfig, AutoProcessor
273
+ import os
274
+
275
+ # 1. Load models
276
+ ## Load config and processor
277
+ model_id = "google/gemma-3n-E2B-it"
278
+ processor = AutoProcessor.from_pretrained(model_id)
279
+ config = AutoConfig.from_pretrained(model_id)
280
+
281
+ ## Load sessions
282
+ model_dir = "/path/to/model/files/"
283
+ embed_model_path = os.path.join(model_dir, "onnx/embed_tokens_quantized.onnx")
284
+ audio_model_path = os.path.join(model_dir, "onnx/audio_encoder.onnx")
285
+ vision_model_path = os.path.join(model_dir, "onnx/vision_encoder.onnx")
286
+ decoder_model_path = os.path.join(model_dir, "onnx/decoder_model_merged_q4.onnx")
287
+ vision_session = onnxruntime.InferenceSession(vision_model_path)
288
+ audio_session = onnxruntime.InferenceSession(audio_model_path)
289
+ embed_session = onnxruntime.InferenceSession(embed_model_path)
290
+ decoder_session = onnxruntime.InferenceSession(decoder_model_path)
291
+
292
+ ## Set config values
293
+ num_key_value_heads = config.text_config.num_key_value_heads
294
+ head_dim = config.text_config.head_dim
295
+ num_hidden_layers = config.text_config.num_hidden_layers
296
+ eos_token_id = 106 # != config.text_config.eos_token_id
297
+ image_token_id = config.image_token_id
298
+ audio_token_id = config.audio_token_id
299
+
300
+
301
+ # 2. Prepare inputs
302
+ ## Create input messages
303
+ messages = [
304
+ {
305
+ "role": "user",
306
+ "content": [
307
+ {"type": "text", "text": "In detail, describe the following audio and image."},
308
+ {"type": "audio", "audio": "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav"},
309
+ {"type": "image", "image": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg"},
310
+ ],
311
+ },
312
+ ]
313
+ inputs = processor.apply_chat_template(
314
+ messages,
315
+ add_generation_prompt=True,
316
+ tokenize=True,
317
+ return_dict=True,
318
+ return_tensors="pt",
319
+ )
320
+ input_ids = inputs["input_ids"].numpy()
321
+ attention_mask = inputs["attention_mask"].numpy()
322
+ position_ids = np.cumsum(attention_mask, axis=-1) - 1
323
+
324
+ pixel_values = inputs["pixel_values"].numpy() if "pixel_values" in inputs else None
325
+ input_features = inputs["input_features"].numpy().astype(np.float32) if "input_features" in inputs else None
326
+ input_features_mask = inputs["input_features_mask"].numpy() if "input_features_mask" in inputs else None
327
+
328
+ ## Prepare decoder inputs
329
+ batch_size = input_ids.shape[0]
330
+ past_key_values = {
331
+ f"past_key_values.{layer}.{kv}": np.zeros([batch_size, num_key_value_heads, 0, head_dim], dtype=np.float32)
332
+ for layer in range(num_hidden_layers)
333
+ for kv in ("key", "value")
334
+ }
335
+
336
+ # 3. Generation loop
337
+ max_new_tokens = 1024
338
+ generated_tokens = np.array([[]], dtype=np.int64)
339
+ image_features = None
340
+ audio_features = None
341
+ for i in range(max_new_tokens):
342
+ inputs_embeds, per_layer_inputs = embed_session.run(None, {"input_ids": input_ids})
343
+ if image_features is None and pixel_values is not None:
344
+ image_features = vision_session.run(
345
+ ["image_features"],
346
+ {
347
+ "pixel_values": pixel_values,
348
+ }
349
+ )[0]
350
+ mask = (input_ids == image_token_id).reshape(-1)
351
+ flat_embeds = inputs_embeds.reshape(-1, inputs_embeds.shape[-1])
352
+ flat_embeds[mask] = image_features.reshape(-1, image_features.shape[-1])
353
+ inputs_embeds = flat_embeds.reshape(inputs_embeds.shape)
354
+
355
+ if audio_features is None and input_features is not None and input_features_mask is not None:
356
+ audio_features = audio_session.run(
357
+ ["audio_features"],
358
+ {
359
+ "input_features": input_features,
360
+ "input_features_mask": input_features_mask,
361
+ }
362
+ )[0]
363
+ mask = (input_ids == audio_token_id).reshape(-1)
364
+ flat_embeds = inputs_embeds.reshape(-1, inputs_embeds.shape[-1])
365
+ flat_embeds[mask] = audio_features.reshape(-1, audio_features.shape[-1])
366
+ inputs_embeds = flat_embeds.reshape(inputs_embeds.shape)
367
+
368
+ logits, *present_key_values = decoder_session.run(None, dict(
369
+ inputs_embeds=inputs_embeds,
370
+ per_layer_inputs=per_layer_inputs,
371
+ position_ids=position_ids,
372
+ **past_key_values,
373
+ ))
374
+
375
+ ## Update values for next generation loop
376
+ input_ids = logits[:, -1].argmax(-1, keepdims=True)
377
+ attention_mask = np.ones_like(input_ids)
378
+ position_ids = position_ids[:, -1:] + 1
379
+ for j, key in enumerate(past_key_values):
380
+ past_key_values[key] = present_key_values[j]
381
+
382
+ generated_tokens = np.concatenate([generated_tokens, input_ids], axis=-1)
383
+ if (input_ids == eos_token_id).all():
384
+ break
385
+
386
+ ## (Optional) Streaming
387
+ print(processor.decode(input_ids[0]), end="", flush=True)
388
+ print()
389
+
390
+ # 4. Output result
391
+ print(processor.batch_decode(generated_tokens, skip_special_tokens=True)[0])
392
+ ```
393
+
394
+ ### Citation
395
+
396
+ ```
397
+ @article{gemma_3n_2025,
398
+ title={Gemma 3n},
399
+ url={https://ai.google.dev/gemma/docs/gemma-3n},
400
+ publisher={Google DeepMind},
401
+ author={Gemma Team},
402
+ year={2025}
403
+ }
404
+ ```
405
+
406
+ ## Model Data
407
+
408
+ Data used for model training and how the data was processed.
409
+
410
+ ### Training Dataset
411
+
412
+ These models were trained on a dataset that includes a wide variety of sources
413
+ totalling approximately 11 trillion tokens. The knowledge cutoff date for the
414
+ training data was June 2024. Here are the key components:
415
+
416
+ - **Web Documents**: A diverse collection of web text ensures the model
417
+ is exposed to a broad range of linguistic styles, topics, and vocabulary.
418
+ The training dataset includes content in over 140 languages.
419
+ - **Code**: Exposing the model to code helps it to learn the syntax and
420
+ patterns of programming languages, which improves its ability to generate
421
+ code and understand code-related questions.
422
+ - **Mathematics**: Training on mathematical text helps the model learn
423
+ logical reasoning, symbolic representation, and to address mathematical queries.
424
+ - **Images**: A wide range of images enables the model to perform image
425
+ analysis and visual data extraction tasks.
426
+ - Audio: A diverse set of sound samples enables the model to recognize
427
+ speech, transcribe text from recordings, and identify information in audio data.
428
+
429
+ The combination of these diverse data sources is crucial for training a
430
+ powerful multimodal model that can handle a wide variety of different tasks and
431
+ data formats.
432
+
433
+ ### Data Preprocessing
434
+
435
+ Here are the key data cleaning and filtering methods applied to the training
436
+ data:
437
+
438
+ - **CSAM Filtering**: Rigorous CSAM (Child Sexual Abuse Material)
439
+ filtering was applied at multiple stages in the data preparation process to
440
+ ensure the exclusion of harmful and illegal content.
441
+ - **Sensitive Data Filtering**: As part of making Gemma pre-trained models
442
+ safe and reliable, automated techniques were used to filter out certain
443
+ personal information and other sensitive data from training sets.
444
+ - **Additional methods**: Filtering based on content quality and safety in
445
+ line with
446
+ [our policies](https://ai.google/static/documents/ai-responsibility-update-published-february-2025.pdf).
447
+
448
+ ## Implementation Information
449
+
450
+ Details about the model internals.
451
+
452
+ ### Hardware
453
+
454
+ Gemma was trained using [Tensor Processing Unit
455
+ (TPU)](https://cloud.google.com/tpu/docs/intro-to-tpu) hardware (TPUv4p, TPUv5p
456
+ and TPUv5e). Training generative models requires significant computational
457
+ power. TPUs, designed specifically for matrix operations common in machine
458
+ learning, offer several advantages in this domain:
459
+
460
+ - **Performance**: TPUs are specifically designed to handle the massive
461
+ computations involved in training generative models. They can speed up
462
+ training considerably compared to CPUs.
463
+ - **Memory**: TPUs often come with large amounts of high-bandwidth memory,
464
+ allowing for the handling of large models and batch sizes during training.
465
+ This can lead to better model quality.
466
+ - **Scalability**: TPU Pods (large clusters of TPUs) provide a scalable
467
+ solution for handling the growing complexity of large foundation models.
468
+ You can distribute training across multiple TPU devices for faster and more
469
+ efficient processing.
470
+ - **Cost-effectiveness**: In many scenarios, TPUs can provide a more
471
+ cost-effective solution for training large models compared to CPU-based
472
+ infrastructure, especially when considering the time and resources saved
473
+ due to faster training.
474
+
475
+ These advantages are aligned with
476
+ [Google's commitments to operate sustainably](https://sustainability.google/operating-sustainably/).
477
+
478
+ ### Software
479
+
480
+ Training was done using [JAX](https://github.com/jax-ml/jax) and
481
+ [ML Pathways](https://blog.google/technology/ai/introducing-pathways-next-generation-ai-architecture/).
482
+ JAX allows researchers to take advantage of the latest generation of hardware,
483
+ including TPUs, for faster and more efficient training of large models. ML
484
+ Pathways is Google's latest effort to build artificially intelligent systems
485
+ capable of generalizing across multiple tasks. This is specially suitable for
486
+ foundation models, including large language models like these ones.
487
+
488
+ Together, JAX and ML Pathways are used as described in the
489
+ [paper about the Gemini family of models](https://goo.gle/gemma2report):
490
+ *"the 'single controller' programming model of Jax and Pathways allows a single
491
+ Python process to orchestrate the entire training run, dramatically simplifying
492
+ the development workflow."*
493
+
494
+ ## Evaluation
495
+
496
+ Model evaluation metrics and results.
497
+
498
+ ### Benchmark Results
499
+
500
+ These models were evaluated at full precision (float32) against a large
501
+ collection of different datasets and metrics to cover different aspects of
502
+ content generation. Evaluation results marked with **IT** are for
503
+ instruction-tuned models. Evaluation results marked with **PT** are for
504
+ pre-trained models.
505
+
506
+ #### Reasoning and factuality
507
+
508
+ | Benchmark | Metric | n-shot | E2B PT | E4B PT |
509
+ | ------------------------------ |----------------|----------|:--------:|:--------:|
510
+ | [HellaSwag][hellaswag] | Accuracy | 10-shot | 72.2 | 78.6 |
511
+ | [BoolQ][boolq] | Accuracy | 0-shot | 76.4 | 81.6 |
512
+ | [PIQA][piqa] | Accuracy | 0-shot | 78.9 | 81.0 |
513
+ | [SocialIQA][socialiqa] | Accuracy | 0-shot | 48.8 | 50.0 |
514
+ | [TriviaQA][triviaqa] | Accuracy | 5-shot | 60.8 | 70.2 |
515
+ | [Natural Questions][naturalq] | Accuracy | 5-shot | 15.5 | 20.9 |
516
+ | [ARC-c][arc] | Accuracy | 25-shot | 51.7 | 61.6 |
517
+ | [ARC-e][arc] | Accuracy | 0-shot | 75.8 | 81.6 |
518
+ | [WinoGrande][winogrande] | Accuracy | 5-shot | 66.8 | 71.7 |
519
+ | [BIG-Bench Hard][bbh] | Accuracy | few-shot | 44.3 | 52.9 |
520
+ | [DROP][drop] | Token F1 score | 1-shot | 53.9 | 60.8 |
521
+
522
+ [hellaswag]: https://arxiv.org/abs/1905.07830
523
+ [boolq]: https://arxiv.org/abs/1905.10044
524
+ [piqa]: https://arxiv.org/abs/1911.11641
525
+ [socialiqa]: https://arxiv.org/abs/1904.09728
526
+ [triviaqa]: https://arxiv.org/abs/1705.03551
527
+ [naturalq]: https://github.com/google-research-datasets/natural-questions
528
+ [arc]: https://arxiv.org/abs/1911.01547
529
+ [winogrande]: https://arxiv.org/abs/1907.10641
530
+ [bbh]: https://paperswithcode.com/dataset/bbh
531
+ [drop]: https://arxiv.org/abs/1903.00161
532
+
533
+ #### Multilingual
534
+
535
+ | Benchmark | Metric | n-shot | E2B IT | E4B IT |
536
+ | ------------------------------------|-------------------------|----------|:--------:|:--------:|
537
+ | [MGSM][mgsm] | Accuracy | 0-shot | 53.1 | 60.7 |
538
+ | [WMT24++][wmt24pp] (ChrF) | Character-level F-score | 0-shot | 42.7 | 50.1 |
539
+ | [Include][include] | Accuracy | 0-shot | 38.6 | 57.2 |
540
+ | [MMLU][mmlu] (ProX) | Accuracy | 0-shot | 8.1 | 19.9 |
541
+ | [OpenAI MMLU][openai-mmlu] | Accuracy | 0-shot | 22.3 | 35.6 |
542
+ | [Global-MMLU][global-mmlu] | Accuracy | 0-shot | 55.1 | 60.3 |
543
+ | [ECLeKTic][eclektic] | ECLeKTic score | 0-shot | 2.5 | 1.9 |
544
+
545
+ [mgsm]: https://arxiv.org/abs/2210.03057
546
+ [wmt24pp]: https://arxiv.org/abs/2502.12404v1
547
+ [include]:https://arxiv.org/abs/2411.19799
548
+ [mmlu]: https://arxiv.org/abs/2009.03300
549
+ [openai-mmlu]: https://huggingface.co/datasets/openai/MMMLU
550
+ [global-mmlu]: https://huggingface.co/datasets/CohereLabs/Global-MMLU
551
+ [eclektic]: https://arxiv.org/abs/2502.21228
552
+
553
+ #### STEM and code
554
+
555
+ | Benchmark | Metric | n-shot | E2B IT | E4B IT |
556
+ | ------------------------------------|--------------------------|----------|:--------:|:--------:|
557
+ | [GPQA][gpqa] Diamond | RelaxedAccuracy/accuracy | 0-shot | 24.8 | 23.7 |
558
+ | [LiveCodeBench][lcb] v5 | pass@1 | 0-shot | 18.6 | 25.7 |
559
+ | Codegolf v2.2 | pass@1 | 0-shot | 11.0 | 16.8 |
560
+ | [AIME 2025][aime-2025] | Accuracy | 0-shot | 6.7 | 11.6 |
561
+
562
+ [gpqa]: https://arxiv.org/abs/2311.12022
563
+ [lcb]: https://arxiv.org/abs/2403.07974
564
+ [aime-2025]: https://www.vals.ai/benchmarks/aime-2025-05-09
565
+
566
+ #### Additional benchmarks
567
+
568
+ | Benchmark | Metric | n-shot | E2B IT | E4B IT |
569
+ | ------------------------------------ |------------|----------|:--------:|:--------:|
570
+ | [MMLU][mmlu] | Accuracy | 0-shot | 60.1 | 64.9 |
571
+ | [MBPP][mbpp] | pass@1 | 3-shot | 56.6 | 63.6 |
572
+ | [HumanEval][humaneval] | pass@1 | 0-shot | 66.5 | 75.0 |
573
+ | [LiveCodeBench][lcb] | pass@1 | 0-shot | 13.2 | 13.2 |
574
+ | HiddenMath | Accuracy | 0-shot | 27.7 | 37.7 |
575
+ | [Global-MMLU-Lite][global-mmlu-lite] | Accuracy | 0-shot | 59.0 | 64.5 |
576
+ | [MMLU][mmlu] (Pro) | Accuracy | 0-shot | 40.5 | 50.6 |
577
+
578
+ [gpqa]: https://arxiv.org/abs/2311.12022
579
+ [mbpp]: https://arxiv.org/abs/2108.07732
580
+ [humaneval]: https://arxiv.org/abs/2107.03374
581
+ [lcb]: https://arxiv.org/abs/2403.07974
582
+ [global-mmlu-lite]: https://huggingface.co/datasets/CohereForAI/Global-MMLU-Lite
583
+
584
+ ## Ethics and Safety
585
+
586
+ Ethics and safety evaluation approach and results.
587
+
588
+ ### Evaluation Approach
589
+
590
+ Our evaluation methods include structured evaluations and internal red-teaming
591
+ testing of relevant content policies. Red-teaming was conducted by a number of
592
+ different teams, each with different goals and human evaluation metrics. These
593
+ models were evaluated against a number of different categories relevant to
594
+ ethics and safety, including:
595
+
596
+ - **Child Safety**: Evaluation of text-to-text and image to text prompts
597
+ covering child safety policies, including child sexual abuse and
598
+ exploitation.
599
+ - **Content Safety:** Evaluation of text-to-text and image to text prompts
600
+ covering safety policies including, harassment, violence and gore, and hate
601
+ speech.
602
+ - **Representational Harms**: Evaluation of text-to-text and image to text
603
+ prompts covering safety policies including bias, stereotyping, and harmful
604
+ associations or inaccuracies.
605
+
606
+ In addition to development level evaluations, we conduct "assurance
607
+ evaluations" which are our 'arms-length' internal evaluations for responsibility
608
+ governance decision making. They are conducted separately from the model
609
+ development team, to inform decision making about release. High level findings
610
+ are fed back to the model team, but prompt sets are held-out to prevent
611
+ overfitting and preserve the results' ability to inform decision making. Notable
612
+ assurance evaluation results are reported to our Responsibility & Safety Council
613
+ as part of release review.
614
+
615
+ ### Evaluation Results
616
+
617
+ For all areas of safety testing, we saw safe levels of performance across the
618
+ categories of child safety, content safety, and representational harms relative
619
+ to previous Gemma models. All testing was conducted without safety filters to
620
+ evaluate the model capabilities and behaviors. For text-to-text, image-to-text,
621
+ and audio-to-text, and across all model sizes, the model produced minimal policy
622
+ violations, and showed significant improvements over previous Gemma models'
623
+ performance with respect to high severity violations. A limitation of our
624
+ evaluations was they included primarily English language prompts.
625
+
626
+ ## Usage and Limitations
627
+
628
+ These models have certain limitations that users should be aware of.
629
+
630
+ ### Intended Usage
631
+
632
+ Open generative models have a wide range of applications across various
633
+ industries and domains. The following list of potential uses is not
634
+ comprehensive. The purpose of this list is to provide contextual information
635
+ about the possible use-cases that the model creators considered as part of model
636
+ training and development.
637
+
638
+ - Content Creation and Communication
639
+ - **Text Generation**: Generate creative text formats such as
640
+ poems, scripts, code, marketing copy, and email drafts.
641
+ - **Chatbots and Conversational AI**: Power conversational
642
+ interfaces for customer service, virtual assistants, or interactive
643
+ applications.
644
+ - **Text Summarization**: Generate concise summaries of a text
645
+ corpus, research papers, or reports.
646
+ - **Image Data Extraction**: Extract, interpret, and summarize
647
+ visual data for text communications.
648
+ - **Audio Data Extraction**: Transcribe spoken language, translate speech
649
+ to text in other languages, and analyze sound-based data.
650
+ - Research and Education
651
+ - **Natural Language Processing (NLP) and generative model
652
+ Research**: These models can serve as a foundation for researchers to
653
+ experiment with generative models and NLP techniques, develop
654
+ algorithms, and contribute to the advancement of the field.
655
+ - **Language Learning Tools**: Support interactive language
656
+ learning experiences, aiding in grammar correction or providing writing
657
+ practice.
658
+ - **Knowledge Exploration**: Assist researchers in exploring large
659
+ bodies of data by generating summaries or answering questions about
660
+ specific topics.
661
+
662
+ ### Limitations
663
+
664
+ - Training Data
665
+ - The quality and diversity of the training data significantly
666
+ influence the model's capabilities. Biases or gaps in the training data
667
+ can lead to limitations in the model's responses.
668
+ - The scope of the training dataset determines the subject areas
669
+ the model can handle effectively.
670
+ - Context and Task Complexity
671
+ - Models are better at tasks that can be framed with clear
672
+ prompts and instructions. Open-ended or highly complex tasks might be
673
+ challenging.
674
+ - A model's performance can be influenced by the amount of context
675
+ provided (longer context generally leads to better outputs, up to a
676
+ certain point).
677
+ - Language Ambiguity and Nuance
678
+ - Natural language is inherently complex. Models might struggle
679
+ to grasp subtle nuances, sarcasm, or figurative language.
680
+ - Factual Accuracy
681
+ - Models generate responses based on information they learned
682
+ from their training datasets, but they are not knowledge bases. They
683
+ may generate incorrect or outdated factual statements.
684
+ - Common Sense
685
+ - Models rely on statistical patterns in language. They might
686
+ lack the ability to apply common sense reasoning in certain situations.
687
+
688
+ ### Ethical Considerations and Risks
689
+
690
+ The development of generative models raises several ethical concerns. In
691
+ creating an open model, we have carefully considered the following:
692
+
693
+ - Bias and Fairness
694
+ - Generative models trained on large-scale, real-world text and image data
695
+ can reflect socio-cultural biases embedded in the training material.
696
+ These models underwent careful scrutiny, input data pre-processing
697
+ described and posterior evaluations reported in this card.
698
+ - Misinformation and Misuse
699
+ - Generative models can be misused to generate text that is
700
+ false, misleading, or harmful.
701
+ - Guidelines are provided for responsible use with the model, see the
702
+ [Responsible Generative AI Toolkit](https://ai.google.dev/responsible).
703
+ - Transparency and Accountability:
704
+ - This model card summarizes details on the models' architecture,
705
+ capabilities, limitations, and evaluation processes.
706
+ - A responsibly developed open model offers the opportunity to
707
+ share innovation by making generative model technology accessible to
708
+ developers and researchers across the AI ecosystem.
709
+
710
+ Risks identified and mitigations:
711
+
712
+ - **Perpetuation of biases**: It's encouraged to perform continuous monitoring
713
+ (using evaluation metrics, human review) and the exploration of de-biasing
714
+ techniques during model training, fine-tuning, and other use cases.
715
+ - **Generation of harmful content**: Mechanisms and guidelines for content
716
+ safety are essential. Developers are encouraged to exercise caution and
717
+ implement appropriate content safety safeguards based on their specific
718
+ product policies and application use cases.
719
+ - **Misuse for malicious purposes**: Technical limitations and developer
720
+ and end-user education can help mitigate against malicious applications of
721
+ generative models. Educational resources and reporting mechanisms for users
722
+ to flag misuse are provided. Prohibited uses of Gemma models are outlined
723
+ in the
724
+ [Gemma Prohibited Use Policy](https://ai.google.dev/gemma/prohibited_use_policy).
725
+ - **Privacy violations**: Models were trained on data filtered for removal of
726
+ certain personal information and other sensitive data. Developers are
727
+ encouraged to adhere to privacy regulations with privacy-preserving
728
+ techniques.
729
+
730
+ ### Benefits
731
+
732
+ At the time of release, this family of models provides high-performance open
733
+ generative model implementations designed from the ground up for responsible AI
734
+ development compared to similarly sized models.
735
+
736
+ Using the benchmark evaluation metrics described in this document, these models
737
+ have shown to provide superior performance to other, comparably-sized open model
738
+ alternatives.
chat_template.jinja ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{ bos_token }}
2
+ {%- if messages[0]['role'] == 'system' -%}
3
+ {%- if messages[0]['content'] is string -%}
4
+ {%- set first_user_prefix = messages[0]['content'] + '
5
+
6
+ ' -%}
7
+ {%- else -%}
8
+ {%- set first_user_prefix = messages[0]['content'][0]['text'] + '
9
+
10
+ ' -%}
11
+ {%- endif -%}
12
+ {%- set loop_messages = messages[1:] -%}
13
+ {%- else -%}
14
+ {%- set first_user_prefix = "" -%}
15
+ {%- set loop_messages = messages -%}
16
+ {%- endif -%}
17
+ {%- for message in loop_messages -%}
18
+ {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
19
+ {{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
20
+ {%- endif -%}
21
+ {%- if (message['role'] == 'assistant') -%}
22
+ {%- set role = "model" -%}
23
+ {%- else -%}
24
+ {%- set role = message['role'] -%}
25
+ {%- endif -%}
26
+ {{ '<start_of_turn>' + role + '
27
+ ' + (first_user_prefix if loop.first else "") }}
28
+ {%- if message['content'] is string -%}
29
+ {{ message['content'] | trim }}
30
+ {%- elif message['content'] is iterable -%}
31
+ {%- for item in message['content'] -%}
32
+ {%- if item['type'] == 'audio' -%}
33
+ {{ '<audio_soft_token>' }}
34
+ {%- elif item['type'] == 'image' -%}
35
+ {{ '<image_soft_token>' }}
36
+ {%- elif item['type'] == 'text' -%}
37
+ {{ item['text'] | trim }}
38
+ {%- endif -%}
39
+ {%- endfor -%}
40
+ {%- else -%}
41
+ {{ raise_exception("Invalid content type") }}
42
+ {%- endif -%}
43
+ {{ '<end_of_turn>
44
+ ' }}
45
+ {%- endfor -%}
46
+ {%- if add_generation_prompt -%}
47
+ {{'<start_of_turn>model
48
+ '}}
49
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Gemma3nForConditionalGeneration"
4
+ ],
5
+ "audio_config": {
6
+ "conf_attention_chunk_size": 12,
7
+ "conf_attention_context_left": 13,
8
+ "conf_attention_context_right": 0,
9
+ "conf_attention_invalid_logits_value": -1000000000.0,
10
+ "conf_attention_logit_cap": 50.0,
11
+ "conf_conv_kernel_size": 5,
12
+ "conf_num_attention_heads": 8,
13
+ "conf_num_hidden_layers": 12,
14
+ "conf_positional_bias_size": 256,
15
+ "conf_reduction_factor": 4,
16
+ "conf_residual_weight": 0.5,
17
+ "gradient_clipping": 10000000000.0,
18
+ "hidden_size": 1536,
19
+ "input_feat_size": 128,
20
+ "model_type": "gemma3n_audio",
21
+ "rms_norm_eps": 1e-06,
22
+ "sscp_conv_channel_size": [
23
+ 128,
24
+ 32
25
+ ],
26
+ "sscp_conv_eps": 0.001,
27
+ "sscp_conv_kernel_size": [
28
+ [
29
+ 3,
30
+ 3
31
+ ],
32
+ [
33
+ 3,
34
+ 3
35
+ ]
36
+ ],
37
+ "sscp_conv_stride_size": [
38
+ [
39
+ 2,
40
+ 2
41
+ ],
42
+ [
43
+ 2,
44
+ 2
45
+ ]
46
+ ],
47
+ "torch_dtype": "float32",
48
+ "vocab_size": 128
49
+ },
50
+ "audio_soft_tokens_per_image": 188,
51
+ "audio_token_id": 262273,
52
+ "boa_token_id": 256000,
53
+ "boi_token_id": 255999,
54
+ "eoa_token_id": 262272,
55
+ "eoi_token_id": 262144,
56
+ "eos_token_id": [
57
+ 1,
58
+ 106
59
+ ],
60
+ "image_token_id": 262145,
61
+ "initializer_range": 0.02,
62
+ "model_type": "gemma3n",
63
+ "text_config": {
64
+ "activation_sparsity_pattern": [
65
+ 0.95,
66
+ 0.95,
67
+ 0.95,
68
+ 0.95,
69
+ 0.95,
70
+ 0.95,
71
+ 0.95,
72
+ 0.95,
73
+ 0.95,
74
+ 0.95,
75
+ 0.0,
76
+ 0.0,
77
+ 0.0,
78
+ 0.0,
79
+ 0.0,
80
+ 0.0,
81
+ 0.0,
82
+ 0.0,
83
+ 0.0,
84
+ 0.0,
85
+ 0.0,
86
+ 0.0,
87
+ 0.0,
88
+ 0.0,
89
+ 0.0,
90
+ 0.0,
91
+ 0.0,
92
+ 0.0,
93
+ 0.0,
94
+ 0.0
95
+ ],
96
+ "altup_active_idx": 0,
97
+ "altup_coef_clip": 120.0,
98
+ "altup_correct_scale": true,
99
+ "altup_lr_multiplier": 1.0,
100
+ "altup_num_inputs": 4,
101
+ "attention_bias": false,
102
+ "attention_dropout": 0.0,
103
+ "attn_logit_softcapping": null,
104
+ "final_logit_softcapping": 30.0,
105
+ "head_dim": 256,
106
+ "hidden_activation": "gelu_pytorch_tanh",
107
+ "hidden_size": 2048,
108
+ "hidden_size_per_layer_input": 256,
109
+ "initializer_range": 0.02,
110
+ "intermediate_size": 8192,
111
+ "laurel_rank": 64,
112
+ "layer_types": [
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
+ "full_attention",
123
+ "sliding_attention",
124
+ "sliding_attention",
125
+ "sliding_attention",
126
+ "sliding_attention",
127
+ "full_attention",
128
+ "sliding_attention",
129
+ "sliding_attention",
130
+ "sliding_attention",
131
+ "sliding_attention",
132
+ "full_attention",
133
+ "sliding_attention",
134
+ "sliding_attention",
135
+ "sliding_attention",
136
+ "sliding_attention",
137
+ "full_attention",
138
+ "sliding_attention",
139
+ "sliding_attention",
140
+ "sliding_attention",
141
+ "sliding_attention",
142
+ "full_attention"
143
+ ],
144
+ "max_position_embeddings": 32768,
145
+ "model_type": "gemma3n_text",
146
+ "num_attention_heads": 8,
147
+ "num_hidden_layers": 30,
148
+ "num_key_value_heads": 2,
149
+ "num_kv_shared_layers": 10,
150
+ "query_pre_attn_scalar": 256,
151
+ "rms_norm_eps": 1e-06,
152
+ "rope_local_base_freq": 10000.0,
153
+ "rope_scaling": null,
154
+ "rope_theta": 1000000.0,
155
+ "sliding_window": 512,
156
+ "torch_dtype": "float32",
157
+ "use_cache": true,
158
+ "vocab_size": 262144
159
+ },
160
+ "torch_dtype": "float32",
161
+ "transformers_version": "4.53.0.dev0",
162
+ "transformers.js_config": {
163
+ "use_external_data_format": {
164
+ "audio_encoder.onnx": 1,
165
+ "embed_tokens.onnx": 1,
166
+ "embed_tokens_fp16.onnx": 1,
167
+ "embed_tokens_int8.onnx": 1,
168
+ "embed_tokens_uint8.onnx": 1,
169
+ "embed_tokens_quantized.onnx": 2,
170
+ "decoder_model_merged.onnx": 1,
171
+ "decoder_model_merged_fp16.onnx": 1,
172
+ "vision_encoder.onnx": 1
173
+ },
174
+ "dtype": {
175
+ "embed_tokens": "q8",
176
+ "decoder_model_merged": "q4"
177
+ }
178
+ },
179
+ "vision_config": {
180
+ "architecture": "mobilenetv5_enc",
181
+ "do_pooling": true,
182
+ "hidden_size": 2048,
183
+ "initializer_range": 0.02,
184
+ "label_names": [
185
+ "LABEL_0",
186
+ "LABEL_1"
187
+ ],
188
+ "model_type": "gemma3n_vision",
189
+ "num_classes": 2,
190
+ "torch_dtype": "float32",
191
+ "vocab_size": 128
192
+ },
193
+ "vision_soft_tokens_per_image": 256
194
+ }
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 2,
3
+ "cache_implementation": "hybrid",
4
+ "do_sample": true,
5
+ "eos_token_id": [
6
+ 1,
7
+ 106
8
+ ],
9
+ "pad_token_id": 0,
10
+ "top_k": 64,
11
+ "top_p": 0.95,
12
+ "transformers_version": "4.53.0.dev0"
13
+ }
onnx/audio_encoder.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9bf2bd244e47512209e97dd03a8ced93b771aefbc7976e4dffa95dc26a46e834
3
+ size 574186
onnx/audio_encoder.onnx_data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f1ef1d1f5ca8fdf754ca310f4941810518ed9b5d95311071a2faa95f9317fb78
3
+ size 2738092544
onnx/audio_encoder_fp16.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f4b9f9743736f14a65fc90c36099d5d537a1f7630f6279b35367fa71e1c24c0a
3
+ size 1369532994
onnx/audio_encoder_int8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d08cebb815f95957830f0e4c8ad5236633684193394d9fe78b03834de49af6d3
3
+ size 685768656
onnx/audio_encoder_q4.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9bc02b241faaa00e336191241e9a12692ef6e91a8c46333c149143eec69127bc
3
+ size 429503628
onnx/audio_encoder_q4f16.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:032ea8b096cc786bd64fc91be0b289c1ec090d8bf7d4b66950c89c0024a0abf7
3
+ size 386021189
onnx/audio_encoder_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e97d41ceaf872e6c086a329c30f9cee65ac76e496b0f33d0063f084ce1b3ce63
3
+ size 685768729
onnx/audio_encoder_uint8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e97d41ceaf872e6c086a329c30f9cee65ac76e496b0f33d0063f084ce1b3ce63
3
+ size 685768729
onnx/decoder_model_merged.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6667abc5aad8c619e32b97d5810e127a85993dc9bbddb5f6d4ac5552372ea725
3
+ size 3097473
onnx/decoder_model_merged.onnx_data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:251cb348af5bdfa3dfc8927b4a3661fe982f44ea3d912958f353a53e23e59b18
3
+ size 9685536768
onnx/decoder_model_merged_fp16.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d17037e16fe8113d36e9abe0162a636a4fc83eef049f76cf3da00629186eb58a
3
+ size 3124259
onnx/decoder_model_merged_fp16.onnx_data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:67701dd9c9f2ff9816f328857b823aa58cc5af76a252218390fe8446c6a626e9
3
+ size 4842754048
onnx/decoder_model_merged_q4.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7659477568fb3f5a435467b90aa37587b4c517e089c9c21001a9cecf1f332318
3
+ size 1518206957
onnx/decoder_model_merged_q4f16.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c322cb1383546c11d04cd1e4d221bbe9060e4a94963aa95052caf5c24576acab
3
+ size 1367169309
onnx/embed_tokens.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c8e909884c67470deb1f45cba980e9be920e1d462483aacc1f033e924b1b99b
3
+ size 24096
onnx/embed_tokens.onnx_data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:41496f3e27c6e3a05c6b0a4c920ab5feb801a61573271e4e0dc8fe375aee307e
3
+ size 10231756800
onnx/embed_tokens_fp16.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:421caccd14d4b9c23f61777a411ec279be3b683ae167dd4f1f2c1311cf63ceea
3
+ size 24294
onnx/embed_tokens_fp16.onnx_data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef1d95f6dc54561f482f63c36b952ebb42e19c218b210f82a35e621c1c791c42
3
+ size 5115878400
onnx/embed_tokens_int8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4eb81b7edee8dd69a8dd2da128f538f036e8a8e195fbd88334d068eccc9b7a92
3
+ size 37469
onnx/embed_tokens_int8.onnx_data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9f3681c4674f7a9d622f26de9facb2361f45d975c376cc84908ea51c4fdb2671
3
+ size 2557949952
onnx/embed_tokens_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c825362923452ea0e84fe4ad36fc403435727fa6f70d7e62a25ce65b460ca596
3
+ size 829132
onnx/embed_tokens_quantized.onnx_data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:042ac572db0ab810be89075850a33cbbae1e58a9f1725b9cfad2b1ac1afedb09
3
+ size 584056832
onnx/embed_tokens_quantized.onnx_data_1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cd6255ac239a73db0da6a3f829b3105e0bafdd146ff5459cd57e8cb9746c5f3a
3
+ size 2076180480
onnx/embed_tokens_uint8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a2d08faa32d867b176039c7187670c680f0506c13d6ab017e5265d0c41d2fc4e
3
+ size 37477
onnx/embed_tokens_uint8.onnx_data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8fd1802008b547d884a3f0ccf5577331bea0e12d44caca52cae491ecba801917
3
+ size 2557949952
onnx/vision_encoder.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:827bf4aeb6e6df7bd8034fd9d376c3e9bf2ee4529dc6e8e53df4be5b5feebfaa
3
+ size 1243721
onnx/vision_encoder.onnx_data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:44bc629382fa2a35b4311cf5bb47e491153768b074d339e3b4f4c9781d82d032
3
+ size 1194281728
onnx/vision_encoder_fp16.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cb287b5cf96471f082ad148e56b2a0ef998759d64e0515f41bcbdc96c294ccf1
3
+ size 606875188
onnx/vision_encoder_int8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:319f0ad13f54efdb6444ab7756701cc9c729ea88b7164b2b0e565651f7e14ec3
3
+ size 301671895
onnx/vision_encoder_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f9fa5670686d5e5b6ed1215033da5194e83cca4410fd134346f623900ca4ad1d
3
+ size 300879908
onnx/vision_encoder_uint8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:49109faefd77424060d1bfc4037190a17a3634e3b05e639630d3f833bde0dff8
3
+ size 301672063
preprocessor_config.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "crop_size": null,
3
+ "data_format": "channels_first",
4
+ "default_to_square": false,
5
+ "device": null,
6
+ "dither": 0.0,
7
+ "do_center_crop": null,
8
+ "do_convert_rgb": null,
9
+ "do_normalize": false,
10
+ "do_rescale": true,
11
+ "do_resize": true,
12
+ "feature_extractor_type": "Gemma3nAudioFeatureExtractor",
13
+ "feature_size": 128,
14
+ "fft_length": 1024,
15
+ "fft_overdrive": true,
16
+ "frame_length": 512,
17
+ "hop_length": 160,
18
+ "image_mean": [
19
+ 0.5,
20
+ 0.5,
21
+ 0.5
22
+ ],
23
+ "image_processor_type": "SiglipImageProcessorFast",
24
+ "image_seq_length": 256,
25
+ "image_std": [
26
+ 0.5,
27
+ 0.5,
28
+ 0.5
29
+ ],
30
+ "input_data_format": null,
31
+ "input_scale_factor": 1.0,
32
+ "max_frequency": 7600.0,
33
+ "mel_floor": 1e-05,
34
+ "min_frequency": 125.0,
35
+ "padding_side": "right",
36
+ "padding_value": 0.0,
37
+ "per_bin_mean": null,
38
+ "per_bin_stddev": null,
39
+ "preemphasis": 0.97,
40
+ "preemphasis_htk_flavor": true,
41
+ "processor_class": "Gemma3nProcessor",
42
+ "resample": 2,
43
+ "rescale_factor": 0.00392156862745098,
44
+ "return_attention_mask": false,
45
+ "return_tensors": null,
46
+ "sampling_rate": 16000,
47
+ "size": {
48
+ "height": 768,
49
+ "width": 768
50
+ }
51
+ }
processor_config.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "audio_seq_length": 188,
3
+ "image_seq_length": 256,
4
+ "processor_class": "Gemma3nProcessor"
5
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "audio_token": "<audio_soft_token>",
3
+ "boa_token": "<start_of_audio>",
4
+ "boi_token": "<start_of_image>",
5
+ "bos_token": {
6
+ "content": "<bos>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "eoa_token": "<end_of_audio>",
13
+ "eoi_token": "<end_of_image>",
14
+ "eos_token": {
15
+ "content": "<eos>",
16
+ "lstrip": false,
17
+ "normalized": false,
18
+ "rstrip": false,
19
+ "single_word": false
20
+ },
21
+ "image_token": "<image_soft_token>",
22
+ "pad_token": {
23
+ "content": "<pad>",
24
+ "lstrip": false,
25
+ "normalized": false,
26
+ "rstrip": false,
27
+ "single_word": false
28
+ },
29
+ "unk_token": {
30
+ "content": "<unk>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false
35
+ }
36
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b6c35ee648c07754b44cd9e371c75d4caa05c4504910b7ad29b1847ee9d8ba5d
3
+ size 33442553
tokenizer_config.json ADDED
The diff for this file is too large to render. See raw diff