llmfan46 commited on
Commit
027bb36
·
verified ·
1 Parent(s): 099ff66

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +81 -64
README.md CHANGED
@@ -232,21 +232,29 @@ GGUF quantizations available here [llmfan46/gemma-4-31B-it-qat-q4_0-uncensored-h
232
  <p align="center">
233
  <a href="https://huggingface.co/collections/google/gemma-4" target="_blank">Hugging Face</a> |
234
  <a href="https://github.com/google-gemma" target="_blank">GitHub</a> |
235
- <a href="https://blog.google/innovation-and-ai/technology/developers-tools/gemma-4/" target="_blank">Launch Blog</a> |
236
  <a href="https://ai.google.dev/gemma/docs/core" target="_blank">Documentation</a>
237
  <br>
238
  <b>License</b>: <a href="https://ai.google.dev/gemma/docs/gemma_4_license" target="_blank">Apache 2.0</a> | <b>Authors</b>: <a href="https://deepmind.google/models/gemma/" target="_blank">Google DeepMind</a>
239
  </p>
240
 
241
- Gemma is a family of open models built by Google DeepMind. Gemma 4 models are multimodal, handling text and image input (with audio supported on small models) and generating text output. This release includes open-weights models in both pre-trained and instruction-tuned variants. Gemma 4 features a context window of up to 256K tokens and maintains multilingual support in over 140 languages.
 
 
 
 
 
 
 
 
242
 
243
- Featuring both Dense and Mixture-of-Experts (MoE) architectures, Gemma 4 is well-suited for tasks like text generation, coding, and reasoning. The models are available in four distinct sizes: **E2B**, **E4B**, **26B A4B**, and **31B**. Their diverse sizes make them deployable in environments ranging from high-end phones to laptops and servers, democratizing access to state-of-the-art AI.
244
 
245
  Gemma 4 introduces key **capability and architectural advancements**:
246
 
247
  * **Reasoning** – All models in the family are designed as highly capable reasoners, with configurable thinking modes.
248
 
249
- * **Extended Multimodalities** – Processes Text, Image with variable aspect ratio and resolution support (all models), Video, and Audio (featured natively on the E2B and E4B models).
250
 
251
  * **Diverse & Efficient Architectures** – Offers Dense and Mixture-of-Experts (MoE) variants of different sizes for scalable deployment.
252
 
@@ -260,25 +268,27 @@ Gemma 4 introduces key **capability and architectural advancements**:
260
 
261
  ## **Models Overview**
262
 
263
- Gemma 4 models are designed to deliver frontier-level performance at each size, targeting deployment scenarios from mobile and edge devices (E2B, E4B) to consumer GPUs and workstations (26B A4B, 31B). They are well-suited for reasoning, agentic workflows, coding, and multimodal understanding.
264
 
265
  The models employ a hybrid attention mechanism that interleaves local sliding window attention with full global attention, ensuring the final layer is always global. This hybrid design delivers the processing speed and low memory footprint of a lightweight model without sacrificing the deep awareness required for complex, long-context tasks. To optimize memory for long contexts, global layers feature unified Keys and Values, and apply Proportional RoPE (p-RoPE).
266
 
267
  ### Dense Models
268
 
269
- | Property | E2B | E4B | 31B Dense |
270
- | :---- | :---- | :---- | :---- |
271
- | **Total Parameters** | 2.3B effective (5.1B with embeddings) | 4.5B effective (8B with embeddings) | 30.7B |
272
- | **Layers** | 35 | 42 | 60 |
273
- | **Sliding Window** | 512 tokens | 512 tokens | 1024 tokens |
274
- | **Context Length** | 128K tokens | 128K tokens | 256K tokens |
275
- | **Vocabulary Size** | 262K | 262K | 262K |
276
- | **Supported Modalities** | Text, Image, Audio | Text, Image, Audio | Text, Image |
277
- | **Vision Encoder Parameters** | *~150M* | *~150M* | *~550M* |
278
- | **Audio Encoder Parameters** | *~300M* | *~300M* | No Audio |
279
 
280
  The "E" in E2B and E4B stands for "effective" parameters. The smaller models incorporate Per-Layer Embeddings (PLE) to maximize parameter efficiency in on-device deployments. Rather than adding more layers or parameters to the model, PLE gives each decoder layer its own small embedding for every token. These embedding tables are large but are only used for quick lookups, which is why the effective parameter count is much smaller than the total.
281
 
 
 
282
  ### Mixture-of-Experts (MoE) Model
283
 
284
  | Property | 26B A4B MoE |
@@ -299,42 +309,45 @@ The "A" in 26B A4B stands for "active parameters" in contrast to the total numbe
299
 
300
  These models were evaluated against a large collection of different datasets and metrics to cover different aspects of text generation. Evaluation results marked in the table are for instruction-tuned models.
301
 
302
- | | Gemma 4 31B | Gemma 4 26B A4B | Gemma 4 E4B | Gemma 4 E2B | Gemma 3 27B (no think) |
303
- | :---- | :---- | :---- | :---- | :---- | :---- |
304
- | MMLU Pro | 85.2% | 82.6% | 69.4% | 60.0% | 67.6% |
305
- | AIME 2026 no tools | 89.2% | 88.3% | 42.5% | 37.5% | 20.8% |
306
- | LiveCodeBench v6 | 80.0% | 77.1% | 52.0% | 44.0% | 29.1% |
307
- | Codeforces ELO | 2150 | 1718 | 940 | 633 | 110 |
308
- | GPQA Diamond | 84.3% | 82.3% | 58.6% | 43.4% | 42.4% |
309
- | Tau2 (average over 3) | 76.9% | 68.2% | 42.2% | 24.5% | 16.2% |
310
- | HLE no tools | 19.5% | 8.7% | - | - | - |
311
- | HLE with search | 26.5% | 17.2% | - | - | - |
312
- | BigBench Extra Hard | 74.4% | 64.8% | 33.1% | 21.9% | 19.3% |
313
- | MMMLU | 88.4% | 86.3% | 76.6% | 67.4% | 70.7% |
314
- | **Vision** | | | | | |
315
- | MMMU Pro | 76.9% | 73.8% | 52.6% | 44.2% | 49.7% |
316
- | OmniDocBench 1.5 (average edit distance, lower is better) | 0.131 | 0.149 | 0.181 | 0.290 | 0.365 |
317
- | MATH-Vision | 85.6% | 82.4% | 59.5% | 52.4% | 46.0% |
318
- | MedXPertQA MM | 61.3% | 58.1% | 28.7% | 23.5% | - |
319
- | **Audio** | | | | | |
320
- | CoVoST | - | - | 35.54 | 33.47 | - |
321
- | FLEURS (lower is better) | - | - | 0.08 | 0.09 | - |
322
- | **Long Context** | | | | | |
323
- | MRCR v2 8 needle 128k (average) | 66.4% | 44.1% | 25.4% | 19.1% | 13.5% |
 
 
324
 
325
  ## **Core Capabilities**
326
 
327
  Gemma 4 models handle a broad range of tasks across text, vision, and audio. Key capabilities include:
328
 
329
  * **Thinking** – Built-in reasoning mode that lets the model think step-by-step before answering.
330
- * **Long Context** – Context windows of up to 128K tokens (E2B/E4B) and 256K tokens (26B A4B/31B).
331
  * **Image Understanding** – Object detection, Document/PDF parsing, screen and UI understanding, chart comprehension, OCR (including multilingual), handwriting recognition, and pointing. Images can be processed at variable aspect ratios and resolutions.
332
  * **Video Understanding** – Analyze video by processing sequences of frames.
333
  * **Interleaved Multimodal Input** – Freely mix text and images in any order within a single prompt.
334
  * **Function Calling** – Native support for structured tool use, enabling agentic workflows.
335
  * **Coding** – Code generation, completion, and correction.
336
  * **Multilingual** – Out-of-the-box support for 35+ languages, pre-trained on 140+ languages.
337
- * **Audio** (E2B and E4B only) – Automatic speech recognition (ASR) and speech-to-translated-text translation across multiple languages.
 
338
 
339
  ## Getting Started
340
 
@@ -345,13 +358,13 @@ You can use all Gemma 4 models with the latest version of Transformers. To get s
345
  Once you have everything installed, you can proceed to load the model with the code below:
346
 
347
  ```python
348
- from transformers import AutoProcessor, AutoModelForCausalLM
349
 
350
- MODEL_ID = "google/gemma-4-31B-it"
351
 
352
  # Load model
353
  processor = AutoProcessor.from_pretrained(MODEL_ID)
354
- model = AutoModelForCausalLM.from_pretrained(
355
  MODEL_ID,
356
  dtype="auto",
357
  device_map="auto"
@@ -368,13 +381,14 @@ messages = [
368
  ]
369
 
370
  # Process input
371
- text = processor.apply_chat_template(
372
- messages,
373
- tokenize=False,
374
- add_generation_prompt=True,
 
 
375
  enable_thinking=False
376
- )
377
- inputs = processor(text=text, return_tensors="pt").to(model.device)
378
  input_len = inputs["input_ids"].shape[-1]
379
 
380
  # Generate output
@@ -387,22 +401,21 @@ processor.parse_response(response)
387
 
388
  To enable reasoning, set `enable_thinking=True` and the `parse_response` function will take care of parsing the thinking output.
389
 
390
- Below, you will also find snippets for processing audio (E2B and E4B only), images, and video alongside text:
391
 
392
  <details>
393
  <summary>Code for processing Audio</summary>
394
 
395
- Instead of using `AutoModelForCausalLM`, you can use `AutoModelForMultimodalLM` to process audio. To use it, make sure to install the following packages:
396
-
397
 
398
- `pip install -U transformers torch librosa accelerate`
399
 
400
  You can then load the model with the code below:
401
 
402
  ```python
403
  from transformers import AutoProcessor, AutoModelForMultimodalLM
404
 
405
- MODEL_ID = "google/gemma-4-E2B-it"
406
 
407
  # Load model
408
  processor = AutoProcessor.from_pretrained(MODEL_ID)
@@ -417,13 +430,13 @@ Once the model is loaded, you can start generating output by directly referencin
417
 
418
 
419
  ```python
420
- # Prompt - add audio before text
421
  messages = [
422
  {
423
  "role": "user",
424
  "content": [
425
- {"type": "audio", "audio": "https://raw.githubusercontent.com/google-gemma/cookbook/refs/heads/main/Demos/sample-data/journal1.wav"},
426
  {"type": "text", "text": "Transcribe the following speech segment in its original language. Follow these specific instructions for formatting the answer:\n* Only output the transcription, with no newlines.\n* When transcribing numbers, write the digits, i.e. write 1.7 and not one point seven, and write 3 instead of three."},
 
427
  ]
428
  }
429
  ]
@@ -451,7 +464,7 @@ processor.parse_response(response)
451
  <details>
452
  <summary>Code for processing Images</summary>
453
 
454
- Instead of using `AutoModelForCausalLM`, you can use `AutoModelForMultimodalLM` to process images. To use it, make sure to install the following packages:
455
 
456
 
457
  `pip install -U transformers torch torchvision accelerate`
@@ -461,7 +474,7 @@ You can then load the model with the code below:
461
  ```python
462
  from transformers import AutoProcessor, AutoModelForMultimodalLM
463
 
464
- MODEL_ID = "google/gemma-4-31B-it"
465
 
466
  # Load model
467
  processor = AutoProcessor.from_pretrained(MODEL_ID)
@@ -480,7 +493,7 @@ Once the model is loaded, you can start generating output by directly referencin
480
  messages = [
481
  {
482
  "role": "user", "content": [
483
- {"type": "image", "url": "https://raw.githubusercontent.com/google-gemma/cookbook/refs/heads/main/Demos/sample-data/GoldenGate.png"},
484
  {"type": "text", "text": "What is shown in this image?"}
485
  ]
486
  }
@@ -510,16 +523,16 @@ processor.parse_response(response)
510
  <details>
511
  <summary>Code for processing Videos</summary>
512
 
513
- Instead of using `AutoModelForCausalLM`, you can use `AutoModelForMultimodalLM` to process videos. To use it, make sure to install the following packages:
514
 
515
- `pip install -U transformers torch torchvision torchcodec librosa accelerate`
516
 
517
  You can then load the model with the code below:
518
 
519
  ```python
520
  from transformers import AutoProcessor, AutoModelForMultimodalLM
521
 
522
- MODEL_ID = "google/gemma-4-31B-it"
523
 
524
  # Load model
525
  processor = AutoProcessor.from_pretrained(MODEL_ID)
@@ -566,6 +579,7 @@ processor.parse_response(response)
566
  </details>
567
 
568
 
 
569
  ## **Best Practices**
570
 
571
  For the best performance, use these configurations and best practices:
@@ -597,7 +611,10 @@ Compared to Gemma 3, the models use standard `system`, `assistant`, and `user` r
597
 
598
  ### 4. Modality order
599
 
600
- * For optimal performance with multimodal inputs, place image and/or audio content **before** the text in your prompt.
 
 
 
601
 
602
  ### 5. Variable Image Resolution
603
 
@@ -630,7 +647,7 @@ When formatting the answer, first output the transcription in {SOURCE_LANGUAGE},
630
 
631
  ### 7. Audio and Video Length
632
 
633
- All models support image inputs and can process videos as frames whereas the E2B and E4B models also support audio inputs. Audio supports a maximum length of 30 seconds. Video supports a maximum of 60 seconds assuming the images are processed at one frame per second.
634
 
635
  ## **Model Data**
636
 
@@ -686,7 +703,7 @@ Multimodal models (capable of processing vision, language, and/or audio) have a
686
  * **Chatbots and Conversational AI**: Power conversational interfaces for customer service, virtual assistants, or interactive applications.
687
  * **Text Summarization**: Generate concise summaries of a text corpus, research papers, or reports.
688
  * **Image Data Extraction**: These models can be used to extract, interpret, and summarize visual data for text communications.
689
- * **Audio Processing and Interaction**: The smaller models (E2B and E4B) can analyze and interpret audio inputs, enabling voice-driven interactions and transcriptions.
690
  * **Research and Education**
691
  * **Natural Language Processing (NLP) and VLM Research**: These models can serve as a foundation for researchers to experiment with VLM and NLP techniques, develop algorithms, and contribute to the advancement of the field.
692
  * **Language Learning Tools**: Support interactive language learning experiences, aiding in grammar correction or providing writing practice.
 
232
  <p align="center">
233
  <a href="https://huggingface.co/collections/google/gemma-4" target="_blank">Hugging Face</a> |
234
  <a href="https://github.com/google-gemma" target="_blank">GitHub</a> |
235
+ <a href="https://blog.google/innovation-and-ai/technology/developers-tools/introducing-gemma-4-12B/" target="_blank">Launch Blog</a> |
236
  <a href="https://ai.google.dev/gemma/docs/core" target="_blank">Documentation</a>
237
  <br>
238
  <b>License</b>: <a href="https://ai.google.dev/gemma/docs/gemma_4_license" target="_blank">Apache 2.0</a> | <b>Authors</b>: <a href="https://deepmind.google/models/gemma/" target="_blank">Google DeepMind</a>
239
  </p>
240
 
241
+ > [!Note]
242
+ > This model card is for the new versions of the Gemma 4 family optimized with Quantization-Aware Training (QAT), which allows preserving similar quality to bfloat16 while dramatically reducing the memory requirements to load the model.
243
+ > Four versions of the QAT checkpoints are available:
244
+ > * **Unquantized QAT checkpoints** (Q4_0): Half-precision weights extracted from the QAT pipeline, ideal for custom downstream compilation and research. Available for Gemma 4 E2B, E4B, 12B, 26B A4B, and 31B, and their drafter models.
245
+ > * **GGUF** (Q4_0): Ready-to-deploy formats for broad ecosystem compatibility. Available for Gemma 4 E2B, E4B, 12B, 26B A4B, and 31B.
246
+ > * **Mobile-optimized** (wNa8o8): A custom schema engineered explicitly for mobile hardware efficiency. It features targeted 2-bit decoding layers, optimized KV caches, and static activations to maximize VRAM savings. Available for Gemma 4 E2B and E4B.
247
+ > * **Compressed Tensors** (w4a16): QAT checkpoints serialized in the compressed-tensors format for native, optimized inference with vLLM. Available for Gemma 4 E2B, E4B, 12B, and 31B.
248
+
249
+ Gemma is a family of open models built by Google DeepMind. Gemma 4 models are multimodal, handling text and image input (with audio supported on E2B, E4B, and 12B) and generating text output. This release includes open-weights models in both pre-trained and instruction-tuned variants. Gemma 4 features a context window of up to 256K tokens and maintains multilingual support in over 140 languages.
250
 
251
+ Featuring both Dense and Mixture-of-Experts (MoE) architectures, Gemma 4 is well-suited for tasks like text generation, coding, and reasoning. The models are available in five distinct sizes: **E2B**, **E4B**, **12B**, **26B A4B**, and **31B**. Their diverse sizes make them deployable in environments ranging from high-end phones to laptops and servers, democratizing access to state-of-the-art AI.
252
 
253
  Gemma 4 introduces key **capability and architectural advancements**:
254
 
255
  * **Reasoning** – All models in the family are designed as highly capable reasoners, with configurable thinking modes.
256
 
257
+ * **Extended Multimodalities** – Processes Text, Image with variable aspect ratio and resolution support (all models), Video, and Audio (featured natively on the E2B, E4B, and 12B models).
258
 
259
  * **Diverse & Efficient Architectures** – Offers Dense and Mixture-of-Experts (MoE) variants of different sizes for scalable deployment.
260
 
 
268
 
269
  ## **Models Overview**
270
 
271
+ Gemma 4 models are designed to deliver frontier-level performance at each size, targeting deployment scenarios from mobile and edge devices (E2B, E4B) to consumer GPUs and workstations (12B, 26B A4B, 31B). They are well-suited for reasoning, agentic workflows, coding, and multimodal understanding.
272
 
273
  The models employ a hybrid attention mechanism that interleaves local sliding window attention with full global attention, ensuring the final layer is always global. This hybrid design delivers the processing speed and low memory footprint of a lightweight model without sacrificing the deep awareness required for complex, long-context tasks. To optimize memory for long contexts, global layers feature unified Keys and Values, and apply Proportional RoPE (p-RoPE).
274
 
275
  ### Dense Models
276
 
277
+ | Property | E2B | E4B | 12B Unified | 31B Dense |
278
+ | :---- | :---- | :---- | :---- | :---- |
279
+ | **Total Parameters** | 2.3B effective <br> (5.1B with embeddings) | 4.5B effective <br> (8B with embeddings) | 11.95B | 30.7B |
280
+ | **Layers** | 35 | 42 | 48 | 60 |
281
+ | **Sliding Window** | 512 tokens | 512 tokens | 1024 tokens | 1024 tokens |
282
+ | **Context Length** | 128K tokens | 128K tokens | 256K tokens | 256K tokens |
283
+ | **Vocabulary Size** | 262K | 262K | 262K | 262K |
284
+ | **Supported Modalities** | Text, Image, Audio | Text, Image, Audio | Text, Image, Audio | Text, Image |
285
+ | **Vision Encoder Parameters** | *~150M* | *~150M* | - | *~550M* |
286
+ | **Audio Encoder Parameters** | *~300M* | *~300M* | - | No Audio |
287
 
288
  The "E" in E2B and E4B stands for "effective" parameters. The smaller models incorporate Per-Layer Embeddings (PLE) to maximize parameter efficiency in on-device deployments. Rather than adding more layers or parameters to the model, PLE gives each decoder layer its own small embedding for every token. These embedding tables are large but are only used for quick lookups, which is why the effective parameter count is much smaller than the total.
289
 
290
+ The "Unified" in Gemma 4 12B Unified refers to its encoder-free architecture. Other Gemma 4 models use dedicated encoders to process multimodal data before passing it to the LLM. Gemma 4 12B eliminates these encoders entirely, projecting raw image patches and audio waveforms directly into the LLM's embedding space through lightweight linear layers. This unified approach means all modalities flow straight into a single decoder-only transformer, reducing multimodal latency and allowing the entire model to be fine-tuned in one pass.
291
+
292
  ### Mixture-of-Experts (MoE) Model
293
 
294
  | Property | 26B A4B MoE |
 
309
 
310
  These models were evaluated against a large collection of different datasets and metrics to cover different aspects of text generation. Evaluation results marked in the table are for instruction-tuned models.
311
 
312
+ | | Gemma 4 31B | Gemma 4 26B A4B | Gemma 4 12B Unified | Gemma 4 E4B | Gemma 4 E2B | Gemma 3 27B (no think) |
313
+ | :---- | :---- | :---- | :---- | :---- | :---- | :---- |
314
+ | MMLU Pro | 85.2% | 82.6% | 77.2% | 69.4% | 60.0% | 67.6% |
315
+ | AIME 2026 no tools | 89.2% | 88.3% | 77.5% | 42.5% | 37.5% | 20.8% |
316
+ | LiveCodeBench v6 | 80.0% | 77.1% | 72.0% | 52.0% | 44.0% | 29.1% |
317
+ | Codeforces ELO | 2150 | 1718 | 1659 | 940 | 633 | 110 |
318
+ | GPQA Diamond | 84.3% | 82.3% | 78.8% | 58.6% | 43.4% | 42.4% |
319
+ | Tau2 (average over 3) | 76.9% | 68.2% | 69.0% | 42.2% | 24.5% | 16.2% |
320
+ | HLE no tools | 19.5% | 8.7% | 5.2% | - | - | - |
321
+ | HLE with search | 26.5% | 17.2% | - | - | - | - |
322
+ | BigBench Extra Hard | 74.4% | 64.8% | 53.0% | 33.1% | 21.9% | 19.3% |
323
+ | MMMLU | 88.4% | 86.3% | 83.4% | 76.6% | 67.4% | 70.7% |
324
+ | **Vision** | | | | | | |
325
+ | MMMU Pro | 76.9% | 73.8% | 69.1% | 52.6% | 44.2% | 49.7% |
326
+ | OmniDocBench 1.5 (average edit distance, lower is better) | 0.131 | 0.149 | 0.164 | 0.181 | 0.290 | 0.365 |
327
+ | MATH-Vision | 85.6% | 82.4% | 79.7% | 59.5% | 52.4% | 46.0% |
328
+ | MedXPertQA MM | 61.3% | 58.1% | 48.7% | 28.7% | 23.5% | - |
329
+ | **Audio** | | | | | | |
330
+ | CoVoST | - | - | 38.5<sup>*</sup> | 35.54 | 33.47 | - |
331
+ | FLEURS (lower is better) | - | - | 0.069<sup>*</sup> | 0.08 | 0.09 | - |
332
+ | **Long Context** | | | | | | |
333
+ | MRCR v2 8 needle 128k (average) | 66.4% | 44.1% | 43.4% | 25.4% | 19.1% | 13.5% |
334
+
335
+ <sup>*</sup>Excluding Chinese language.
336
 
337
  ## **Core Capabilities**
338
 
339
  Gemma 4 models handle a broad range of tasks across text, vision, and audio. Key capabilities include:
340
 
341
  * **Thinking** – Built-in reasoning mode that lets the model think step-by-step before answering.
342
+ * **Long Context** – Context windows of up to 128K tokens (E2B/E4B) and 256K tokens (12B, 26B A4B/31B).
343
  * **Image Understanding** – Object detection, Document/PDF parsing, screen and UI understanding, chart comprehension, OCR (including multilingual), handwriting recognition, and pointing. Images can be processed at variable aspect ratios and resolutions.
344
  * **Video Understanding** – Analyze video by processing sequences of frames.
345
  * **Interleaved Multimodal Input** – Freely mix text and images in any order within a single prompt.
346
  * **Function Calling** – Native support for structured tool use, enabling agentic workflows.
347
  * **Coding** – Code generation, completion, and correction.
348
  * **Multilingual** – Out-of-the-box support for 35+ languages, pre-trained on 140+ languages.
349
+ * **Audio** (E2B, E4B, and 12B only) – Automatic speech recognition (ASR) and speech-to-translated-text translation across multiple languages.
350
+
351
 
352
  ## Getting Started
353
 
 
358
  Once you have everything installed, you can proceed to load the model with the code below:
359
 
360
  ```python
361
+ from transformers import AutoProcessor, AutoModelForMultimodalLM
362
 
363
+ MODEL_ID = "google/gemma-4-12B-it"
364
 
365
  # Load model
366
  processor = AutoProcessor.from_pretrained(MODEL_ID)
367
+ model = AutoModelForMultimodalLM.from_pretrained(
368
  MODEL_ID,
369
  dtype="auto",
370
  device_map="auto"
 
381
  ]
382
 
383
  # Process input
384
+ inputs = processor.apply_chat_template(
385
+ messages,
386
+ tokenize=True,
387
+ return_dict=True,
388
+ return_tensors="pt",
389
+ add_generation_prompt=True,
390
  enable_thinking=False
391
+ ).to(model.device)
 
392
  input_len = inputs["input_ids"].shape[-1]
393
 
394
  # Generate output
 
401
 
402
  To enable reasoning, set `enable_thinking=True` and the `parse_response` function will take care of parsing the thinking output.
403
 
404
+ Below, you will also find snippets for processing audio (E2B, E4B, 12B only), images, and video alongside text:
405
 
406
  <details>
407
  <summary>Code for processing Audio</summary>
408
 
409
+ Make sure to install the following packages:
 
410
 
411
+ `pip install -U transformers torch torchvision librosa accelerate`
412
 
413
  You can then load the model with the code below:
414
 
415
  ```python
416
  from transformers import AutoProcessor, AutoModelForMultimodalLM
417
 
418
+ MODEL_ID = "google/gemma-4-12B-it"
419
 
420
  # Load model
421
  processor = AutoProcessor.from_pretrained(MODEL_ID)
 
430
 
431
 
432
  ```python
433
+ # Prompt - add audio after text
434
  messages = [
435
  {
436
  "role": "user",
437
  "content": [
 
438
  {"type": "text", "text": "Transcribe the following speech segment in its original language. Follow these specific instructions for formatting the answer:\n* Only output the transcription, with no newlines.\n* When transcribing numbers, write the digits, i.e. write 1.7 and not one point seven, and write 3 instead of three."},
439
+ {"type": "audio", "audio": "https://raw.githubusercontent.com/google-gemma/cookbook/refs/heads/main/apps/sample-data/journal1.wav"},
440
  ]
441
  }
442
  ]
 
464
  <details>
465
  <summary>Code for processing Images</summary>
466
 
467
+ Make sure to install the following packages:
468
 
469
 
470
  `pip install -U transformers torch torchvision accelerate`
 
474
  ```python
475
  from transformers import AutoProcessor, AutoModelForMultimodalLM
476
 
477
+ MODEL_ID = "google/gemma-4-12B-it"
478
 
479
  # Load model
480
  processor = AutoProcessor.from_pretrained(MODEL_ID)
 
493
  messages = [
494
  {
495
  "role": "user", "content": [
496
+ {"type": "image", "url": "https://raw.githubusercontent.com/google-gemma/cookbook/refs/heads/main/apps/sample-data/GoldenGate.png"},
497
  {"type": "text", "text": "What is shown in this image?"}
498
  ]
499
  }
 
523
  <details>
524
  <summary>Code for processing Videos</summary>
525
 
526
+ Make sure to install the following packages:
527
 
528
+ `pip install -U transformers torch torchvision librosa accelerate`
529
 
530
  You can then load the model with the code below:
531
 
532
  ```python
533
  from transformers import AutoProcessor, AutoModelForMultimodalLM
534
 
535
+ MODEL_ID = "google/gemma-4-12B-it"
536
 
537
  # Load model
538
  processor = AutoProcessor.from_pretrained(MODEL_ID)
 
579
  </details>
580
 
581
 
582
+
583
  ## **Best Practices**
584
 
585
  For the best performance, use these configurations and best practices:
 
611
 
612
  ### 4. Modality order
613
 
614
+ For optimal performance with multimodal inputs, place:
615
+
616
+ * Image content **before** the text in your prompt.
617
+ * Audio content **after** the text in your prompt.
618
 
619
  ### 5. Variable Image Resolution
620
 
 
647
 
648
  ### 7. Audio and Video Length
649
 
650
+ All models support image inputs and can process videos as frames whereas the E2B, E4B, and 12B models also support audio inputs. Audio supports a maximum length of 30 seconds. Video supports a maximum of 60 seconds assuming the images are processed at one frame per second.
651
 
652
  ## **Model Data**
653
 
 
703
  * **Chatbots and Conversational AI**: Power conversational interfaces for customer service, virtual assistants, or interactive applications.
704
  * **Text Summarization**: Generate concise summaries of a text corpus, research papers, or reports.
705
  * **Image Data Extraction**: These models can be used to extract, interpret, and summarize visual data for text communications.
706
+ * **Audio Processing and Interaction**: The E2B, E4B, and 12B models can analyze and interpret audio inputs, enabling voice-driven interactions and transcriptions.
707
  * **Research and Education**
708
  * **Natural Language Processing (NLP) and VLM Research**: These models can serve as a foundation for researchers to experiment with VLM and NLP techniques, develop algorithms, and contribute to the advancement of the field.
709
  * **Language Learning Tools**: Support interactive language learning experiences, aiding in grammar correction or providing writing practice.