What is model memory footprint?
Model memory footprint is the total memory an AI model occupies to run during inference or training, including weights, key and value cache, intermediate values and the runtime environment's own overhead.
Unlike parameter count, which gives only the number of weights, it covers weights times bytes per number plus other parts, chiefly the KV cache growing with context length and concurrency. One model thus needs different memory under different use.
- Topic
- Inference and performance
- Also known as
- Memory footprint
How model memory footprint works
- Weight memory is parameter count times bytes per parameter; quantisation lowers it.
- The KV cache takes 2 × layers × key and value heads × head size × bytes per token.
- Calculation: with 32 layers, 8 key and value heads, head size 128 and BF16, per token 2 × 32 × 8 × 128 × 2 = 131,072 bytes; for an 8,192-token sequence 131,072 × 8,192 bytes = 1 GiB.
- Intermediate values and engine working memory come on top.
In more detail
Training memory components: gradients, optimiser state and activations
In standard mixed-precision training (e.g., AdamW), memory footprint is several times larger than inference: besides weights, training stores gradients and FP32 optimiser states (momentum and variance, typically 12 to 16 bytes per parameter) plus intermediate activations unless activation checkpointing or ZeRO/FSDP sharding is used.
The effect of GQA, MLA, PagedAttention and FP8 KV caches
Modern LLMs sharply shrink KV cache per token using Grouped-Query Attention (GQA), Multi-Head Latent Attention (MLA) and sliding-window attention, while engines such as vLLM apply PagedAttention and FP8 KV-cache quantisation to prevent memory fragmentation and serve higher concurrency.
Peak prefill activations, runtime buffers and headroom
Even when weights and KV cache fit mathematically into VRAM, inference engines require headroom for peak prefill activations, CUDA context, NCCL buffers and allocator fragmentation. Production sizing therefore budgets memory headroom to avoid out-of-memory errors under bursty long-prompt traffic.
Commonly confused terms
| Term | How it differs |
|---|---|
| Peak memory usage | Peak memory footprint is the maximum instantaneous VRAM/RAM allocated during worst-case prefill, long context or gradient step, which determines whether an Out-Of-Memory (OOM) crash occurs, unlike average memory usage. |
Why model memory footprint matters for on-premises AI
Memory footprint is the core input to in-house hardware decisions, setting which GPU a model fits, how many concurrent users it serves and what context length it handles. A common mistake is counting only weights; with long context and many users the KV cache can exceed them. The calculation is therefore made with expected context length and concurrency, then confirmed by measuring under real load.
Choosing GPUs for an in-house assistant, an insurer adds the KV cache for its target context and 20 concurrent sessions to weight memory; when the total exceeds one GPU, it compares quantisation and context limits.
Common questions
Does model memory footprint depend only on parameter count?
No. Besides weights there is the KV cache, growing with context length and concurrency, plus intermediate values and runtime overhead.
How is memory footprint reduced?
By quantising weights and cache, limiting context length, managing the cache efficiently and choosing models with fewer key and value heads.
Related terms
Sources
- Pope et al., Efficiently Scaling Transformer Inference, 2022
- Kwon et al., Efficient Memory Management for Large Language Model Serving with PagedAttention, 2023
In the glossary: Glossary, M to Q