Downloads · 30 days
42
37% of all-time downloads
xv0y5ncu/gemma-4-E2B-it-GLQ-trellis-3inst-4bpw
gemma-4-E2B-it-GLQ-trellis-3inst-4bpw is a any-to-any model from xv0y5ncu. Use it for the any-to-any task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as apache-2.0.
GLQ (4.0 bits/weight) quantization of google/gemma-4-E2B-it using a trellis-coded codebook (QTIP TCQ) + randomized Hadamard transform (RHT) + LDLQ. Weights stay compressed in memory and are decoded on the fly by a fus…
Downloads · 30 days
42
37% of all-time downloads
All-time downloads
114
Public
Parameters
2.5B
4.9 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors4.9 GB · 100%
How the weights are stored.
I161.5B · 63%
From the Hugging Face model README
GLQ (4.0 bits/weight) quantization of google/gemma-4-E2B-it using a trellis-coded codebook (QTIP TCQ) + randomized Hadamard transform (RHT) + LDLQ. Weights stay compressed in memory and are decoded on the fly by a fused CUDA kernel.
Where GLQ shines: the size-vs-accuracy win is strongest at 2–4 bits/weight. For even more headroom, combine it with the E8 KV cache (≈4× smaller KV cache → longer context in the same VRAM).
google/gemma-4-E2B-it3inst variant) + RHT + LDLQ — 4.0 bpw uniform (native trellis rate — one decode pass, no residual stacking)python -m venv .venv
source .venv/bin/activate
pip install 'glq[vllm]' "transformers>=5.13.1,<5.15"
Pin transformers below 5.15 — 5.15.0 moved gemma-4 to a per-layer config, so
config.head_dim raises and vLLM dies before loading a single weight. Verified on
5.14.1 with vLLM 0.27.1. Not specific to GLQ: stock bf16 gemma-4 fails the same way.
Requires
glq >= 0.8.0— this checkpoint stores the trellis in the kernel (MMA-fragment) layout that the lookup-free 3INST CUDA kernels consume.
Everything in this section was measured on this exact checkpoint, on one RTX PRO 6000
Blackwell (sm_120) under vLLM 0.25.1. Footprint is vLLM's own Model loading took X GiB
line, not nvidia-smi.
| Loaded weights | 5.04 GiB (bf16 reference ≈ 10.2 GB) |
| Decode, batch 1 | 170.8 tok/s |
| Avg weight SQNR | 22.10 dB |
| AIME-2026 (avg@8, thinking) | 29.2% |
AIME-2026 detail: pass@8 16/30 problems, 0 truncations, 40/240 generations finished without a parseable \boxed{}, mean 6,680 generated tokens (thinking confirmed). n=30 problems × 8 samples, 32k budget, no system message, temperature 1.0 / top_p 0.95 / top_k 64, seed 0.
Scope these numbers to this run. Decode rate is GPU-specific and not by a constant factor — GLQ's speed advantage comes from moving 4× fewer weight bytes, so it is largest on bandwidth-starved 24–32 GB cards and roughly at parity on a 96 GB Blackwell like the one above. Quote the GPU or the claim is wrong somewhere.
Not measured yet: WikiText-2 perplexity, MMLU-Pro, and a paired bf16 arm run under this same harness. There is no bf16 baseline for this model on this box, so the table above cannot be read as a quantization delta — only as this checkpoint's own numbers.
from vllm import LLM, SamplingParams
def main():
llm = LLM(
model="xv0y5ncu/gemma-4-E2B-it-GLQ-trellis-3inst-4bpw",
quantization="glq",
dtype="bfloat16",
max_model_len=4096,
limit_mm_per_prompt={"image": 0, "video": 0, "audio": 0}, # text-only serving
)
out = llm.generate(["The capital city of New Zealand is"],
SamplingParams(max_tokens=64, temperature=0))
print(out[0].outputs[0].text)
# The __main__ guard is REQUIRED when running this as a script. vLLM switches to the
# "spawn" multiprocessing start method once CUDA is initialised, so its worker processes
# re-import this file; without the guard the script spawns itself recursively and dies
# with "An attempt has been made to start a new process before the current process has
# finished its bootstrapping phase" -- before the model ever loads.
if __name__ == "__main__":
main()
glq registers with vLLM automatically via its plugin entry point — no extra import needed.
import glq.hf_integration # registers the GLQ quantization method
from transformers import AutoModelForImageTextToText, AutoTokenizer
import torch
model = AutoModelForImageTextToText.from_pretrained(
"xv0y5ncu/gemma-4-E2B-it-GLQ-trellis-3inst-4bpw", device_map="cuda", dtype=torch.bfloat16)
tok = AutoTokenizer.from_pretrained("xv0y5ncu/gemma-4-E2B-it-GLQ-trellis-3inst-4bpw")
msgs = [{"role": "user", "content": "What is the capital city of New Zealand?"}]
ids = tok.apply_chat_template(msgs, add_generation_prompt=True, return_tensors="pt").to("cuda")
print(tok.decode(model.generate(ids, max_new_tokens=64)[0][ids.shape[1]:], skip_special_tokens=True))
This is a multimodal base model. GLQ quantizes the text decoder (the vision/audio towers are kept in their native format). vLLM is the recommended runtime.
Serve an OpenAI-compatible endpoint, then point your agent at it:
vllm serve xv0y5ncu/gemma-4-E2B-it-GLQ-trellis-3inst-4bpw --port 8000
pi-code — ~/.pi/agent/models.json:
{
"providers": {
"glq": {
"baseUrl": "http://localhost:8000/v1",
"api": "openai-completions",
"apiKey": "glq",
"models": [
{
"id": "xv0y5ncu/gemma-4-E2B-it-GLQ-trellis-3inst-4bpw"
}
]
}
}
}
opencode — ~/.config/opencode/opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"glq": {
"npm": "@ai-sdk/openai-compatible",
"name": "GLQ (local vLLM)",
"options": {
"baseURL": "http://localhost:8000/v1",
"apiKey": "glq"
},
"models": {
"xv0y5ncu/gemma-4-E2B-it-GLQ-trellis-3inst-4bpw": {
"name": "gemma-4-E2B-it-trellis-3inst-4bpw"
}
}
}
}
}
GLQ also ships an E8-quantized KV cache (~4× smaller than fp16, ~bit-identical at 4-bit). Enable it at serve time:
GLQ_KV_QUANT=e8_relaxed:2 \
GLQ_KV_E8_SIDECAR=1 GLQ_KV_E8_SIDECAR_READ=1 GLQ_KV_E8_COMPRESSED_ALLOC=1 \
GLQ_KV_E8_FUSED_GATHER=1 GLQ_KV_E8_FUSED_WRITE=1 \
vllm serve xv0y5ncu/gemma-4-E2B-it-GLQ-trellis-3inst-4bpw
e8_relaxed:2 ≈ 4-bit KV, :1 ≈ 2-bit, :3 ≈ 6-bit. This is the part of GLQ that keeps paying off above 4-bit weights.
A randomized Hadamard transform (a fixed random sign-flip + Hadamard rotation on each side) makes the weights and the calibration Hessian incoherent — spreading outliers so they quantize well. LDLQ then rounds the weights with error feedback across the remaining input dimensions via the Hessian's LDL factorization. Instead of a per-group lattice codebook, GLQ here uses trellis-coded quantization (TCQ, from QTIP): each 16×16 weight tile is encoded as a tail-biting Viterbi sequence over a dimension-256 trellis code, reaching a higher effective quantization dimension than an 8-D lattice at the same bit-rate. Decoding is a small look-up plus a few arithmetic ops per weight; a fused CUDA kernel keeps the weights compressed in VRAM and decodes them inline.
The "Golay/Leech" in the project name refers to the lattice codebooks GLQ also ships (E8 and its higher-dimensional cousins). Code, kernels and quantizer: GLQ on GitHub.
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).
| Property | E2B | E4B | 12B Unified | 31B Dense |
|---|---|---|---|---|
| Total Parameters | 2.3B effective <br> (5.1B with embeddings) | 4.5B effective <br> (8B with embeddings) | 11.95B | 30.7B |
| Layers | 35 | 42 | 48 | 60 |
| Sliding Window | 512 tokens | 512 tokens | 1024 tokens | 1024 tokens |
| Context Length | 128K tokens | 128K tokens | 256K tokens | 256K tokens |
| Vocabulary Size | 262K | 262K | 262K | 262K |
| Supported Modalities | Text, Image, Audio | Text, Image, Audio | Text, Image, Audio | Text, Image |
| Vision Encoder Parameters | ~150M | ~150M | - | ~550M |
| Audio Encoder Parameters | ~300M | ~300M | - | No Audio |
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.
| Property | 26B A4B MoE |
|---|---|
| Total Parameters | 25.2B |
| Active Parameters | 3.8B |
| Layers | 30 |
| Sliding Window | 1024 tokens |
| Context Length | 256K tokens |
| Vocabulary Size | 262K |
| Expert Count | 8 active / 128 total and 1 shared |
| Supported Modalities | Text, Image |
| Vision Encoder Parameters | ~550M |
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 are Google's published figures for the original bf16 models, not for this quantization. They are reproduced from the base model card for context. Google reports AIME-2026 (no tools) 37.5% for this model at bf16; this GLQ checkpoint measured 29.2% avg@8 under the protocol described above. The two were produced by different harnesses and are not a paired comparison — treat the gap as indicative, not as a measured quantization loss.
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 31B | Gemma 4 26B A4B | Gemma 4 12B Unified | Gemma 4 E4B | Gemma 4 E2B | Gemma 3 27B (no think) | |
|---|---|---|---|---|---|---|
| MMLU Pro | 85.2% | 82.6% | 77.2% | 69.4% | 60.0% | 67.6% |
| AIME 2026 no tools | 89.2% | 88.3% | 77.5% | 42.5% | 37.5% | 20.8% |
| LiveCodeBench v6 | 80.0% | 77.1% | 72.0% | 52.0% | 44.0% | 29.1% |
| Codeforces ELO | 2150 | 1718 | 1659 | 940 | 633 | 110 |
| GPQA Diamond | 84.3% | 82.3% | 78.8% | 58.6% | 43.4% | 42.4% |
| Tau2 (average over 3) | 76.9% | 68.2% | 69.0% | 42.2% | 24.5% | 16.2% |
| HLE no tools | 19.5% | 8.7% | 5.2% | - | - | - |
| HLE with search | 26.5% | 17.2% | - | - | - | - |
| BigBench Extra Hard | 74.4% | 64.8% | 53.0% | 33.1% | 21.9% | 19.3% |
| MMMLU | 88.4% | 86.3% | 83.4% | 76.6% | 67.4% | 70.7% |
| Vision | ||||||
| MMMU Pro | 76.9% | 73.8% | 69.1% | 52.6% | 44.2% | 49.7% |
| OmniDocBench 1.5 (average edit distance, lower is better) | 0.131 | 0.149 | 0.164 | 0.181 | 0.290 | 0.365 |
| MATH-Vision | 85.6% | 82.4% | 79.7% | 59.5% | 52.4% | 46.0% |
| MedXPertQA MM | 61.3% | 58.1% | 48.7% | 28.7% | 23.5% | - |
| Audio | ||||||
| CoVoST | - | - | 38.5<sup>*</sup> | 35.54 | 33.47 | - |
| FLEURS (lower is better) | - | - | 0.069<sup>*</sup> | 0.08 | 0.09 | - |
| Long Context | ||||||
| MRCR v2 8 needle 128k (average) | 66.4% | 44.1% | 43.4% | 25.4% | 19.1% | 13.5% |
<sup>*</sup>Excluding Chinese language.
Gemma 4 models handle a broad range of tasks across text, vision, and audio. Key capabilities include:
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-E2B-it"
# Load model
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:
# Prompt
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Write a short joke about saving RAM."},
]
# Process input
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]
# Generate output
outputs = model.generate(**inputs, max_new_tokens=1024)
response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
# Parse output
processor.parse_response(response, prefix=inputs["input_ids"])
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:
<details> <summary>Code for processing Audio</summary>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-E2B-it"
# Load model
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:
# Prompt - add audio after text
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"},
]
}
]
# Process input
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]
# Generate output
outputs = model.generate(**inputs, max_new_tokens=512)
response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
# Parse output
processor.parse_response(response, prefix=inputs["input_ids"])
</details>
<details>
<summary>Code for processing Images</summary>
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-E2B-it"
# Load model
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:
# Prompt - add image before text
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?"}
]
}
]
# Process input
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]
# Generate output
outputs = model.generate(**inputs, max_new_tokens=512)
response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
# Parse output
processor.parse_response(response, prefix=inputs["input_ids"])
</details>
<details>
<summary>Code for processing Videos</summary>
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-E2B-it"
# Load model
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:
# Prompt - add video before text
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.'}
]
}
]
# Process input
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]
# Generate output
outputs = model.generate(**inputs, max_new_tokens=512)
response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
# Parse output
processor.parse_response(response, prefix=inputs["input_ids"])
</details>
For the best performance, use these configurations and best practices:
Use the following standardized sampling configuration across all use cases:
temperature=1.0top_p=0.95top_k=64Compared to Gemma 3, the models use standard system, assistant, and user roles. To properly manage the thinking process, use the following control tokens:
<|think|> token at the start of the system prompt. To disable thinking, remove the token.<|channel>thought\n[Internal reasoning]<channel|><|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.
For optimal performance with multimodal inputs, place:
Aside 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.
Use the following prompt structures for audio processing:
Transcribe the following speech segment in {LANGUAGE} into {LANGUAGE} text.
Follow these specific instructions for formatting the answer:
* Only output the transcription, with no newlines.
* When transcribing numbers, write the digits, i.e. write 1.7 and not one point seven, and write 3 instead of three.
Transcribe the following speech segment in {SOURCE_LANGUAGE}, then translate it into {TARGET_LANGUAGE}.
When 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}.
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.
Data used for model training and how the data was processed.
Our 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:
The 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.
Here are the key data cleaning and filtering methods applied to the training data:
As 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.
Gemma 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, as well as safety policies, which aim to prevent our generative AI models from generating harmful content, including:
For 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.
These models have certain limitations that users should be aware of.
Multimodal 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.
The development of vision-language models (VLMs) raises several ethical concerns. In creating an open model, we have carefully considered the following:
Risks identified and mitigations:
At 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.
If you find our work helpful, please consider citing it:
@misc{gemmateam2026gemma4,
title={Gemma 4 Technical Report},
author={Gemma Team},
year={2026},
eprint={2607.02770},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2607.02770},
}
</details>
Derivative work of google/gemma-4-E2B-it, quantized with GLQ. It inherits the base model's license (apache-2.0) — please respect the base model's terms.