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.
Part of the Gemma 3 family: 268M · 1B · 3.88B · 11.8B · 27B
Architecture · VRAM · KV cache · Tensor shapes · Parameter count · FLOPs
Architecture
| Architecture | Gemma3ForConditionalGeneration |
|---|---|
| Layers (L) | 34 |
| Hidden size (d) | 2,560 |
| Attention | GQA (2 query heads share each KV head) |
| Heads | 8 query, 4 key/value, 256 each |
| Feed-forward | GeGLU, hidden size 10,240 |
| Vocabulary (V) | 262,208 |
| Tied embeddings | yes: the output head reuses the embedding |
| Biases | none |
| Extra norms | RMSNorm on q and k (per head); norms before and after attention and FFN |
| Max context | 131,072 tokens; 29 of 34 layers use a 1,024-token sliding window |
| Vision encoder | SigLIP, 27 layers, 1,152 wide: 420M parameters with the projector (in the checkpoint, used only for images) |
| Weights in the release | bfloat16 |
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 | 15.5 GB | 14.46 GiB |
| BF16 / FP16 | 2 | 7.8 GB | 7.23 GiB |
| INT8 / FP8 | 1 | 3.9 GB | 3.61 GiB |
| INT4 | 0.5 | 1.9 GB | 1.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.
On common GPUs
Whether the weights plus a 8K-token KV cache fit in 90% of the card (how this is worked out):
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.
| Context | KV cache, BF16 | 8-bit KV | With the sliding window | Weights + KV, BF16 |
|---|---|---|---|---|
| 4K | 570 MB | 285 MB | 206 MB | 8.3 GB |
| 32K | 4.6 GB | 2.3 GB | 793 MB | 12.3 GB |
| 128K (max) | 18.3 GB | 9.1 GB | 2.8 GB | 26.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.
| Tensor | Shape | Parameters |
|---|---|---|
| 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.
2. Every block, ×34
3. Final norm and output head
4. Total
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
one layer, ×27
final norm and projector
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 T | 2N | Attention | Total per token |
|---|---|---|---|
| 4K | 7.8 GFLOPs | 411.0 MFLOPs | 8.2 GFLOPs |
| 32K | 7.8 GFLOPs | 1.6 GFLOPs | 9.3 GFLOPs |
| 128K | 7.8 GFLOPs | 5.6 GFLOPs | 13.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.