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.

30.7Bparameters
61.4 GBBF16 weights
15.3 GB4-bit weights
901.1 KBKV per token

Part of the Gemma 4 family: 25.2B · 30.7B

Architecture · VRAM · KV cache · Tensor shapes · Parameter count · FLOPs

Architecture

ArchitectureGemma4ForConditionalGeneration
Layers (L)60
Hidden size (d)5,376
AttentionGQA (8 query heads share each KV head)
Heads32 query, 4 key/value, 512 each
Feed-forwardGeGLU, hidden size 21,504
Vocabulary (V)262,144
Tied embeddingsyes: the output head reuses the embedding
Biasesnone
Extra normspre-norm (RMSNorm before attention and FFN)
Max context262,144 tokens; 50 of 60 layers use a 1,024-token sliding window
Local layers32 query and 16 key/value heads of 256 (the global layers have 4 KV heads)
Vision encoderViT, 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:

PrecisionBytes per parameterWeights
FP324123 GB114.36 GiB
BF16 / FP16261.4 GB57.18 GiB
INT8 / FP8130.7 GB28.59 GiB
INT40.515.3 GB14.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.

Memory calculator

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 memoryBF168-bit4-bit
8 GB68.8 GBtoo big40.0 GBtoo big24.6 GBtoo big
12 GB68.8 GBtoo big40.0 GBtoo big24.6 GBtoo big
16 GB68.8 GBtoo big40.0 GBtoo big24.6 GBtoo big
24 GB68.8 GBtoo big40.0 GBtoo big24.6 GBtoo big
48 GB68.8 GBtoo big40.0 GB24.6 GB
64 GB68.8 GBtoo big40.0 GB24.6 GB
80 GB68.8 GB40.0 GB24.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.

ContextKV cache, BF168-bit KVWith the sliding windowWeights + KV, BF16
4K3.7 GB1.8 GB1.2 GB65.1 GB
32K29.5 GB14.8 GB3.5 GB90.9 GB
128K118 GB59.1 GB11.6 GB180 GB
256K (max)236 GB118 GB22.3 GB298 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).

TensorShapeParameters
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.

Embedding
V × d
262,144 × 5,376
= 1,409,286,144

2. Sliding-window blocks (50 layers), ×50

Attention (sliding window)
H·h × d + 2 × (K·h × d) + d × H·h + 2 × h
8,192 × 5,376 + 2 × (4,096 × 5,376) + 5,376 × 8,192 + 2 × 256
= 132,121,088
Feed-forward (GeGLU)
2 × (f × d) + d × f
2 × (21,504 × 5,376) + 5,376 × 21,504
= 346,816,512
Norms and scale
4 × d + 1
4 × 5,376 + 1
= 21,505
One block
attention + feed-forward + norms and scale
132,121,088 + 346,816,512 + 21,505
= 478,959,105
50 blocks
50 × block
50 × 478,959,105
= 23,947,955,250

3. Global blocks (every 6th: layers 5, 11, …, 59), ×10

Attention (global)
H·h_g × d + K_g·h_g × d + d × H·h_g + 2 × h_g
16,384 × 5,376 + 2,048 × 5,376 + 5,376 × 16,384 + 2 × 512
= 187,171,840
Feed-forward (GeGLU)
2 × (f × d) + d × f
2 × (21,504 × 5,376) + 5,376 × 21,504
= 346,816,512
Norms and scale
4 × d + 1
4 × 5,376 + 1
= 21,505
One block
attention + feed-forward + norms and scale
187,171,840 + 346,816,512 + 21,505
= 534,009,857
10 blocks
10 × block
10 × 534,009,857
= 5,340,098,570

4. Final norm and output head

Final norm (the head is the embedding, tied: 0 more)
d
5,376
= 5,376

5. Total

Language model
embedding + blocks + final
1,409,286,144 + 23,947,955,250 + 5,340,098,570 + 5,376
= 30,697,345,340

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

Patch embedding
d_v × C·p·p + 2 × n_pos × d_v
1,152 × 768 + 2 × 10,240 × 1,152
= 24,477,696

one layer, ×27

Attention
4 × (d_v × d_v) + 2 × h_v
4 × (1,152 × 1,152) + 2 × 72
= 5,308,560
MLP (gated)
2 × (f_v × d_v) + d_v × f_v
2 × (4,304 × 1,152) + 1,152 × 4,304
= 14,874,624
Norms
4 × d_v
4 × 1,152
= 4,608
One block
attention + mlp + norms
5,308,560 + 14,874,624 + 4,608
= 20,187,792
27 blocks
27 × block
27 × 20,187,792
= 545,070,384

output and projector

Into the language model
2 × d_v + d × d_v
2 × 1,152 + 5,376 × 1,152
= 6,195,456
Vision encoder
the parts above
24,477,696 + 545,070,384 + 6,195,456
= 575,743,536
In the checkpoint
language model + vision
30,697,345,340 + 575,743,536
= 31,273,088,876

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 T2NAttentionTotal per token
4K61.4 GFLOPs4.4 GFLOPs65.8 GFLOPs
32K61.4 GFLOPs23.2 GFLOPs84.5 GFLOPs
128K61.4 GFLOPs87.6 GFLOPs149.0 GFLOPs
256K61.4 GFLOPs173.5 GFLOPs234.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.