LetheanNetwork/lemma-pt
03
1---2library_name: transformers3license: apache-2.04license_link: https://ai.google.dev/gemma/docs/gemma_4_license5pipeline_tag: any-to-any6base_model:7- google/gemma-4-E4B8---9 10<div align="center">11 <img src=https://ai.google.dev/gemma/images/gemma4_banner.png>12</div>13 14 15<p align="center">16 <a href="https://huggingface.co/collections/google/gemma-4" target="_blank">Hugging Face</a> |17 <a href="https://github.com/google-gemma" target="_blank">GitHub</a> |18 <a href="https://blog.google/innovation-and-ai/technology/developers-tools/gemma-4/" target="_blank">Launch Blog</a> |19 <a href="https://ai.google.dev/gemma/docs/core" target="_blank">Documentation</a>20 <br>21 <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>22</p>23 24Gemma 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. 25 26Featuring 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.27 28Gemma 4 introduces key **capability and architectural advancements**:29 30* **Reasoning** – All models in the family are designed as highly capable reasoners, with configurable thinking modes.31 32* **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).33 34* **Diverse & Efficient Architectures** – Offers Dense and Mixture-of-Experts (MoE) variants of different sizes for scalable deployment.35 36* **Optimized for On-Device** – Smaller models are specifically designed for efficient local execution on laptops and mobile devices.37 38* **Increased Context Window** – The small models feature a 128K context window, while the medium models support 256K.39 40* **Enhanced Coding & Agentic Capabilities** – Achieves notable improvements in coding benchmarks alongside native function-calling support, powering highly capable autonomous agents.41 42* **Native System Prompt Support** – Gemma 4 introduces native support for the `system` role, enabling more structured and controllable conversations.43 44## **Models Overview**45 46Gemma 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.47 48The 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). 49 50### Dense Models51 52| Property | E2B | E4B | 31B Dense |53| :---- | :---- | :---- | :---- |54| **Total Parameters** | 2.3B effective (5.1B with embeddings) | 4.5B effective (8B with embeddings) | 30.7B |55| **Layers** | 35 | 42 | 60 |56| **Sliding Window** | 512 tokens | 512 tokens | 1024 tokens |57| **Context Length** | 128K tokens | 128K tokens | 256K tokens |58| **Vocabulary Size** | 262K | 262K | 262K |59| **Supported Modalities** | Text, Image, Audio | Text, Image, Audio | Text, Image |60| **Vision Encoder Parameters** | *~150M* | *~150M* | *~550M* |61| **Audio Encoder Parameters** | *~300M* | *~300M* | No Audio |62 63The "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.64 65### Mixture-of-Experts (MoE) Model66 67| Property | 26B A4B MoE |68| :---- | :---- |69| **Total Parameters** | 25.2B |70| **Active Parameters** | 3.8B |71| **Layers** | 30 |72| **Sliding Window** | 1024 tokens |73| **Context Length** | 256K tokens |74| **Vocabulary Size** | 262K |75| **Expert Count** | 8 active / 128 total and 1 shared |76| **Supported Modalities** | Text, Image |77| **Vision Encoder Parameters** | *~550M* |78 79The "A" in 26B A4B stands for "active parameters" in contrast to the total number of parameters the model contains. By only activating a 4B subset of parameters during inference, the Mixture-of-Experts model runs much faster than its 26B total might suggest. This makes it an excellent choice for fast inference compared to the dense 31B model since it runs almost as fast as a 4B-parameter model.80 81## **Benchmark Results** 82 83These 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.84 85| | Gemma 4 31B | Gemma 4 26B A4B | Gemma 4 E4B | Gemma 4 E2B | Gemma 3 27B (no think) |86| :---- | :---- | :---- | :---- | :---- | :---- |87| MMLU Pro | 85.2% | 82.6% | 69.4% | 60.0% | 67.6% |88| AIME 2026 no tools | 89.2% | 88.3% | 42.5% | 37.5% | 20.8% |89| LiveCodeBench v6 | 80.0% | 77.1% | 52.0% | 44.0% | 29.1% |90| Codeforces ELO | 2150 | 1718 | 940 | 633 | 110 |91| GPQA Diamond | 84.3% | 82.3% | 58.6% | 43.4% | 42.4% |92| Tau2 (average over 3) | 76.9% | 68.2% | 42.2% | 24.5% | 16.2% |93| HLE no tools | 19.5% | 8.7% | - | - | - |94| HLE with search | 26.5% | 17.2% | - | - | - |95| BigBench Extra Hard | 74.4% | 64.8% | 33.1% | 21.9% | 19.3% |96| MMMLU | 88.4% | 86.3% | 76.6% | 67.4% | 70.7% |97| **Vision** | | | | | |98| MMMU Pro | 76.9% | 73.8% | 52.6% | 44.2% | 49.7% |99| OmniDocBench 1.5 (average edit distance, lower is better) | 0.131 | 0.149 | 0.181 | 0.290 | 0.365 |100| MATH-Vision | 85.6% | 82.4% | 59.5% | 52.4% | 46.0% |101| MedXPertQA MM | 61.3% | 58.1% | 28.7% | 23.5% | - |102| **Audio** | | | | | |103| CoVoST | - | - | 35.54 | 33.47 | - |104| FLEURS (lower is better) | - | - | 0.08 | 0.09 | - |105| **Long Context** | | | | | |106| MRCR v2 8 needle 128k (average) | 66.4% | 44.1% | 25.4% | 19.1% | 13.5% |107 108## **Core Capabilities**109 110Gemma 4 models handle a broad range of tasks across text, vision, and audio. Key capabilities include:111 112* **Thinking** – Built-in reasoning mode that lets the model think step-by-step before answering.113* **Long Context** – Context windows of up to 128K tokens (E2B/E4B) and 256K tokens (26B A4B/31B).114* **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.115* **Video Understanding** – Analyze video by processing sequences of frames.116* **Interleaved Multimodal Input** – Freely mix text and images in any order within a single prompt.117* **Function Calling** – Native support for structured tool use, enabling agentic workflows.118* **Coding** – Code generation, completion, and correction.119* **Multilingual** – Out-of-the-box support for 35+ languages, pre-trained on 140+ languages.120* **Audio** (E2B and E4B only) – Automatic speech recognition (ASR) and speech-to-translated-text translation across multiple languages.121 122## Getting Started123 124You can use all Gemma 4 models with the latest version of Transformers. To get started, install the necessary dependencies in your environment:125 126`pip install -U transformers torch accelerate`127 128Once you have everything installed, you can proceed to load the model with the code below:129 130```python131from transformers import AutoProcessor, AutoModelForCausalLM132 133MODEL_ID = "google/gemma-4-E4B-it"134 135# Load model136processor = AutoProcessor.from_pretrained(MODEL_ID)137model = AutoModelForCausalLM.from_pretrained(138 MODEL_ID,139 dtype="auto",140 device_map="auto"141)142```143 144Once the model is loaded, you can start generating output:145 146```python147# Prompt148messages = [149 {"role": "system", "content": "You are a helpful assistant."},150 {"role": "user", "content": "Write a short joke about saving RAM."},151]152 153# Process input154text = processor.apply_chat_template(155 messages, 156 tokenize=False, 157 add_generation_prompt=True, 158 enable_thinking=False159)160inputs = processor(text=text, return_tensors="pt").to(model.device)161input_len = inputs["input_ids"].shape[-1]162 163# Generate output164outputs = model.generate(**inputs, max_new_tokens=1024)165response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)166 167# Parse output168processor.parse_response(response)169```170 171To enable reasoning, set `enable_thinking=True` and the `parse_response` function will take care of parsing the thinking output.172 173Below, you will also find snippets for processing audio (E2B and E4B only), images, and video alongside text:174 175<details>176<summary>Code for processing Audio</summary>177 178Instead of using `AutoModelForCausalLM`, you can use `AutoModelForMultimodalLM` to process audio. To use it, make sure to install the following packages:179 180 181`pip install -U transformers torch torchvision librosa accelerate`182 183You can then load the model with the code below:184 185```python186from transformers import AutoProcessor, AutoModelForMultimodalLM187 188MODEL_ID = "google/gemma-4-E4B-it"189 190# Load model191processor = AutoProcessor.from_pretrained(MODEL_ID)192model = AutoModelForMultimodalLM.from_pretrained(193 MODEL_ID, 194 dtype="auto", 195 device_map="auto"196)197```198 199Once the model is loaded, you can start generating output by directly referencing the audio URL in the prompt:200 201 202```python203# Prompt - add audio before text204messages = [205 {206 "role": "user",207 "content": [208 {"type": "audio", "audio": "https://raw.githubusercontent.com/google-gemma/cookbook/refs/heads/main/Demos/sample-data/journal1.wav"},209 {"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."},210 ]211 }212]213 214# Process input215inputs = processor.apply_chat_template(216 messages,217 tokenize=True,218 return_dict=True,219 return_tensors="pt",220 add_generation_prompt=True,221).to(model.device)222input_len = inputs["input_ids"].shape[-1]223 224# Generate output225outputs = model.generate(**inputs, max_new_tokens=512)226response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)227 228# Parse output229processor.parse_response(response)230```231 232</details>233 234<details>235<summary>Code for processing Images</summary>236 237Instead of using `AutoModelForCausalLM`, you can use `AutoModelForMultimodalLM` to process images. To use it, make sure to install the following packages:238 239 240`pip install -U transformers torch torchvision accelerate`241 242You can then load the model with the code below:243 244```python245from transformers import AutoProcessor, AutoModelForMultimodalLM246 247MODEL_ID = "google/gemma-4-E4B-it"248 249# Load model250processor = AutoProcessor.from_pretrained(MODEL_ID)251model = AutoModelForMultimodalLM.from_pretrained(252 MODEL_ID, 253 dtype="auto", 254 device_map="auto"255)256```257 258Once the model is loaded, you can start generating output by directly referencing the image URL in the prompt:259 260 261```python262# Prompt - add image before text263messages = [264 {265 "role": "user", "content": [266 {"type": "image", "url": "https://raw.githubusercontent.com/google-gemma/cookbook/refs/heads/main/Demos/sample-data/GoldenGate.png"},267 {"type": "text", "text": "What is shown in this image?"}268 ]269 }270]271 272# Process input273inputs = processor.apply_chat_template(274 messages,275 tokenize=True,276 return_dict=True,277 return_tensors="pt",278 add_generation_prompt=True,279).to(model.device)280input_len = inputs["input_ids"].shape[-1]281 282# Generate output283outputs = model.generate(**inputs, max_new_tokens=512)284response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)285 286# Parse output287processor.parse_response(response)288```289 290</details>291 292 293<details>294<summary>Code for processing Videos</summary>295 296Instead of using `AutoModelForCausalLM`, you can use `AutoModelForMultimodalLM` to process videos. To use it, make sure to install the following packages:297 298`pip install -U transformers torch torchvision librosa accelerate`299 300You can then load the model with the code below:301 302```python303from transformers import AutoProcessor, AutoModelForMultimodalLM304 305MODEL_ID = "google/gemma-4-E4B-it"306 307# Load model308processor = AutoProcessor.from_pretrained(MODEL_ID)309model = AutoModelForMultimodalLM.from_pretrained(310 MODEL_ID, 311 dtype="auto", 312 device_map="auto"313)314```315 316Once the model is loaded, you can start generating output by directly referencing the video URL in the prompt:317 318 319```python320# Prompt - add video before text321messages = [322 {323 'role': 'user',324 'content': [325 {"type": "video", "video": "https://github.com/bebechien/gemma/raw/refs/heads/main/videos/ForBiggerBlazes.mp4"},326 {'type': 'text', 'text': 'Describe this video.'}327 ]328 }329]330 331# Process input332inputs = processor.apply_chat_template(333 messages,334 tokenize=True,335 return_dict=True,336 return_tensors="pt",337 add_generation_prompt=True,338).to(model.device)339input_len = inputs["input_ids"].shape[-1]340 341# Generate output342outputs = model.generate(**inputs, max_new_tokens=512)343response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)344 345# Parse output346processor.parse_response(response)347```348 349</details>350 351 352## **Best Practices**353 354For the best performance, use these configurations and best practices:355 356### 1. Sampling Parameters357 358Use the following standardized sampling configuration across all use cases:359 360* `temperature=1.0` 361* `top_p=0.95` 362* `top_k=64`363 364### 2. Thinking Mode Configuration365 366Compared to Gemma 3, the models use standard `system`, `assistant`, and `user` roles. To properly manage the thinking process, use the following control tokens:367 368* **Trigger Thinking:** Thinking is enabled by including the `<|think|>` token at the start of the system prompt. To disable thinking, remove the token. 369* **Standard Generation:** When thinking is enabled, the model will output its internal reasoning followed by the final answer using this structure: 370 `<|channel>thought\n`**[Internal reasoning]**`<channel|>` 371* **Disabled Thinking Behavior:** For all models except for the E2B and E4B variants, if thinking is disabled, the model will still generate the tags but with an empty thought block: 372 `<|channel>thought\n<channel|>`**[Final answer]**373 374> [!Note]375> Note that many libraries like Transformers and llama.cpp handle the complexities of the chat template for you.376 377### 3. Multi-Turn Conversations378 379* **No Thinking Content in History**: In multi-turn conversations, the historical model output should only include the final response. Thoughts from previous model turns must *not be added* before the next user turn begins.380 381### 4. Modality order382 383* For optimal performance with multimodal inputs, place image and/or audio content **before** the text in your prompt. 384 385### 5. Variable Image Resolution386 387Aside from variable aspect ratios, Gemma 4 supports variable image resolution through a configurable visual token budget, which controls how many tokens are used to represent an image. A higher token budget preserves more visual detail at the cost of additional compute, while a lower budget enables faster inference for tasks that don't require fine-grained understanding.388 389* The supported token budgets are: **70**, **140**, **280**, **560**, and **1120**. 390 * Use *lower budgets* for classification, captioning, or video understanding, where faster inference and processing many frames outweigh fine-grained detail. 391 * Use *higher budgets* for tasks like OCR, document parsing, or reading small text.392 393### 6. Audio394 395Use the following prompt structures for audio processing:396 397* **Audio Speech Recognition (ASR)**398 399```text400Transcribe the following speech segment in {LANGUAGE} into {LANGUAGE} text.401 402Follow these specific instructions for formatting the answer:403* Only output the transcription, with no newlines.404* When transcribing numbers, write the digits, i.e. write 1.7 and not one point seven, and write 3 instead of three.405```406 407* **Automatic Speech Translation (AST)**408 409```text410Transcribe the following speech segment in {SOURCE_LANGUAGE}, then translate it into {TARGET_LANGUAGE}.411When formatting the answer, first output the transcription in {SOURCE_LANGUAGE}, then one newline, then output the string '{TARGET_LANGUAGE}: ', then the translation in {TARGET_LANGUAGE}.412```413 414### 7. Audio and Video Length415 416All 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.417 418## **Model Data**419 420Data used for model training and how the data was processed.421 422### **Training Dataset**423 424Our pre-training dataset is a large-scale, diverse collection of data encompassing a wide range of domains and modalities, which includes web documents, code, images, audio, with a cutoff date of January 2025. Here are the key components:425 426* **Web Documents**: A diverse collection of web text ensures the model is exposed to a broad range of linguistic styles, topics, and vocabulary. The training dataset includes content in over 140 languages. 427* **Code**: Exposing the model to code helps it to learn the syntax and patterns of programming languages, which improves its ability to generate code and understand code-related questions. 428* **Mathematics**: Training on mathematical text helps the model learn logical reasoning, symbolic representation, and to address mathematical queries. 429* **Images**: A wide range of images enables the model to perform image analysis and visual data extraction tasks.430 431The combination of these diverse data sources is crucial for training a powerful multimodal model that can handle a wide variety of different tasks and data formats.432 433### **Data Preprocessing**434 435Here are the key data cleaning and filtering methods applied to the training data:436 437* **CSAM Filtering**: Rigorous CSAM (Child Sexual Abuse Material) filtering was applied at multiple stages in the data preparation process to ensure the exclusion of harmful and illegal content. 438* **Sensitive Data Filtering**: As part of making Gemma pre-trained models safe and reliable, automated techniques were used to filter out certain personal information and other sensitive data from training sets. 439* **Additional methods**: Filtering based on content quality and safety in line with [our policies](https://ai.google/static/documents/ai-responsibility-update-published-february-2025.pdf).440 441## **Ethics and Safety**442 443As open models become central to enterprise infrastructure, provenance and security are paramount. Developed by Google DeepMind, Gemma 4 undergoes the same rigorous safety evaluations as our proprietary Gemini models. 444 445### **Evaluation Approach**446 447Gemma 4 models were developed in partnership with internal safety and responsible AI teams. A range of automated as well as human evaluations were conducted to help improve model safety. These evaluations align with [Google’s AI principles](https://ai.google/principles/), as well as safety policies, which aim to prevent our generative AI models from generating harmful content, including:448 449* Content related to child sexual abuse material and exploitation 450* Dangerous content (e.g., promoting suicide, or instructing in activities that could cause real-world harm) 451* Sexually explicit content 452* Hate speech (e.g., dehumanizing members of protected groups) 453* Harassment (e.g., encouraging violence against people)454 455### **Evaluation Results**456 457For all areas of safety testing, we saw major improvements in all categories of content safety relative to previous Gemma models. Overall, Gemma 4 models significantly outperform Gemma 3 and 3n models in improving safety, while keeping unjustified refusals low. All testing was conducted without safety filters to evaluate the model capabilities and behaviors. For both text-to-text and image-to-text, and across all model sizes, the model produced minimal policy violations, and showed significant improvements over previous Gemma models' performance. 458 459## **Usage and Limitations**460 461These models have certain limitations that users should be aware of.462 463### **Intended Usage**464 465Multimodal models (capable of processing vision, language, and/or audio) have a wide range of applications across various industries and domains. The following list of potential uses is not comprehensive. The purpose of this list is to provide contextual information about the possible use-cases that the model creators considered as part of model training and development.466 467* **Content Creation and Communication** 468 * **Text Generation**: These models can be used to generate creative text formats such as poems, scripts, code, marketing copy, and email drafts. 469 * **Chatbots and Conversational AI**: Power conversational interfaces for customer service, virtual assistants, or interactive applications. 470 * **Text Summarization**: Generate concise summaries of a text corpus, research papers, or reports. 471 * **Image Data Extraction**: These models can be used to extract, interpret, and summarize visual data for text communications. 472 * **Audio Processing and Interaction**: The smaller models (E2B and E4B) can analyze and interpret audio inputs, enabling voice-driven interactions and transcriptions. 473* **Research and Education** 474 * **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. 475 * **Language Learning Tools**: Support interactive language learning experiences, aiding in grammar correction or providing writing practice. 476 * **Knowledge Exploration**: Assist researchers in exploring large bodies of text by generating summaries or answering questions about specific topics.477 478### **Limitations**479 480* **Training Data** 481 * The quality and diversity of the training data significantly influence the model's capabilities. Biases or gaps in the training data can lead to limitations in the model's responses. 482 * The scope of the training dataset determines the subject areas the model can handle effectively. 483* **Context and Task Complexity** 484 * Models perform well on tasks that can be framed with clear prompts and instructions. Open-ended or highly complex tasks might be challenging. 485 * A model's performance can be influenced by the amount of context provided (longer context generally leads to better outputs, up to a certain point). 486* **Language Ambiguity and Nuance** 487 * Natural language is inherently complex. Models might struggle to grasp subtle nuances, sarcasm, or figurative language. 488* **Factual Accuracy** 489 * Models generate responses based on information they learned from their training datasets, but they are not knowledge bases. They may generate incorrect or outdated factual statements. 490* **Common Sense** 491 * Models rely on statistical patterns in language. They might lack the ability to apply common sense reasoning in certain situations.492 493### **Ethical Considerations and Risks**494 495The development of vision-language models (VLMs) raises several ethical concerns. In creating an open model, we have carefully considered the following:496 497* **Bias and Fairness** 498 * VLMs trained on large-scale, real-world text and image data can reflect socio-cultural biases embedded in the training material. Gemma 4 models underwent careful scrutiny, input data pre-processing, and post-training evaluations as reported in this card to help mitigate the risk of these biases. 499* **Misinformation and Misuse** 500 * VLMs can be misused to generate text that is false, misleading, or harmful. 501 * Guidelines are provided for responsible use with the model, see the [Responsible Generative AI Toolkit](https://ai.google.dev/responsible). 502* **Transparency and Accountability** 503 * This model card summarizes details on the models' architecture, capabilities, limitations, and evaluation processes. 504 * A responsibly developed open model offers the opportunity to share innovation by making VLM technology accessible to developers and researchers across the AI ecosystem.505 506**Risks identified and mitigations**:507 508* **Generation of harmful content**: Mechanisms and guidelines for content safety are essential. Developers are encouraged to exercise caution and implement appropriate content safety safeguards based on their specific product policies and application use cases. 509* **Misuse for malicious purposes**: Technical limitations and developer and end-user education can help mitigate against malicious applications of VLMs. Educational resources and reporting mechanisms for users to flag misuse are provided. 510* **Privacy violations**: Models were trained on data filtered for removal of certain personal information and other sensitive data. Developers are encouraged to adhere to privacy regulations with privacy-preserving techniques. 511* **Perpetuation of biases**: It's encouraged to perform continuous monitoring (using evaluation metrics, human review) and the exploration of de-biasing techniques during model training, fine-tuning, and other use cases.512 513### **Benefits**514 515At the time of release, this family of models provides high-performance open vision-language model implementations designed from the ground up for responsible AI development compared to similarly sized models.