gemma-4-31B-it-qat-GGUF
This model ships a Multi-Token Prediction drafter at the repo root (`mtp-gemma-4-31B-it.gguf`, a near-lossless smart Q4_0). A recent llama.cpp auto-discovers it from `-hf`, so you do not pass `--model-draft`: ./build/bin/llama-server \ -hf unsloth/gemma-4-31B-it-qat-GGUF:UD-Q4_K_XL \ --spec-type draft-mtp --spec-draft-n-max 4 \ -ngl 999 -fa on The drafter shares the target's KV cache and does not change the output (the target verifies every drafted token). See the `MTP/` folder for the other precisions and explicit usage. > [!Note] > 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. > Four versions of the QAT checkpoints are available: > * **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. > * **GGUF** (Q4_0): Ready-to-deploy formats for broad ecosystem compatibility. Available for Gemma 4 E2B, E4B, 12B, 26B A4B, and 31B. > * **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. > * **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. 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. 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. Gemma 4 introduces key **capability and architectural advancements**: * **Reasoning** – All models in the family are designed as highly capable reasoners, with configurable thinking modes. * **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). * **Diverse & Efficient Architectures** – Offers Dense and Mixture-of-Experts (MoE) variants of different sizes for scalable deployment. * **Optimized for On-Device** – Smaller models are specifically designed for efficient local execution on laptops and mobile devices. * **Increased Context Window** – The small models feature a 128K context window, while the medium models support 256K. * **Enhanced Coding & Agentic Capabilities** – Achieves notable improvements in coding benchmarks alongside native function-calling support, powering highly capable autonomous agents. * **Native System Prompt Support** – Gemma 4 introduces native support for the `system` role, enabling more structured and controllable conversations. 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. 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). 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. 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. The "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. 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. Gemma 4 models handle a broad range of tasks across text, vision, and audio. Key capabilities include: * **Thinking** – Built-in reasoning mode that lets the model think step-by-step before answering. * **Long Context** – Context windows of up to 128K tokens (E2B/E4B) and 256K tokens (12B, 26B A4B/31B). * **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. * **Video Understanding** – Analyze video by processing sequences of frames. * **Interleaved Multimodal Input** – Freely mix text and images in any order within a single prompt. * **Function Calling** – Native support for structured tool use, enabling agentic workflows. * **Coding** – Code generation, completion, and correction. * **Multilingual** – Out-of-the-box support for 35+ languages, pre-trained on 140+ languages. * **Audio** (E2B, E4B, and 12B only) – Automatic speech recognition (ASR) and speech-to-translated-text translation across multiple languages. You can use all Gemma 4 models with the latest version of Transformers. To get started, install the necessary dependencies in your environment: `pip install -U transformers torch accelerate` Once you have everything installed, you can proceed to load the model with the code below: from transformers import AutoProcessor, AutoModelForMultimodalLM MODEL_ID = "google/gemma-4-12B-it" processor = AutoProcessor.from_pretrained(MODEL_ID) model = AutoModelForMultimodalLM.from_pretrained( MODEL_ID, dtype="auto", device_map="auto" ) Once the model is loaded, you can start generating output: messages = [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Write a short joke about saving RAM."}, ] inputs = processor.apply_chat_template( messages, tokenize=True, return_dict=True, return_tensors="pt", add_generation_prompt=True, enable_thinking=False ).to(model.device) input_len = inputs["input_ids"].shape[-1] outputs = model.generate(**inputs, max_new_tokens=1024) response = processor.decode(outputs[0][input_len:], skip_special_tokens=False) processor.parse_response(response) To enable reasoning, set `enable_thinking=True` and the `parse_response` function will take care of parsing the thinking output. Below, you will also find snippets for processing audio (E2B, E4B, 12B only), images, and video alongside text: Make sure to install the following packages: `pip install -U transformers torch torchvision librosa accelerate` You can then load the model with the code below: from transformers import AutoProcessor, AutoModelForMultimodalLM MODEL_ID = "google/gemma-4-12B-it" processor = AutoProcessor.from_pretrained(MODEL_ID) model = AutoModelForMultimodalLM.from_pretrained( MODEL_ID, dtype="auto", device_map="auto" ) Once the model is loaded, you can start generating output by directly referencing the audio URL in the prompt: messages = [ { "role": "user", "content": [ {"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."}, {"type": "audio", "audio": "https://raw.githubusercontent.com/google-gemma/cookbook/refs/heads/main/apps/sample-data/journal1.wav"}, ] } ] inputs = processor.apply_chat_template( messages, tokenize=True, return_dict=True, return_tensors="pt", add_generation_prompt=True, ).to(model.device) input_len = inputs["input_ids"].shape[-1] outputs = model.generate(**inputs, max_new_tokens=512) response = processor.decode(outputs[0][input_len:], skip_special_tokens=False) processor.parse_response(response) Make sure to install the following packages: `pip install -U transformers torch torchvision accelerate` You can then load the model with the code below: from transformers import AutoProcessor, AutoModelForMultimodalLM MODEL_ID = "google/gemma-4-12B-it" processor = AutoProcessor.from_pretrained(MODEL_ID) model = AutoModelForMultimodalLM.from_pretrained( MODEL_ID, dtype="auto", device_map="auto" ) Once the model is loaded, you can start generating output by directly referencing the image URL in the prompt: messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://raw.githubusercontent.com/google-gemma/cookbook/refs/heads/main/apps/sample-data/GoldenGate.png"}, {"type": "text", "text": "What is shown in this image?"} ] } ] inputs = processor.apply_chat_template( messages, tokenize=True, return_dict=True, return_tensors="pt", add_generation_prompt=True, ).to(model.device) input_len = inputs["input_ids"].shape[-1] outputs = model.generate(**inputs, max_new_tokens=512) response = processor.decode(outputs[0][input_len:], skip_special_tokens=False) processor.parse_response(response) Make sure to install the following packages: `pip install -U transformers torch torchvision librosa accelerate` You can then load the model with the code below: from transformers import AutoProcessor, AutoModelForMultimodalLM MODEL_ID = "google/gemma-4-12B-it" processor = AutoProcessor.from_pretrained(MODEL_ID) model = AutoModelForMultimodalLM.from_pretrained( MODEL_ID, dtype="auto", device_map="auto" ) Once the model is loaded, you can start generating output by directly referencing the video URL in the prompt: messages = [ { 'role': 'user', 'content': [ {"type": "video", "video": "https://github.com/bebechien/gemma/raw/refs/heads/main/videos/ForBiggerBlazes.mp4"}, {'type': 'text', 'text': 'Describe this video.'} ] } ] inputs = processor.apply_chat_template( messages, tokenize=True, return_dict=True, return_tensors="pt", add_generation_prompt=True, ).to(model.device) input_len = inputs["input_ids"].shape[-1] outputs = model.generate(**inputs, max_new_tokens=512) response = processor.decode(outputs[0][input_len:], skip_special_tokens=False) processor.parse_response(response) For the best performance, use these configurations and best practices: Use the following standardized sampling configuration across all use cases: * `temperature=1.0` * `top_p=0.95` * `top_k=64` Compared to Gemma 3, the models use standard `system`, `assistant`, and `user` roles. To properly manage the thinking process, use the following control tokens: * **Trigger Thinking:** Thinking is enabled by including the `<|think|>` token at the start of the system prompt. To disable thinking, remove the token. * **Standard Generation:** When thinking is enabled, the model will output its internal reasoning followed by the final answer using this structure: `<|channel>thought\n`**[Internal reasoning]**`<channel|>` * **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: `<|channel>thought\n<channel|>`**[Final answer]** > [!Note] > Note that many libraries like Transformers and llama.cpp handle the complexities of the chat template for you. * **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. For optimal performance with multimodal inputs, place: * Image content **before** the text in your prompt. * Audio content **after** the text in your prompt. As
Open gemma-4-31B-it-qat-GGUF in AIniverse
Compare versions, read real ratings, save to your stack.
Open in App