Datasets:
|
Download articles/gpu-memory-for-70b.md from inference-engineering-academy/llm-inference-notes: direct link, hf CLI and curl.
- Browser
- Download file 3.16 kB
-
https://huggingface.co/datasets/inference-engineering-academy/llm-inference-notes/resolve/main/articles/gpu-memory-for-70b.md
- Command line
-
hf download hf://datasets/inference-engineering-academy/llm-inference-notes/articles/gpu-memory-for-70b.md
-
curl -L -o gpu-memory-for-70b.md https://huggingface.co/datasets/inference-engineering-academy/llm-inference-notes/resolve/main/articles/gpu-memory-for-70b.md
3.16 kB
| # How much GPU memory do you need to serve a 70B model? | |
| Short answer for Llama 3.1 70B: about **141 GB for BF16 weights alone**, so plan on 2 x 80 GB GPUs as the bare minimum and 4 x 80 GB for comfortable serving. With FP8 it squeezes onto one 80 GB GPU for light traffic; with 4-bit it fits on one 80 GB GPU (or two 48 GB GPUs) with useful KV space. Here is the full calculation so you can redo it for any model. | |
| ## Step 1: weights | |
| Llama 3.1 70B has 70.6B parameters. | |
| - BF16: 70.6B x 2 bytes = **141.2 GB** (131.5 GiB) | |
| - FP8/INT8: 70.6B x 1 = **70.6 GB** (65.8 GiB) | |
| - INT4: 70.6B x 0.5 = **35.3 GB**, plus a few percent for quantization scales | |
| ## Step 2: KV cache per token | |
| From the model's config: 80 layers, 8 KV heads (grouped-query attention), head_dim 128. | |
| KV per token = 2 x 80 x 8 x 128 x 2 bytes = 327,680 bytes = **320 KiB** (BF16), or 160 KiB with an FP8 KV cache. | |
| Per sequence: | |
| - 4,096 tokens: 1.25 GiB | |
| - 8,192 tokens: 2.5 GiB | |
| - 32,768 tokens: 10 GiB | |
| - 128K tokens (the model's maximum, 131,072): 40 GiB | |
| ## Step 3: overhead | |
| Engines reserve memory for activations, CUDA graphs, and the CUDA context. Budget roughly 1 to 3 GiB per GPU, and remember engines like vLLM only use a fraction you set (`--gpu-memory-utilization`, default 0.9). | |
| ## Step 4: put it together | |
| Usable memory per 80 GB GPU at 0.9 utilization ~= 72 GB = 67 GiB, minus ~2 GiB overhead = ~65 GiB. | |
| | Setup | Usable | Weights | Left for KV | Tokens of KV (BF16) | 8K-token sequences | | |
| |---|---|---|---|---|---| | |
| | 1 x 80 GB, BF16 | 65 GiB | 131.5 GiB | does not fit | - | - | | |
| | 2 x 80 GB, BF16 | 130 GiB | 131.5 GiB | does not fit at 0.9 | - | - | | |
| | 2 x 80 GB, BF16, util 0.95 | ~138 GiB | 131.5 GiB | ~6 GiB | ~20K | ~2 | | |
| | 4 x 80 GB, BF16 | ~260 GiB | 131.5 GiB | ~129 GiB | ~420K | ~51 | | |
| | 1 x 80 GB, FP8 weights + FP8 KV | ~65 GiB | 65.8 GiB | does not fit at 0.9 | - | - | | |
| | 1 x 80 GB, INT4 weights | ~65 GiB | ~34 GiB | ~31 GiB | ~100K | ~12 | | |
| (Numbers from the formulas above; "8K-token sequences" = KV left / 2.5 GiB.) The FP8 row shows why "70B in FP8 fits on one H100" is only just true: you need to raise utilization close to 1.0 and keep context short. A 141 GB H200 holds FP8 70B comfortably (~50 GiB left for KV at 0.9 utilization). | |
| ## Step 5: choose by workload | |
| - **Few users, short prompts, budget-limited:** INT4 on one 80 GB GPU. | |
| - **Production chat at moderate scale:** BF16 or FP8 with tensor parallelism across 4 GPUs, or FP8 on 2 GPUs. | |
| - **Long context (32K+) for many users:** KV dominates; use FP8 KV cache, more GPUs, and prefix caching. | |
| ## Do it for any model | |
| Read `config.json` and use: | |
| - weights = params x bytes per param | |
| - KV/token = 2 x num_hidden_layers x num_key_value_heads x (hidden_size / num_attention_heads) x bytes | |
| - concurrent tokens = (usable memory - weights) / KV per token | |
| Our zero-dependency calculator does this for you: [kv_calc.py](https://github.com/inference-engineering-academy/inference-engineering-notes). | |
| --- | |
| *If you want to go deeper, the free Foundations course at [Inference Engineering Academy](https://www.inference-engineering.xyz/) covers these topics with browser labs. Disclosure: written by the academy team.* | |