TL;DR
Gemma 3 is a family of open language models from 1 to 27 billion parameters. This report adds three things to the earlier Gemma models: image input, a context window of 128K tokens for most sizes, and better multilingual and math ability. It also changes the attention layout so that long contexts do not fill memory. Most layers look only at a 1024-token window, and only one layer in six sees the whole context. The paper reports that the 27B instruction-tuned model reaches an Elo score of 1338 in blind human comparisons, placing it among the top ten models in its Chatbot Arena table, and that the 4B model is competitive with the earlier 27B model on several benchmarks.
Builds on: Transformer, KV Cache, Grouped-Query Attention, Sliding Window Attention, Rotary Position Embedding, Knowledge Distillation, RMS Normalization · Leads to: none listed yet
Why it mattered
Gemma 3 is an open-weights release, so its design choices can be inspected and reused. The report's own framing is that the models are meant for consumer hardware, "phones, laptops, and high-end GPUs". The two design ideas most worth copying are the local-to-global attention layout and the training recipe that combines distillation from a teacher with reinforcement learning. The first is a direct answer to a memory problem: the KV Cache grows with context length, so keeping a full-length cache in every layer is expensive to serve. The report measures that a global-only layout adds about 60% memory overhead at a 32K context for a 2B model, and that a 1:3 local-to-global layout with 1024-token windows brings the overhead below 15%.
The report also shows that the model's raw quality holds up under the change. Its ablations find little change in perplexity as the local-to-global ratio varies. For practitioners the result is a concrete recipe: keep the attention span of most layers short, and keep a few layers global.
The problem
Three pressures pulled against each other.
Long context is memory-hungry. In a standard Transformer, every layer stores keys and values for every past token. That store is the KV Cache. Table 3 shows the scale: for the 4B model at a 32K context, the weights take 8.0 GB in bfloat16 and the weights plus cache take 12.7 GB, so the cache already adds more than half again the weight memory, and the cache grows linearly with context. Grouped-Query Attention already reduces the cache by sharing keys and values across query heads. Sliding Window Attention reduces it further, but a model that only sees a short window cannot use a long context on its own.
Images need a fixed-size input. The vision encoder takes square images at one fixed resolution. A wide photo or a page of text, squashed into a square, loses detail: small objects vanish and text becomes unreadable.
Small models need a good training signal. Every Gemma 3 model, including the 1B, is trained with Knowledge Distillation, so each student learns from a teacher's output distribution, not only from the raw next word. The paper also asks whether a small teacher or a large one is the better source for a small student.
How it works
The model is trained in stages, and then used one token at a time. Here is the pipeline in order, followed by one traced example.
- Encode the image. A frozen SigLIP vision encoder, a 400-million-parameter variant, takes an image resized to 896 by 896 pixels and produces a grid of vectors. The paper condenses these into a fixed 256 vectors per image, the "soft tokens" the language model reads as if they were words.
- Split a non-square image (Pan and Scan, at inference time). To avoid squashing, the adaptive windowing method cuts the image into non-overlapping crops of equal size that cover the whole image. Each crop is resized to 896 by 896 and passed through the encoder. It is applied only when needed, and it can be turned off for speed.
- Read the tokens in a decoder-only transformer. The language model is a standard decoder-only transformer with Grouped-Query Attention, RMS Normalization before and after each sub-layer, and QK-norm (normalising the query and key vectors before they are compared) in place of the soft-capping used by Gemma 2, which smoothly limits attention scores.
- Alternate local and global attention. Layers follow a 5-to-1 pattern. Five local layers use Sliding Window Attention over the last 1024 tokens. Then one global layer attends to the full context. The pattern starts with a local layer.
- Use two rotary frequencies. Rotary Position Embedding rotates each query and key by an angle that depends on position; the base sets how fast those angles change. Global layers use a rotary base of one million. Local layers keep the base of ten thousand. The context is first trained to 32K and then stretched to 128K at the end of pre-training by rescaling the rotary positions.
- Emit one token at a time. At inference, each new token adds one entry to the key-value cache in every layer. Local layers keep only the last 1024 entries, so their cache stops growing; global layers keep the whole context.
A tiny trace of step 4 with 12 layers: the pattern gives layers 1 to 5 local, layer 6 global, layers 7 to 11 local, layer 12 global. Two of twelve layers are global, which is one in six, the same proportion as the 5-to-1 pattern. The other ten layers never need more than 1024 cached entries.
flowchart LR I[Image] --> P[Pan and Scan crops] P --> V[SigLIP encoder, 256 soft tokens per crop] T[Text tokens] --> D V --> D[Decoder: 5 local layers, then 1 global, repeated] D --> O[Next-token distribution]
The math
Key-value cache per token. For a model with L layers, h key-value heads of size d, and b bytes per value, the cache for one token costs 2 L h d b bytes, the factor 2 covering keys and values. Each cached entry is one token in one layer, so the total cache for a context of C tokens depends on how many entries each layer keeps.
Layer-averaged cache length. Let the local window be W and let C be the context length. With a 5-to-1 pattern, five out of every six layers keep min(C, W) entries and one in six keeps C entries. The average entries per layer is
Worked check with W = 1024 and C = 32768: the local term is (5/6) times 1024 = 853.3, the global term is (1/6) times 32768 = 5461.3, and the total is 6314.7. The global-only layout keeps 32768 per layer. The ratio is 6314.7 / 32768, about 0.19, so this simplified count needs about a fifth of the cache entries. This is my illustration with equal per-layer costs. It is not the paper's measurement, which also counts the weights and reports a different overhead.
Distillation loss. The paper samples 256 logits per token from the teacher, weights them by teacher probability, and sets the teacher's probability for all other tokens to zero before renormalising. The student is trained with Cross-Entropy Loss against this sparse target:
where S is the set of sampled vocabulary entries and tilde p_T is the renormalised teacher distribution on S. In words: the student is pushed to put probability on the words the teacher favours, and only on the sampled part of the vocabulary.
Results
The main numbers, all copied from the paper's tables:
- Human preference (Table 5). Gemma 3 27B IT scores Elo 1338 with a 95% interval of plus 8 and minus 9, ranked 9th in the table, above DeepSeek-V3 (1318) and above Gemma 2 27B IT (1220). The paper marks these as preliminary results received on March 8, 2025, and notes that Elo does not measure visual ability, which none of the compared models had.
- Math (Table 6). On MATH, the 27B instruction-tuned model scores 89.0, against 55.6 for Gemma 2 27B. The 4B model scores 75.6 and the 12B model scores 83.8.
- Science and factuality (Table 6). On GPQA Diamond the 27B model scores 42.4, against 34.3 for Gemma 2 27B. On MMLU-Pro it scores 67.5.
- Memory (Table 3). For the 27B model at 32K context, weights alone are 54.0 GB in bfloat16 and 14.1 GB with per-channel int4 (Quantization). With the KV cache the figures are 72.7 GB and 32.8 GB.
- Documents (Table 8). Pan and Scan raises DocVQA from 72.8 to 81.0 for the 4B model and from 85.6 to 90.4 for the 27B model. On InfoVQA the 27B model rises from 59.4 to 76.4.
- Resolution (Table 7). For a 2B model, DocVQA rises from 31.9 at 256 pixels to 59.8 at 896 pixels.
- Local-to-global ratio (Figure 3). Perplexity changes little across ratios, even at 7 to 1.
- Teacher size (Figure 8). A smaller teacher is better for short training runs, and a larger teacher wins for longer runs.
- Memorisation (Figure 9). The paper reports that Gemma 3 memorises long-form text at a much lower rate than earlier models, and it found no personal information in the outputs it classified as memorised.
Limits. The Elo numbers are preliminary, and Chatbot Arena is a human-preference measure, not a test of correctness. The ablations use text-only models at small scale, and the paper says probe benchmarks may be contaminated despite decontamination. The report notes that quality degrades beyond the 128K range. The paper also does not compare directly with external models using their own evaluation settings, and it points readers to third-party leaderboards for that.
Reading guide
- Abstract and Section 1, Introduction. The three new abilities and the memory motivation. Needs Transformer and KV Cache.
- Section 2, Model Architecture. Grouped-query attention, RMS normalisation, the 5-to-1 layout and the rotary base changes. Needs Grouped-Query Attention, RMS Normalization, Sliding Window Attention and Rotary Position Embedding. For the context stretch, read Extending Context Window of Large Language Models via Positional Interpolation first.
- Section 2.1, Vision modality. The SigLIP encoder and Pan and Scan. Needs Sigmoid Loss for Language Image Pre-Training and Vision Transformer (ViT).
- Section 2.2, Pre-training. The token budgets, the tokenizer and distillation. Needs Knowledge Distillation and Subword Tokenization.
- Section 2.3, Quantization aware training. The int4 and fp8 formats. Needs Quantization.
- Section 3, Instruction tuning. Distillation from a large instruction teacher and the reinforcement learning phase. Needs Instruction Tuning and Reinforcement Learning from Human Feedback (RLHF).
- Sections 4 and 5, Evaluation and Ablations. Read the tables with the Results section above in hand.
- Sections 6 and 7, Memorisation and safety. The privacy audit and the responsibility work. Read them for the method, not as a verdict.
Check yourself
QuestionRecall. In Gemma 3's layout, how many of every six layers use global attention, and how far back does a local layer look?Show answer
One in six: a 5-to-1 pattern of local to global layers. A local layer uses sliding-window attention over the last 1024 tokens, so its cache stops growing once the window is full. Only the global layers attend to the full context.
QuestionComputation. Using the simplified count in The math, with a window of W = 1024 and a context of C = 16384, what is the average number of cache entries per layer?Show answer
The formula is (5/6) times min(C, W) + (1/6) times C. Here min(16384, 1024) = 1024, so the local term is (5/6) times 1024 = 853.3. The global term is (1/6) times 16384 = 2730.7. The total is 3584.0.
QuestionWhy. Why does a shorter local window reduce memory without much change in perplexity, according to the paper's ablations?Show answer
Local layers only need to keep the last W entries, so their cache is capped at W no matter how long the context is. The paper's ablations find that perplexity is largely unaffected by changing the local-to-global ratio and by shrinking the sliding window, which suggests most layers do not need long-range attention for the model to predict well. Long-range information still reaches the model through the global layers.
QuestionApplied. A team serves the 27B model at a 32K context and wants it to run on a single small GPU. Which row of Table 3 tells them the weight memory they need in int4 with per-channel quantization, and what is it?Show answer
The 27B row gives 14.1 GB for per-channel int4 weights without the KV cache. With the cache at 32K the figure is 32.8 GB, so the cache matters a lot at this length and should be counted in the memory budget.
Sources
- Gemma Team et al. Gemma 3 Technical Report. arXiv:2503.19786 (2025). https://arxiv.org/abs/2503.19786
- Xiaohua Zhai et al. Sigmoid Loss for Language Image Pre-Training (SigLIP). arXiv:2303.15343 (2023). https://arxiv.org/abs/2303.15343