Tools › Model memory
Model memory: will it fit?
To run a language model, its weights and the attention cache must fit into GPU memory. Quantisation stores each weight with fewer bits, which shrinks the weights and makes bigger models fit on the same card.
How it is calculated
weights = parameters × bits_per_weight / 8. Quantised formats store a scale for every group of weights, so the real cost is a little more than the nominal bits: bits_per_weight = bits + 16 / group_size when each group keeps one 16-bit scale. Real formats differ in detail, for example some also keep a zero point or leave sensitive layers at higher precision. Treat the number as an estimate within a few percent.
The KV cache is the same calculation as in the KV-cache calculator, so you can compare architectures: a model with grouped-query or latent attention needs far less cache than one with full multi-head attention.
total = weights + KV cache + runtime overhead. The overhead is your own estimate for the CUDA context, activations and memory fragmentation.
Mixture-of-experts models
A mixture-of-experts model only uses a few experts per token (the active parameters), but it needs all of them in memory, because any token may need any expert. So memory follows the total parameters, while speed follows the active parameters.
The speed estimate
Generating one token at batch size 1 has to read every active weight once from GPU memory. So memory bandwidth divided by the bytes of active weights is an upper limit for tokens per second. Real systems stay below it because of attention, communication between GPUs and software overhead. Larger batches change the picture, since the weights are then read once for many sequences.
What it ignores
Offloading to CPU memory or disk, activation memory for long prompts, paged-attention block rounding, LoRA adapters, draft models for speculative decoding, and the exact size of embedding tables, which some formats keep at higher precision.
References
- Dettmers, Zettlemoyer, The case for 4-bit precision: k-bit inference scaling laws (2022)
- Frantar et al., GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers (2022)
- Lin et al., AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration (2023)
- Pope et al., Efficiently Scaling Transformer Inference (2022)