Phi-3 mini 4k: how much VRAM does it need?

Phi-3 mini 4k has 3.82B parameters in 32 layers. It uses full multi-head attention: each of its 32 heads keeps its own keys and values, so the KV cache is as large as its head count makes it. It takes up to 4,096 tokens of context; one user at that length needs 1.50 GiB of KV cache at FP16 on top of the weights.

BF16 · 4k context · one user
9.42 GiB

7.12 GiB of weights, 1.50 GiB of KV cache and 821 MiB of vLLM's overhead. At INT4 the same workload needs 4.46 GiB.

  • 32 layers
  • hidden 3072
  • 32/32 heads
  • head_dim 96
  • 4k max context

Phi-3 mini 4k memory by precision and context

Precision4k context
BF169.42 GiBKV cache 1.50 GiB
FP86.04 GiBKV cache 1.50 GiB
INT44.46 GiBKV cache 1.50 GiB

One user, FP16 KV cache and vLLM's overhead on one GPU at its defaults for a card under 70 GB. Quantizing shrinks the weights, not the KV cache, so the saving narrows as the context grows.

Which single GPUs hold it

At 4k context for one user, the smallest cards first. A discrete card is budgeted at vLLM's default 92% of its memory, a unified-memory device at the share its GPU can address, and each carries vLLM's overhead at its own defaults.

How many users fit

Users at 4k context each, on one card. ✗: the weights leave no room for even one.

Fine-tuning Phi-3 mini 4k

MethodMemorySmallest GPU
Full fine-tune58.30 GiBAMD MI210
LoRA (rank 16, attention)8.65 GiBRTX 3060
QLoRA (rank 16, attention)3.37 GiBRTX 3060

Sequence length 2,048, batch size 1, gradient checkpointing on, Adam. Full fine-tuning keeps 16 bytes per parameter before activations; QLoRA stores the frozen base in 4-bit NF4.

Where the numbers come from

Weights are parameters × bytes per parameter. The KV cache is 2 × layers × key-value heads × head dimension × bytes × context × users. For Phi-3 mini 4k that is 384.0 KiB per token at FP16. These are capacity-planning figures: the serving engine — vLLM, TGI, llama.cpp — and its paged-attention efficiency still move the real number.

More on KV cache size and on GQA, MQA and MLA.

Work with Phi-3 mini 4k