Gemma · Google
Gemma 4 31B
Gemma 4 31B from Google has 30,697,345,340 parameters in its language model. Its weights take 61.4 GB in BF16 and about 15.3 GB at 4-bit, and each token of context adds 901.1 KB of KV cache (29.5 GB at 32K tokens). The checkpoint also carries a 576M-parameter vision encoder.
Part of the Gemma 4 family: 25.2B · 30.7B
Architecture · VRAM · KV cache · Tensor shapes · Parameter count · FLOPs
Architecture
| Architecture | Gemma4ForConditionalGeneration |
|---|---|
| Layers (L) | 60 |
| Hidden size (d) | 5,376 |
| Attention | GQA (8 query heads share each KV head) |
| Heads | 32 query, 4 key/value, 512 each |
| Feed-forward | GeGLU, hidden size 21,504 |
| Vocabulary (V) | 262,144 |
| Tied embeddings | yes: the output head reuses the embedding |
| Biases | none |
| Extra norms | pre-norm (RMSNorm before attention and FFN) |
| Max context | 262,144 tokens; 50 of 60 layers use a 1,024-token sliding window |
| Local layers | 32 query and 16 key/value heads of 256 (the global layers have 4 KV heads) |
| Vision encoder | ViT, 27 layers, 1,152 wide: 576M parameters with the projector (in the checkpoint, used only for images) |
| Weights in the release | – |
How much memory the weights need
Each parameter takes 4 bytes in FP32, 2 in BF16, 1 at 8 bits and half a byte at 4 bits, so the weights of the language model alone need:
| Precision | Bytes per parameter | Weights | |
|---|---|---|---|
| FP32 | 4 | 123 GB | 114.36 GiB |
| BF16 / FP16 | 2 | 61.4 GB | 57.18 GiB |
| INT8 / FP8 | 1 | 30.7 GB | 28.59 GiB |
| INT4 | 0.5 | 15.3 GB | 14.29 GiB |
GB here is 109 bytes; GiB (230) is what tools like nvidia-smi show. Real 4-bit files are a little larger: they also store scales, and some layers are often kept at higher precision. The vision encoder adds 1.2 GB in BF16 when used. A running model also needs its KV cache, activations and the runtime's own buffers.
On common GPUs
Whether the weights plus a 8K-token KV cache fit in 90% of the card (how this is worked out):
Smallest card: 80 GB at BF16, 48 GB at 8-bit, 48 GB at 4-bit.
| GPU memory | BF16 | 8-bit | 4-bit |
|---|---|---|---|
| 8 GB | 68.8 GBtoo big | 40.0 GBtoo big | 24.6 GBtoo big |
| 12 GB | 68.8 GBtoo big | 40.0 GBtoo big | 24.6 GBtoo big |
| 16 GB | 68.8 GBtoo big | 40.0 GBtoo big | 24.6 GBtoo big |
| 24 GB | 68.8 GBtoo big | 40.0 GBtoo big | 24.6 GBtoo big |
| 48 GB | 68.8 GBtoo big | 40.0 GB | 24.6 GB |
| 64 GB | 68.8 GBtoo big | 40.0 GB | 24.6 GB |
| 80 GB | 68.8 GB | 40.0 GB | 24.6 GB |
Each cell is the weights plus the 8K-token KV cache at that precision; ✓ where it fits.
KV cache
What it is: the KV cache, explained.
Only some layers keep keys and values, and not all of the same size:
10 global layers × 2 × 4 × 512 + 50 sliding-window layers × 2 × 16 × 256 × 2 bytes = 901,120 bytes per token
The global layers reuse their keys as values, so a runtime could keep one copy; the figure counts both, as most runtimes do.
| Context | KV cache, BF16 | 8-bit KV | With the sliding window | Weights + KV, BF16 |
|---|---|---|---|---|
| 4K | 3.7 GB | 1.8 GB | 1.2 GB | 65.1 GB |
| 32K | 29.5 GB | 14.8 GB | 3.5 GB | 90.9 GB |
| 128K | 118 GB | 59.1 GB | 11.6 GB | 180 GB |
| 256K (max) | 236 GB | 118 GB | 22.3 GB | 298 GB |
In the config, 50 of 60 layers use a 1,024-token sliding window. Runtimes that honour it never cache more than 1,024 tokens for those layers; the column shows what that saves.
For one sequence. Batching multiplies the KV cache by the number of sequences, not the weights.
Every tensor shape
The names are those in the Hugging Face checkpoint (the language model's sit under language_model.); shapes are [out, in] for weight matrices, as PyTorch stores them. One block is shown: the model repeats it 60 times (in two kinds).
| Tensor | Shape | Parameters |
|---|---|---|
| Embedding | ||
model.language_model.embed_tokens.weightalso used as the output head (tied) | [262,144, 5,376] | 1,409,286,144 |
| Sliding-window blocks (50 layers): model.layers.N.… | ||
self_attn.q_proj.weight | [8,192, 5,376] | 44,040,192 |
self_attn.k_proj.weight | [4,096, 5,376] | 22,020,096 |
self_attn.v_proj.weight | [4,096, 5,376] | 22,020,096 |
self_attn.o_proj.weight | [5,376, 8,192] | 44,040,192 |
self_attn.q_norm.weightshared by every head | [256] | 256 |
self_attn.k_norm.weight | [256] | 256 |
mlp.gate_proj.weight | [21,504, 5,376] | 115,605,504 |
mlp.up_proj.weight | [21,504, 5,376] | 115,605,504 |
mlp.down_proj.weight | [5,376, 21,504] | 115,605,504 |
input_layernorm.weight | [5,376] | 5,376 |
post_attention_layernorm.weight | [5,376] | 5,376 |
pre_feedforward_layernorm.weight | [5,376] | 5,376 |
post_feedforward_layernorm.weight | [5,376] | 5,376 |
layer_scalarone learned scale for the block | [1] | 1 |
| Global blocks (every 6th: layers 5, 11, …, 59): model.layers.N.… | ||
self_attn.q_proj.weight | [16,384, 5,376] | 88,080,384 |
self_attn.k_proj.weightthe keys are also the values: there is no v_proj | [2,048, 5,376] | 11,010,048 |
self_attn.o_proj.weight | [5,376, 16,384] | 88,080,384 |
self_attn.q_norm.weightshared by every head | [512] | 512 |
self_attn.k_norm.weight | [512] | 512 |
mlp.gate_proj.weight | [21,504, 5,376] | 115,605,504 |
mlp.up_proj.weight | [21,504, 5,376] | 115,605,504 |
mlp.down_proj.weight | [5,376, 21,504] | 115,605,504 |
input_layernorm.weight | [5,376] | 5,376 |
post_attention_layernorm.weight | [5,376] | 5,376 |
pre_feedforward_layernorm.weight | [5,376] | 5,376 |
post_feedforward_layernorm.weight | [5,376] | 5,376 |
layer_scalarone learned scale for the block | [1] | 1 |
| After the last block | ||
model.language_model.norm.weightfinal norm | [5,376] | 5,376 |
| Vision encoder: patches and positions | ||
model.vision_tower.patch_embedder.input_proj.weighteach 16×16 patch, flattened | [1,152, 768] | 884,736 |
model.vision_tower.patch_embedder.position_embedding_tablea learned table for each axis, rows and columns | [2, 10,240, 1,152] | 23,592,960 |
| Vision encoder: one layer (×27): …layers.N.… | ||
self_attn.q_proj.linear.weight | [1,152, 1,152] | 1,327,104 |
self_attn.k_proj.linear.weight | [1,152, 1,152] | 1,327,104 |
self_attn.v_proj.linear.weight | [1,152, 1,152] | 1,327,104 |
self_attn.o_proj.linear.weight | [1,152, 1,152] | 1,327,104 |
self_attn.q_norm.weight | [72] | 72 |
self_attn.k_norm.weight | [72] | 72 |
mlp.gate_proj.linear.weight | [4,304, 1,152] | 4,958,208 |
mlp.up_proj.linear.weight | [4,304, 1,152] | 4,958,208 |
mlp.down_proj.linear.weight | [1,152, 4,304] | 4,958,208 |
input_layernorm.weight | [1,152] | 1,152 |
post_attention_layernorm.weight | [1,152] | 1,152 |
pre_feedforward_layernorm.weight | [1,152] | 1,152 |
post_feedforward_layernorm.weight | [1,152] | 1,152 |
| Vision encoder: output and projector | ||
model.vision_tower.std_biasstandardizes the output | [1,152] | 1,152 |
model.vision_tower.std_scale | [1,152] | 1,152 |
model.embed_vision.embedding_projection.weightimage features to the language model's width | [5,376, 1,152] | 6,193,152 |
The parameter count, step by step
Each line gives the formula, the numbers from config.json, and the subtotal. The symbols:
- V
- vocabulary 262,144
- d
- hidden size 5,376
- L
- layers 60
- H
- query heads 32
- K
- key/value heads 4
- h
- head size 512
- f
- FFN hidden size 21,504
1. Embedding
One row of d numbers for each of the V tokens in the vocabulary.
2. Sliding-window blocks (50 layers), ×50
3. Global blocks (every 6th: layers 5, 11, …, 59), ×10
4. Final norm and output head
5. Total
6. Vision encoder
The checkpoint also holds an image encoder (Llama 4's own ViT, 27 layers of width d_v = 1,152, MLP f_v = 4,304) and a projector into the language model. It runs only when the prompt has an image, so it is listed apart from the language model.
patches and positions
one layer, ×27
output and projector
Hugging Face counts 31,273,088,876 parameters in the google/gemma-4-31B safetensors files. The arithmetic above matches exactly.
FLOPs per token
A forward pass costs about two floating-point operations (a multiply and an add) for every weight a token passes through: 2 × N, with N the weights used in matrix multiplies (the embedding lookup is a read, not a multiply; the output head is a multiply, even though it is tied to the embedding). Here that is 2 × 30,697,345,340 = 61.4 GFLOPs per token.
Attention adds the work of comparing the token with every earlier one: 2 × L × T × H × (hqk + hv) for T tokens of context, which grows with the context while 2N does not. Layers with a window see at most 1,024 tokens, which the table allows for.
That is for one new token at position T, as when generating. Averaged over a whole training sequence of length T, each token sees T/2 earlier ones on average, which halves it.
| Context T | 2N | Attention | Total per token |
|---|---|---|---|
| 4K | 61.4 GFLOPs | 4.4 GFLOPs | 65.8 GFLOPs |
| 32K | 61.4 GFLOPs | 23.2 GFLOPs | 84.5 GFLOPs |
| 128K | 61.4 GFLOPs | 87.6 GFLOPs | 149.0 GFLOPs |
| 256K | 61.4 GFLOPs | 173.5 GFLOPs | 234.9 GFLOPs |
Training costs about three times the forward pass per token (6N): the backward pass does roughly twice the forward work.
More in the glossary: FLOPs per token · quantization · parameters.
Compare
Gemma 4 31B vs Qwen3.5 27B · Gemma 4 31B vs Gemma 3 27B · Compare with any model →
Close in size: Qwen3 30B-A3B 30.5B · Nemotron 3 Nano 30B-A3B 31.6B · OLMo 3 32B 32.2B · OLMo 2 32B 32.2B · Qwen3 32B 32.8B
Source
Read from google/gemma-4-31B, fetched 2026-12-03. Gemma 4's smaller sizes (E2B, E4B and the 12B) add per-layer embeddings and an audio encoder, which this site does not yet count.