Phi · Microsoft
Phi-4 Mini
Phi-4 Mini from Microsoft has 3,836,021,760 parameters. Its weights take 7.7 GB in BF16 and about 1.9 GB at 4-bit, and each token of context adds 131.1 KB of KV cache (4.3 GB at 32K tokens).
Part of the Phi family: 3.82B · 3.82B · 3.84B · 14.7B · 41.9B
Architecture · VRAM · KV cache · Tensor shapes · Parameter count · FLOPs
Architecture
| Architecture | Phi3ForCausalLM |
|---|---|
| Layers (L) | 32 |
| Hidden size (d) | 3,072 |
| Attention | GQA (3 query heads share each KV head) |
| Heads | 24 query, 8 key/value, 128 each |
| Feed-forward | SwiGLU, hidden size 8,192 |
| Vocabulary (V) | 200,064 |
| Tied embeddings | yes: the output head reuses the embedding |
| Biases | none |
| Extra norms | pre-norm (RMSNorm before attention and FFN) |
| Max context | 131,072 tokens |
| 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 alone need:
| Precision | Bytes per parameter | Weights | |
|---|---|---|---|
| FP32 | 4 | 15.3 GB | 14.29 GiB |
| BF16 / FP16 | 2 | 7.7 GB | 7.15 GiB |
| INT8 / FP8 | 1 | 3.8 GB | 3.57 GiB |
| INT4 | 0.5 | 1.9 GB | 1.79 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. 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 8 KV heads, for every token in the context:
2 × L × K × h × 2 bytes = 2 × 32 × 8 × 128 × 2 = 131,072 bytes per token
Grouped-query attention is why this is small: with a KV head for each of the 24 query heads it would be 3 times larger.
| Context | KV cache, BF16 | 8-bit KV | Weights + KV, BF16 |
|---|---|---|---|
| 4K | 537 MB | 268 MB | 8.2 GB |
| 32K | 4.3 GB | 2.1 GB | 12.0 GB |
| 128K (max) | 17.2 GB | 8.6 GB | 24.9 GB |
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; shapes are [out, in] for weight matrices, as PyTorch stores them. One block is shown: the model repeats it 32 times.
| Tensor | Shape | Parameters |
|---|---|---|
| Embedding | ||
model.embed_tokens.weightalso used as the output head (tied) | [200,064, 3,072] | 614,596,608 |
| Every block: model.layers.N.… | ||
self_attn.qkv_proj.weightq, k and v in one matrix | [5,120, 3,072] | 15,728,640 |
self_attn.o_proj.weight | [3,072, 3,072] | 9,437,184 |
mlp.gate_up_proj.weightgate and up in one matrix | [16,384, 3,072] | 50,331,648 |
mlp.down_proj.weight | [3,072, 8,192] | 25,165,824 |
input_layernorm.weight | [3,072] | 3,072 |
post_attention_layernorm.weight | [3,072] | 3,072 |
| After the last block | ||
model.norm.weightfinal norm | [3,072] | 3,072 |
The parameter count, step by step
Each line gives the formula, the numbers from config.json, and the subtotal. The symbols:
- V
- vocabulary 200,064
- d
- hidden size 3,072
- L
- layers 32
- H
- query heads 24
- K
- key/value heads 8
- h
- head size 128
- f
- FFN hidden size 8,192
1. Embedding
One row of d numbers for each of the V tokens in the vocabulary.
2. Every block, ×32
3. Final norm and output head
4. Total
Hugging Face counts 3,836,021,760 parameters in the microsoft/Phi-4-mini-instruct 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,836,021,760 = 7.7 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.
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.7 GFLOPs | 1.6 GFLOPs | 9.3 GFLOPs |
| 32K | 7.7 GFLOPs | 12.9 GFLOPs | 20.6 GFLOPs |
| 128K | 7.7 GFLOPs | 51.5 GFLOPs | 59.2 GFLOPs |
Training costs about three times the forward pass per token (6N): the backward pass does roughly twice the forward work.
Compare
Close in size: Phi-3 Mini 3.82B · Phi-3.5 Mini 3.82B · Gemma 3 4B 3.88B · Qwen3 4B 4.02B · Falcon3 3B 3.23B
Source
Read from microsoft/Phi-4-mini-instruct, fetched 2026-12-02.