Gemma 4 Architecture Explained: Layers, Attention and MoE
By LatestLLM Editorial · Published · Specs verified · 27 min read · License: Apache 2.0
Gemma 4 is Google's family of open-weight, decoder-only transformers, released under the Apache 2.0 license in five sizes: E2B, E4B, 12B, 31B and a 26B mixture-of-experts model that activates 3.8B parameters per token. Its design is conventional apart from a set of memory-saving choices: five of every six layers attend only to a short sliding window, global layers reuse keys as values, p-RoPE gives position information to only a quarter of the frequencies, and normalisation is applied both before and after the attention and feed-forward blocks.
Key takeaways
- Gemma 4 is a decoder-only transformer in five sizes: E2B, E4B, 12B, 31B and the 26B-A4B mixture-of-experts model with 3.8B active parameters.
- Five of every six layers use sliding-window attention (a window of 1,024 tokens, or 512 in E2B and E4B). Every sixth layer is a global, full-attention layer. E2B uses a 4:1 ratio instead of 5:1.
- The memory savings stack: grouped-query attention, keys reused as values on global layers, p-RoPE with p = 0.25, and shared KV caches in E2B and E4B.
- Normalisation is unusual: RMSNorm runs before and after both the attention and feed-forward blocks, and queries and keys are normalised as well.
- The 26B-A4B sends each token to 8 of 128 routed experts plus 1 shared expert, so its compute per token is close to a 3.8B dense model while all 25.2B weights still have to fit in memory.
- The models are released under the Apache 2.0 license, and the numbers on this page come from each model's published configuration.
Gemma 4 variants
| Size | Type | Parameters | Layers | Attention mix | Context | Inputs |
|---|---|---|---|---|---|---|
| Gemma 4 31B | Dense (Keys reused as values, 256K context) | 30.7B | 60 | 50 local · 10 global (5:1) | 256K tokens | text, image |
| Gemma 4 26B-A4B | Mixture-of-experts (8 of 128 experts, 1 shared expert, Keys reused as values) | 25.2B total · 3.8B active | 30 | 25 local · 5 global (5:1) | 256K tokens | text, image |
| Gemma 4 12B | Dense (Encoder-free multimodal, Keys reused as values) | 11.95B | 48 | 40 local · 8 global (5:1) | 256K tokens | text, image, audio |
| Gemma 4 E4B | Dense (Per-layer embeddings, Shared KV cache) | 4.5B effective · 8B with embeddings | 42 | 35 local · 7 global (5:1) | 128K tokens | text, image, audio |
| Gemma 4 E2B | Dense (Per-layer embeddings, Shared KV cache, 4:1 local to global) | 2.3B effective · 5.1B with embeddings | 35 | 28 local · 7 global (4:1) | 128K tokens | text, image, audio |
Inside one transformer block
Tokens: text cut into pieces
A model cannot read letters the way you do. Your text is first chopped into small pieces called tokens, and every piece gets a number from a fixed list. Gemma 4's list has 262,144 entries.
Think of it like this: Like turning a sentence into LEGO bricks. Every brick shape has a catalogue number, and the model only ever sees the numbers.
Embedding: numbers that describe meaning
Each token number is looked up in a big table and replaced by a list of 5,376 numbers that describe what the token means. Similar meanings get similar lists.
Think of it like this: Like giving every word a GPS coordinate on a map of meaning. “Cat” and “kitten” land close together; “cat” and “tax” land far apart.
Transformer block × 60
The same two-step recipe is repeated 60 times: first attention, where words look at other words, then a feed-forward step, where each word is processed on its own. Each repeat passes its result to the next.
Think of it like this: A document handed through 60 editors in a row. Every editor adds margin notes but keeps what is already written.
RMSNorm: keeping numbers steady
Normalisation rescales the numbers so they stay at a steady size, which keeps training stable. Gemma applies it before and after attention, and before and after the feed-forward step.
Think of it like this: Like an audio compressor. Whatever the volume going in, the level coming out stays in a comfortable range.
Grouped-query attention: local and global
Attention lets every word look at other words to work out its meaning in context, such as what “it” refers to. Gemma 4 mixes two kinds of layer: local layers that only look at the nearest 1,024 tokens, and every sixth layer a global one that looks at everything.
Think of it like this: Local layers are reading with a finger on the current paragraph. Global layers are flipping through the whole book. Doing the cheap thing several times per expensive look keeps long documents affordable.
Residual add: keep what was there
Each step adds its result to what was already there instead of replacing it, so earlier information is never lost.
Think of it like this: Highlighting a textbook instead of rewriting it. The original text stays and your notes pile on top.
Feed-forward network: thinking alone
After attention gathers information, each word is processed on its own by a small neural network. It widens the vector (5,376 to 21,504 numbers), applies a gate that decides what to keep, then shrinks it back.
Think of it like this: Attention is the group meeting where everyone shares notes. The feed-forward step is each person going back to their desk to think it through alone.
Mixture-of-experts: a team of specialists
Instead of one big feed-forward network there are — small ones, called experts, plus — shared expert that every token uses. A router picks the best — routed experts for each token, so only a slice of the model works on each word.
Think of it like this: A hospital with — specialists and one general practitioner who sees every patient. A triage nurse, the router, also sends each patient to — specialists, never to all —.
Output head: scoring every possible next word
After the last layer, one more normalisation and a final step turn each vector into a score for every one of the 262,144 possible next tokens. The highest scores are the model's guesses.
Think of it like this: A game-show buzzer round: all 262,144 words ring in with a score, and the loudest ones win.
The big picture: how Gemma 4 is built
In simple words: Gemma 4 reads text as a long list of numbers, passes it through a tall stack of layers, and at the end scores every possible next word. Each layer has two jobs: attention, where words look at each other, and a feed-forward step, where each word is processed on its own.
Think of it like this: Picture a relay race with 60 runners (in the 31B model). Each runner receives the baton, which is the numbers for your text, adds a little something and hands it on. Nobody drops the baton; they only add to it.
Gemma 4 follows the decoder-only transformer recipe used by most modern language models, as the Gemma 4 Technical Report describes it. Text is split into tokens, each token becomes a vector from an embedding table, and that vector travels upward through a stack of transformer blocks. At the top, an output layer turns the final vector into a score for every token in the vocabulary, and the highest-scoring tokens become the model's prediction for what comes next.
What makes Gemma 4 distinctive is not a new building block but the way familiar blocks are combined to save memory. Most layers look only at nearby text, global layers reuse keys as values, position information is added to only a quarter of the rotation frequencies, and one variant replaces the feed-forward network with a mixture of experts. The sections below take those choices one at a time.
The family comes in five sizes: E2B, E4B, 12B, 26B-A4B and 31B. Google's model card groups E2B, E4B, 12B and 31B as dense models and lists the 26B-A4B as the family's one mixture-of-experts model. The numbers in the diagram and the tables come from each model's published configuration, so you can switch between sizes and watch the same design scale up or down.
Go deeper: details for practitioners
- The text decoder follows one design across all sizes. The vision encoders (about 150M parameters on E2B and E4B, about 550M on 31B and 26B-A4B) and the audio encoders (about 300M on E2B and E4B) are separate and are not covered on this page.
- The 12B model uses a unified, encoder-free design that ingests raw audio and image patches, according to the technical report.
- According to the model card, every size accepts text and images, and E2B, E4B and 12B also accept audio.
- In the diagram, data flows from bottom to top, the way it flows through the model.
What is a decoder-only transformer?
A model that reads a sequence of tokens and predicts the next one, using attention only over the tokens that came before. It is the design behind most chat models.
What is a parameter?
One learned number inside the model. A 31B model has about 31 billion of them; together they hold everything the model has learned.
Tokens and embeddings: turning text into numbers
In simple words: A language model works on numbers, not letters. Gemma 4 first cuts text into tokens and then looks each token up in a table that gives it a long list of numbers describing its meaning.
Think of it like this: It is like a dictionary where every entry is a coordinate on a map of meaning instead of a definition. Words that mean similar things sit near each other.
Gemma 4 uses a SentencePiece tokenizer with a vocabulary of about 262,000 entries. Digits are split into single tokens, whitespace is preserved, and rare characters fall back to bytes, according to the technical report.
Each token ID selects one row of the embedding table. For the 31B model that table has 262,144 rows of 5,376 numbers each, roughly 1.4 billion parameters, or about 4.6 percent of the model.
The same table is reused at the output end of the model (tied embeddings), so those parameters serve twice: once to read tokens in and once to score tokens out.
Go deeper: details for practitioners
- A large vocabulary generally means common words and non-English text need fewer tokens. Fewer tokens means shorter sequences and a smaller KV cache.
- Table 1 of the technical report lists 1,410M embedder parameters for the 31B and 740M for the 26B-A4B.
- In E2B and E4B the embedder figure also contains the per-layer embeddings described in the E-series section.
What is a vocabulary?
The fixed list of pieces (tokens) the model can read and write. Every piece has a number; the model never sees raw letters.
Why does vocabulary size matter?
A bigger list covers more words and languages in single pieces, but the embedding table grows with it, and so does the final scoring step.
Local and global attention: the 5:1 pattern
In simple words: Most Gemma 4 layers only look at the last 1,024 tokens. Every sixth layer looks at the whole text. That keeps long conversations affordable without losing the ability to connect distant facts.
Think of it like this: When you read a long novel you mostly keep your finger on the current page, and every so often you flip back through the whole book to check a detail. Gemma 4 works the same way: many cheap local looks, one expensive global look.
Standard self-attention lets every token look at every earlier token. That is powerful but expensive: both the work and the memory grow with the length of the text. Sliding-window attention, introduced in the Longformer paper, restricts each token to a window of recent tokens.
Gemma 4 alternates the two. In the 31B, 26B-A4B, 12B and E4B models, five local layers are followed by one global layer. The window is 1,024 tokens, or 512 in E4B. The smallest model, E2B, uses a 4:1 ratio. The 31B's 60 layers therefore contain 50 local and 10 global layers.
The payoff is memory. A local layer never needs to remember more than its window, no matter how long the conversation grows. Only the global layers keep a cache that grows with the whole text, and in the 31B that is one layer in six.
Information can still travel a long way. A fact seen far back in the text is reachable by the global layers, and what they learn is passed up through the later layers, so the model can connect distant parts of a document.

Go deeper: details for practitioners
- Gemma 3 introduced the 5:1 pattern with a 1,024-token window; Gemma 4 keeps the 5:1 ratio (4:1 for E2B) and the same window for the larger models.
- Local layers use a head dimension of 256 and global layers use 512.
- The 31B, 26B-A4B and 12B models support 262,144 tokens of context; E2B and E4B support 131,072.
What is sliding-window attention?
Each token attends only to the previous N tokens (the window) instead of to the whole text. The window slides forward as the text grows.
What does 5:1 mean?
Out of every six layers, five are local (sliding-window) and one is global (full attention).
Grouped-query attention and the KV cache
In simple words: While writing, the model keeps notes on every earlier token. Gemma 4 shrinks those notes in several ways, so long contexts need far less memory.
Think of it like this: Imagine a library where many readers share a few copies of each book instead of every reader owning their own. Everyone can still read; the shelves stay small.
During generation the model caches the keys and values of every token it has already processed, so it does not recompute them. This KV cache grows with the length of the text and, for long contexts, becomes the largest user of memory.
Grouped-query attention (GQA) shares each set of keys and values across several query heads. The 31B has 32 query heads but 16 KV heads on local layers (2 queries per KV head) and only 4 KV heads on global layers (8 queries per KV head).
The technical report lists further savings. On the global layers of the larger models, values are set equal to keys, so only one tensor per token needs caching. In E2B and E4B, 20 of 35 and 18 of 42 layers reuse the cache of an earlier layer. Combined with the local/global split and p-RoPE, the report says the global KV cache shrinks by up to 37.5 percent.
The compare tool below turns this into numbers. Under its stated assumptions (bfloat16, keys stored once on global layers, local caches trimmed to the window), the 31B needs about 6 GB of cache at a 128K-token context. A hypothetical model of the same shape with full attention on every layer and 16 KV heads would need about 129 GB.
Go deeper: details for practitioners
- Estimate used by the compare tool: local layers cache min(context, window) × 2 × KV heads × head size × 2 bytes; global layers cache context × KV heads × global head size × 2 bytes, with keys stored once when values equal keys.
- Real inference engines differ in how they trim local caches, page memory and quantise the cache, so treat the figures as estimates.
- E2B and E4B are not modelled in the estimate because some of their layers borrow another layer's cache.
What are keys and values?
For every token the model computes a key (what this token is about) and a value (the information it carries). Attention compares a query with all keys and blends the matching values.
Why does the KV cache matter?
It decides how much memory a long conversation needs on top of the model weights, and so how long a context fits on your hardware.
Position information: RoPE and p-RoPE
In simple words: Attention needs to know which word came first. Gemma 4 encodes position by rotating vectors: fully on local layers, and on only a quarter of the dimensions on global layers.
Think of it like this: Give every token a set of clock hands. The angle between two tokens' hands tells attention how far apart they are. Fast hands separate close neighbours; slow hands separate far-away words.
Rotary position embedding (RoPE) encodes where a token sits by rotating its query and key vectors by an angle that grows with position. Because attention compares queries with keys, the comparison naturally depends on how far apart two tokens are.
Local layers in Gemma 4 use standard RoPE with a base frequency of 10,000. Global layers use p-RoPE with p = 0.25 and a base frequency of 1,000,000: only a quarter of the frequency pairs carry position information and the rest are left untouched.
The intuition is that a global layer's job is to match meaning over long distances. Leaving most dimensions free of position keeps them from being disturbed by exact distance, which the report links to better long-context behaviour.
Go deeper: details for practitioners
- The configuration lists a partial rotary factor of 0.25 with a proportional RoPE type for full-attention layers.
- The Gemma 4 report cites p-RoPE as one of three long-context choices, together with the 5:1 layer ratio and KV cache sharing.
- RoPE base 1M on global layers and 10k on local layers means the slowest hands turn far more slowly, which suits very long contexts.
What is a frequency pair?
RoPE rotates vectors in two-dimensional planes. Each plane is a pair of numbers that turns at its own speed, its frequency.
What does the “p” in p-RoPE stand for?
The proportion of frequency pairs that are rotated. Gemma 4 uses p = 0.25 on global layers.
Normalisation: RMSNorm before and after
In simple words: Normalisation layers keep the numbers flowing through the model in a steady range. Gemma 4 normalises on both sides of every attention and feed-forward block, and also normalises queries and keys.
Think of it like this: It is like adjusting the volume at both ends of a long cable, so the signal is neither too faint nor too loud when it arrives.
RMSNorm rescales a vector by its root-mean-square. It is a simpler cousin of LayerNorm that skips mean-centering and is cheaper to compute.
Most open models apply it only before each sub-layer (pre-norm). Gemma 4 applies it before and after both the attention block and the feed-forward block, four norms per layer, a layout sometimes called sandwich normalisation. The technical report describes this as pre-norm and post-norm with RMSNorm.
Gemma 4 also uses QK-norm: queries and keys are normalised before their dot product, which stops attention scores from growing too large during training. For fp16 inference the report adds a scalar scale at each block to keep activations inside the fp16 range.
Go deeper: details for practitioners
- The epsilon used by the RMSNorm layers in the configuration is 1e-6.
- Extra normalisation costs little compute and is a cheap way to improve training stability.
- Analysis by Sebastian Raschka notes that this placement is unusual among current open models.
Pre-norm vs post-norm?
Pre-norm normalises the input of a sub-layer; post-norm normalises its output. Gemma does both around each block.
Normalization and residual connections explained simply and technically
What is QK-norm?
A normalisation applied to the query and key vectors before attention scores are computed, which keeps those scores in a stable range.
Feed-forward layers and the mixture-of-experts variant
In simple words: After attention gathers context, a feed-forward network processes each token alone. Most Gemma 4 models use one big network per layer; the 26B-A4B swaps it for 128 routed experts plus one shared expert and uses only 8 of the routed ones per token.
Think of it like this: A dense layer is one generalist who handles every patient. A mixture-of-experts layer is a hospital: a general practitioner sees everyone, and a triage nurse also sends each patient to the 8 specialists who fit best.
In the dense models, the feed-forward block is a gated network with a GELU (tanh) activation. In the 31B it widens each token's 5,376 numbers to 21,504 and then shrinks them back. This block holds most of each layer's parameters.
The 26B-A4B replaces it with a mixture of experts: 128 routed experts, each with a width of 704, one shared expert that every token passes through, and a router that selects 8 routed experts for every token. The model card counts 25.2B total parameters and 3.8B active ones.
The trade-off is compute against memory. Per token, the 26B-A4B does about as much work as a 4B dense model, so it generates quickly. But a token can be routed to any expert, so all 25.2B parameters must be loaded. MoE saves compute, not memory.
Go deeper: details for practitioners
- Table 1 of the report counts 24.5B matrix-multiply parameters in total and 2.8B active for the 26B-A4B, plus embedding and vision-encoder parameters.
- The model card lists the expert count as “8 active / 128 total and 1 shared”. config.json lists a regular feed-forward width of 2,112 next to the routed-expert width of 704. 2,112 is exactly 3 × 704, which is consistent with the shared expert, but neither document says so outright.
- Expert routing is learned during training; the report does not describe the router in detail.
What is a router?
A small network that scores every expert for the current token and picks the top few. Different tokens usually go to different experts.
Why not make every model mixture-of-experts?
Dense models are simpler to deploy and fine-tune and need less memory per unit of quality. MoE pays off when you have the memory and want fast generation.
The output head and logit softcapping
In simple words: At the top of the stack, Gemma 4 turns each vector into a score for every possible next token and picks from the highest scores. A soft cap stops any single score from becoming extreme.
Think of it like this: A buzzer round on a game show: every one of the 262,144 possible words rings in with a score, and a volume limiter keeps any single buzzer from drowning out the rest.
After the final block, one more RMSNorm is applied and the result is multiplied by the embedding table, flipped, to produce one score (a logit) per token in the vocabulary. Those scores become probabilities, and the model samples or picks the next token.
Gemma 4 soft-caps these scores at 30: each logit is passed through 30 times tanh of the logit divided by 30, which leaves small values almost unchanged and squashes extreme ones.
Go deeper: details for practitioners
- The report also describes multi-token prediction drafters for faster decoding. For E2B and E4B the drafter replaces the projection onto the whole vocabulary with a top-k over clusters of tokens, shrinking the final matrix from d × 262,000 to d × 4,096.
- Tied embeddings mean the output matrix is the embedding table, so no extra parameters are needed for the head.
What is soft-capping?
Squashing a number smoothly into a fixed range with a tanh curve, instead of cutting it off sharply. It keeps large scores bounded.
The E-series: per-layer embeddings and shared caches
In simple words: E2B and E4B are dense models built for phones and laptops. The E stands for effective parameters: part of what they store is a set of per-layer embedding tables that work as quick lookups, so they count fewer parameters than they hold.
Think of it like this: It is like a suitcase where a heavy pocket dictionary can stay at the hotel. You carry less in your hands, and you still look things up when you need them.
E2B and E4B use per-layer embeddings, an idea carried over from Gemma 3n. Besides the main embedding table, per-layer embeddings give each decoder layer its own small embedding for every token (256 numbers per token). The tables are large but only used for lookups, which is why the effective parameter count is much smaller than the total: the technical report counts 2.3B and 4.5B effective parameters out of about 5B and 8B in total. Google's model card lists both among the dense models; there are no experts in them.
They also share KV caches: 20 of E2B's 35 layers and 18 of E4B's 42 layers reuse the cache of an earlier layer instead of keeping their own. Unlike the larger models, they keep separate keys and values on global layers.
Both use a 512-token sliding window and a 131,072-token context, and both accept text, image and audio input with encoders of about 150M (vision) and 300M (audio) parameters. E2B alternates four local layers with one global layer (4:1) instead of five (5:1).
Go deeper: details for practitioners
- In the configuration E2B also enables a double-wide MLP flag, which this page lists but does not model.
- Table 1 of the report lists the embedder of E2B as 400M parameters plus 2,340M extra, and E4B as 670M plus 2,820M extra. The report says the extra embedder parameters are the per-layer embeddings.
- The diagram does not draw the per-layer embeddings or the shared caches.
What does the “E” in E4B mean?
Effective. The model has 4.5B effective parameters, counting what runs in the main network, out of about 8B stored in total.
What are per-layer embeddings?
Extra lookup tables that feed a small, token-specific vector into every layer. They add knowledge without adding much compute.
What changed from Gemma 3
In simple words: Structurally, Gemma 4 looks like a refinement of Gemma 3. The big picture is the same; the changes are small memory-saving details plus new model variants.
Think of it like this: It is the same house with a better insulated roof and a new wing, rather than a new floor plan.
Sebastian Raschka's architecture comparison finds that the Gemma 4 31B looks almost unchanged next to the Gemma 3 27B: the same 5:1 hybrid of sliding-window and global attention, the same grouped-query attention and the same unusual pre-norm plus post-norm placement.
The differences are small. Global layers reuse keys as values, which shrinks their KV cache, and use p-RoPE so that only part of the frequencies carry position. Gemma 4 also adds a mixture-of-experts model, an encoder-free 12B, and a thinking mode, and brings per-layer embeddings and shared caches to its small models.
Because the layout changed so little, the large benchmark gains the report describes cannot be explained by architecture alone. Training data and methods matter as much, which is why this page sticks to what the model is built from.
Go deeper: details for practitioners
- Gemma 3 used a window of 1,024 tokens with a 5:1 ratio; Gemma 2 alternated local and global layers 1:1 with a 4k window.
- Raschka's comparison is a useful side-by-side if you want to see the Gemma 3 and Gemma 4 diagrams next to each other.
Why compare architectures if training matters more?
Architecture decides memory use, speed and how long a context fits. Those are the things you can plan around before you ever run the model.
Which variant should you pick?
In simple words: Start from your memory budget. The 31B is the highest-quality dense model, the 26B-A4B is the fastest large one, the 12B suits laptops and workstations, and E4B and E2B target devices with very little memory.
Think of it like this: Choosing a variant is like choosing a vehicle: a truck (31B) carries the most, a hybrid (26B-A4B) is quick on the road but still needs a big garage, a van (12B) is the everyday choice, and the scooters (E4B, E2B) go anywhere.
The 31B dense model is the largest and usually the strongest choice when you have the memory for it. Its KV cache is also the largest, mostly because of its global layers.
The 26B-A4B generates quickly because it activates only 3.8B parameters per token, but you still need memory for all 25.2B of its weights. It is a good fit when speed matters and memory does not.
The 12B sits in the middle and is the unified, encoder-free multimodal design: images and audio are projected straight into the decoder-only transformer. E4B and E2B are designed for on-device use; their shared caches and per-layer embeddings keep the memory footprint small.
Use the compare tool to see how layers, heads, experts and context length differ, and check the model's page in the LatestLLM catalog for pricing, benchmarks and hosting options.
Go deeper: details for practitioners
- Quantised releases exist for several sizes, and the report describes quantisation-aware training, which can shrink weight memory further.
- The report gives memory with and without a KV cache for a 32k-token sequence in its Table 3, a good reference for real numbers.
Do I need the whole model in memory for MoE?
Yes. Only a few experts run per token, but any expert can be chosen, so all of the weights should be loaded to run at full speed.
Gemma 4 variants compared
| Spec | Gemma 4 31B | Gemma 4 26B-A4B | Gemma 4 12B | Gemma 4 E4B | Gemma 4 E2B |
|---|---|---|---|---|---|
| Parameters | 30.7B | 25.2B total · 3.8B active | 11.95B | 4.5B effective · 8B with embeddings | 2.3B effective · 5.1B with embeddings |
| Layers | 60 | 30 | 48 | 42 | 35 |
| Hidden size | 5,376 | 2,816 | 3,840 | 2,560 | 1,536 |
| Normalisation | before and after each block | before and after each block | before and after each block | before and after each block | before and after each block |
| Query heads | 32 | 16 | 16 | 8 | 8 |
| KV heads (local layers) | 16 | 8 | 8 | 2 | 1 |
| KV heads (global layers) | 4 | 2 | 1 | same as local | same as local |
| Sliding window | 1,024 tokens | 1,024 tokens | 1,024 tokens | 512 tokens | 512 tokens |
| Layer mix | 50 local + 10 global | 25 local + 5 global | 40 local + 8 global | 35 local + 7 global | 28 local + 7 global |
| Global layers reuse keys as values | yes | yes | yes | no | no |
| Layers sharing another layer’s cache | 0 | 0 | 0 | 18 | 20 |
| Type | Dense | Mixture-of-experts | Dense | Dense | Dense |
| FFN size | 21,504 | 2,112 | 15,360 | 10,240 | 6,144 |
| Activation | GELU (tanh) | GELU (tanh) | GELU (tanh) | GELU (tanh) | GELU (tanh) |
| Experts (active / total) | — | 8 / 128 | — | — | — |
| Expert size | — | 704 | — | — | — |
| Shared experts | none | 1 | none | none | none |
| Double-wide MLP flag | no | no | no | no | yes |
| Max context | 262,144 tokens | 262,144 tokens | 262,144 tokens | 131,072 tokens | 131,072 tokens |
| Position encoding | RoPE, base 1,000,000 | RoPE, base 1,000,000 | RoPE, base 1,000,000 | RoPE, base 1,000,000 | RoPE, base 1,000,000 |
| Per-layer embeddings | none | none | none | 256 dims | 256 dims |
| Tied embeddings | yes | yes | yes | yes | yes |
| Input types | text, image | text, image | text, image, audio | text, image, audio | text, image, audio |
| Encoders (approx.) | vision 550M | vision 550M | none | vision 150M, audio 300M | vision 150M, audio 300M |
| Vocabulary | 262,144 | 262,144 | 262,144 | 262,144 | 262,144 |
| Logit softcap | 30 | 30 | 30 | 30 | 30 |
Frequently asked questions
Is Gemma 4 a transformer model?
Yes. Gemma 4 follows a decoder-only transformer architecture, according to the Gemma 4 Technical Report. Its text model is a stack of transformer blocks, each with attention and a feed-forward network.
What is sliding-window attention in Gemma 4?
In most Gemma 4 layers each token attends only to the previous 1,024 tokens (512 in E2B and E4B). Every sixth layer is a global layer that attends to the whole context. E2B uses one global layer for every four local layers.
Does Gemma 4 use mixture-of-experts?
One variant does. Gemma 4 26B-A4B has 128 routed experts, routes each token to 8 of them and also runs 1 shared expert, activating 3.8B of 25.2B parameters. The E2B, E4B, 12B and 31B models are dense.
Are Gemma 4 E2B and E4B dense or mixture-of-experts models?
They are dense models: there are no experts and no router. Google's model card lists them with the 12B and 31B under dense models. The E stands for effective parameters. Per-layer embeddings make up part of the stored parameters but work as lookups, so E4B counts 4.5B effective parameters out of 8B with embeddings, and E2B counts 2.3B out of 5.1B.
How long is Gemma 4's context window?
The 31B, 26B-A4B and 12B models support 262,144 tokens (256K). E2B and E4B support 131,072 tokens (128K).
What is p-RoPE in Gemma 4?
p-RoPE is a form of rotary position embedding that rotates only a fraction p of the frequency pairs. Gemma 4 uses p = 0.25 on its global attention layers, with a base frequency of 1,000,000, and standard RoPE with a base of 10,000 on its local layers.
What does the E in Gemma 4 E4B mean?
E stands for effective parameters. E4B has 4.5B effective parameters out of 8B with embeddings, because its per-layer embeddings are tables used for lookups that add knowledge without adding much compute. E2B has 2.3B effective parameters out of 5.1B.
How is Gemma 4 different from Gemma 3 architecturally?
The layout is very similar: a 5:1 mix of sliding-window and global attention, grouped-query attention, and normalisation before and after each block. Gemma 4 adds keys reused as values on global layers, p-RoPE on global layers, a mixture-of-experts model, shared KV caches in its small models and an encoder-free 12B.
How much memory does the Gemma 4 KV cache need?
It depends on the variant and the context length. Under the assumptions on this page (bfloat16, keys stored once on global layers), one sequence needs about 2.18 GB of KV cache at 32K tokens, 6.21 GB at 128K and 11.6 GB at 256K on Gemma 4 31B; 0.55 GB, 1.55 GB and 2.89 GB on 26B-A4B; and 0.60 GB, 1.41 GB and 2.48 GB on 12B. E2B and E4B share key/value caches between layers, so this page does not estimate them. These figures are calculated from the published configs, not measured, and real inference engines can differ.
Which license does Gemma 4 use?
Gemma 4 models are released under the Apache 2.0 license, according to the technical report and the model cards on Hugging Face.
Sources
Specs last verified November 21, 2026.
- Gemma 4 Technical Report (Gemma Team, arXiv:2607.02770)
- google/gemma-4-31B: model card and config.json (Hugging Face)
- google/gemma-4-26B-A4B: model card and config.json (Hugging Face)
- google/gemma-4-12B: model card and config.json (Hugging Face)
- google/gemma-4-E4B: model card and config.json (Hugging Face)
- google/gemma-4-E2B: model card and config.json (Hugging Face)
- The Big LLM Architecture Comparison (Sebastian Raschka)
- Gemma 3 Technical Report (arXiv:2503.19786)
- GQA: Training Generalized Multi-Query Transformer Models (arXiv:2305.13245)
- Longformer: The Long-Document Transformer (arXiv:2004.05150)
- RoFormer: Enhanced Transformer with Rotary Position Embedding (arXiv:2104.09864)
- Root Mean Square Layer Normalization (arXiv:1910.07467)