Gemma · Google

Gemma 3 4B

Gemma 3 4B from Google has 3,880,263,168 parameters in its language model. Its weights take 7.8 GB in BF16 and about 1.9 GB at 4-bit, and each token of context adds 139.3 KB of KV cache (4.6 GB at 32K tokens). The checkpoint also carries a 420M-parameter vision encoder.

3.88Bparameters
7.8 GBBF16 weights
1.9 GB4-bit weights
139.3 KBKV per token

Part of the Gemma 3 family: 268M · 1B · 3.88B · 11.8B · 27B

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

Architecture

ArchitectureGemma3ForConditionalGeneration
Layers (L)34
Hidden size (d)2,560
AttentionGQA (2 query heads share each KV head)
Heads8 query, 4 key/value, 256 each
Feed-forwardGeGLU, hidden size 10,240
Vocabulary (V)262,208
Tied embeddingsyes: the output head reuses the embedding
Biasesnone
Extra normsRMSNorm on q and k (per head); norms before and after attention and FFN
Max context131,072 tokens; 29 of 34 layers use a 1,024-token sliding window
Vision encoderSigLIP, 27 layers, 1,152 wide: 420M parameters with the projector (in the checkpoint, used only for images)
Weights in the releasebfloat16

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
FP32415.5 GB14.46 GiB
BF16 / FP1627.8 GB7.23 GiB
INT8 / FP813.9 GB3.61 GiB
INT40.51.9 GB1.81 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 840 MB in BF16 when images are 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):

GPU memoryBF168-bit4-bit
8 GB–✓✓
12 GB✓✓✓
16 GB✓✓✓
24 GB✓✓✓
48 GB✓✓✓
80 GB✓✓✓

KV cache

Every layer keeps a key and a value vector for each of its 4 KV heads, for every token in the context:

2 × L × K × h × 2 bytes = 2 × 34 × 4 × 256 × 2 = 139,264 bytes per token

Grouped-query attention is why this is small: with a KV head for each of the 8 query heads it would be 2 times larger.

ContextKV cache, BF168-bit KVWith the sliding windowWeights + KV, BF16
4K570 MB285 MB206 MB8.3 GB
32K4.6 GB2.3 GB793 MB12.3 GB
128K (max)18.3 GB9.1 GB2.8 GB26.0 GB

In the config, 29 of 34 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 34 times.

TensorShapeParameters
Embedding
model.embed_tokens.weightalso used as the output head (tied)[262,208, 2,560]671,252,480
Every block: model.layers.N.…
self_attn.q_proj.weight[2,048, 2,560]5,242,880
self_attn.k_proj.weight[1,024, 2,560]2,621,440
self_attn.v_proj.weight[1,024, 2,560]2,621,440
self_attn.o_proj.weight[2,560, 2,048]5,242,880
self_attn.q_norm.weightshared by every head[256]256
self_attn.k_norm.weight[256]256
mlp.gate_proj.weight[10,240, 2,560]26,214,400
mlp.up_proj.weight[10,240, 2,560]26,214,400
mlp.down_proj.weight[2,560, 10,240]26,214,400
input_layernorm.weight[2,560]2,560
post_attention_layernorm.weight[2,560]2,560
pre_feedforward_layernorm.weight[2,560]2,560
post_feedforward_layernorm.weight[2,560]2,560
After the last block
model.norm.weightfinal norm[2,560]2,560
Vision encoder: patches and positions
vision_tower.vision_model.embeddings.patch_embedding.weighta 14×14 convolution over the image[1,152, 3, 14, 14]677,376
vision_tower.vision_model.embeddings.patch_embedding.bias[1,152]1,152
vision_tower.vision_model.embeddings.position_embedding.weightone per patch of a 896×896 image[4,096, 1,152]4,718,592
Vision encoder: one layer (×27): …layers.N.…
self_attn.q_proj.weight[1,152, 1,152]1,327,104
self_attn.q_proj.bias[1,152]1,152
self_attn.k_proj.weight[1,152, 1,152]1,327,104
self_attn.k_proj.bias[1,152]1,152
self_attn.v_proj.weight[1,152, 1,152]1,327,104
self_attn.v_proj.bias[1,152]1,152
self_attn.out_proj.weight[1,152, 1,152]1,327,104
self_attn.out_proj.bias[1,152]1,152
mlp.fc1.weight[4,304, 1,152]4,958,208
mlp.fc1.bias[4,304]4,304
mlp.fc2.weight[1,152, 4,304]4,958,208
mlp.fc2.bias[1,152]1,152
layer_norm1.weight[1,152]1,152
layer_norm1.bias[1,152]1,152
layer_norm2.weight[1,152]1,152
layer_norm2.bias[1,152]1,152
Vision encoder: final norm and projector
vision_tower.vision_model.post_layernorm.weight[1,152]1,152
vision_tower.vision_model.post_layernorm.bias[1,152]1,152
multi_modal_projector.mm_input_projection_weightimage features to the language model's width[1,152, 2,560]2,949,120
multi_modal_projector.mm_soft_emb_norm.weight[1,152]1,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,208
d
hidden size 2,560
L
layers 34
H
query heads 8
K
key/value heads 4
h
head size 256
f
FFN hidden size 10,240

1. Embedding

One row of d numbers for each of the V tokens in the vocabulary.

Embedding
V × d
262,208 × 2,560
= 671,252,480

2. Every block, ×34

Attention
H·h × d + 2 × (K·h × d) + d × H·h + 2 × h
2,048 × 2,560 + 2 × (1,024 × 2,560) + 2,560 × 2,048 + 2 × 256
= 15,729,152
Feed-forward (GeGLU)
2 × (f × d) + d × f
2 × (10,240 × 2,560) + 2,560 × 10,240
= 78,643,200
Norms
4 × d
4 × 2,560
= 10,240
One block
attention + feed-forward + norms
15,729,152 + 78,643,200 + 10,240
= 94,382,592
34 blocks
L × block
34 × 94,382,592
= 3,209,008,128

3. Final norm and output head

Final norm (the head is the embedding, tied: 0 more)
d
2,560
= 2,560

4. Total

Language model
embedding + blocks + final
671,252,480 + 3,209,008,128 + 2,560
= 3,880,263,168

5. Vision encoder

The checkpoint also holds an image encoder (SigLIP, 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 + d_v + (img/p)² × d_v
1,152 × 3 × 14 × 14 + 1,152 + 4,096 × 1,152
= 5,397,120

one layer, ×27

Attention
4 × (d_v × d_v) + 4 × d_v
4 × (1,152 × 1,152) + 4 × 1,152
= 5,313,024
MLP
f_v × d_v + f_v + d_v × f_v + d_v
4,304 × 1,152 + 4,304 + 1,152 × 4,304 + 1,152
= 9,921,872
LayerNorms
4 × d_v
4 × 1,152
= 4,608
One block
attention + mlp + layernorms
5,313,024 + 9,921,872 + 4,608
= 15,239,504
27 blocks
27 × block
27 × 15,239,504
= 411,466,608

final norm and projector

Into the language model
3 × d_v + d_v × d
3 × 1,152 + 1,152 × 2,560
= 2,952,576
Vision encoder
the parts above
5,397,120 + 411,466,608 + 2,952,576
= 419,816,304
In the checkpoint
language model + vision
3,880,263,168 + 419,816,304
= 4,300,079,472

Hugging Face counts 4,300,079,472 parameters in the unsloth/gemma-3-4b-pt 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 × 3,880,263,168 = 7.8 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
4K7.8 GFLOPs411.0 MFLOPs8.2 GFLOPs
32K7.8 GFLOPs1.6 GFLOPs9.3 GFLOPs
128K7.8 GFLOPs5.6 GFLOPs13.4 GFLOPs

Training costs about three times the forward pass per token (6N): the backward pass does roughly twice the forward work.

Compare

Gemma 3 4B vs Qwen3 4B · Compare with any model →

Close in size: Phi-4 Mini 3.84B · Phi-3 Mini 3.82B · Phi-3.5 Mini 3.82B · Qwen3 4B 4.02B · Falcon3 3B 3.23B

Source

Read from unsloth/gemma-3-4b-pt, an ungated copy of google/gemma-3-4b-pt (which needs a sign-in to download), fetched 2026-12-02.