Anatomy of LLM inference
Weight memory
How many bytes a model's weights take, from parameter count times bytes per parameter, and why precision decides what fits.
A model's weights are the learned numbers that define it. Serving starts by loading them into GPU memory, so their size is the first thing to check. The rule is simple: weight bytes equal the number of parameters times the bytes each parameter takes.
Concept
A parameter is one learned number in the network. "70B" means about seventy billion of them. HBM (high-bandwidth memory) is the main memory on a GPU. Weights, activations and the KV cache all live there.
The big idea
Think of each parameter as a cell that needs room for its number. The width of the number depends on precision. Halve the width and you halve the room.
The analogy breaks for training. Training also stores gradients and optimizer states. Serving only needs the weights, plus the KV cache covered later.
Walking through it
weight_bytes ≈ params × bytes_per_param| Precision | Bytes per param | 8B model | 70B model |
|---|---|---|---|
| FP32 | 4 | 32 GB | 280 GB |
| BF16 / FP16 | 2 | 16 GB | 140 GB |
| FP8 / INT8 | 1 | 8 GB | 70 GB |
| INT4 / FP4 (weights only) | 0.5 | 4 GB | 35 GB |
Now check an 80 GB H100 against two models:
- 8B in BF16: 8e9 × 2 = 16 GB. Fits with plenty of room.
- 70B in BF16: 70e9 × 2 = 140 GB. Does not fit on one GPU. You need two GPUs or a lower precision.
- 70B in FP8: 70e9 × 1 = 70 GB. Fits in theory, but leaves little room for the KV cache. Production usually still uses two or more GPUs.
Common mistakes
- Treating "fits in memory" as "can serve users." Weights are the fixed cost. The cache for live requests comes on top.
- Forgetting the bytes per parameter. INT4 is half a byte, not four bits of overhead.
- Using training rules. Gradients and optimizer states do not matter for inference.
- Mixing up MoE sizes. A mixture-of-experts model stores all experts in memory, even though each token uses only some of them. See serving MoE models.
Check yourself
- How much memory do 13 billion parameters take in FP16? Answer: 13e9 × 2 bytes = 26 GB.
- Why does FP8 make a 70B model easier to fit than BF16? Answer: It halves the bytes per parameter, from 140 GB to 70 GB, which still leaves little room on one 80 GB card.
Key takeaways
- Weight bytes = parameters × bytes per parameter.
- Precision is the biggest lever. BF16 to FP8 halves the footprint.
- Fitting the weights is necessary but not enough. The cache must fit too.
- Next, check how fast a single stream can go in the decode latency floor.
Further learning
The roofline model explains why these byte counts, and not FLOPs, set decode speed.
Related
Inference arithmetic
Napkin math for any model on any GPU: weight memory, decode and prefill time, batch limits and KV budget.
Quantization
INT8, FP8, INT4 and FP4. Fewer bits shrink weights, activations and KV. Match the format to memory-bound decode or compute-bound prefill, then eval quality.
Parallelism for inference
Tensor, pipeline, data and context parallelism: splitting a model across GPUs so weights and KV fit, and single-request latency stays under SLO.