Facts · Inference · 7 cards

Memory

Where the gigabytes go when a model remembers your chat

Chat memory for one Llama 3 70B conversation

8K tokens2.6 GB
32K tokens10.5 GB
128K tokens42 GB
Whole H100 GPU80 GB
The KV cache grows with every token, so a single 128K chat fills half of an 80 GB GPU. Source: Meta, The Llama 3 Herd of Models, 2024

These facts come up in the course How AI Reads, where each one is explained step by step.

1

42 GB

Memory for one long chat with Llama 3 70B

A single 128K-token conversation with Llama 3 70B carries 42 GB of KV cache (the model's notes on every past token). That is half an 80 GB H100 GPU.

How we got this number

320 KiB per token × 128,000 tokens ≈ 42 GB. At 8K tokens the same chat needs 2.6 GB; at 32K, 10.5 GB.

Source: Meta, The Llama 3 Herd of Models, 2024

2

141 GB

Just to load a 70B model, before anyone chats

Full-quality serving takes 2 bytes per parameter in bf16 (16-bit numbers). An 8B model is 16 GB; a 70B model is 141 GB; a 405B model is 810 GB.

How we got this number

Parameters × 2 bytes. About 70.6 billion × 2 ≈ 141 GB, more than one 80 GB GPU holds.

Source: Meta, The Llama 3 Herd of Models, 2024

3

320 KiB

Left behind by every single token you type

Every layer saves a key and a value for each token, so later words can look back without recomputing. In Llama 3 70B that totals 320 KiB per token.

How we got this number

2 (key and value) × 80 layers × 8 KV heads × 128 numbers per head × 2 bytes = 327,680 bytes = 320 KiB.

Source: Meta, The Llama 3 Herd of Models, 2024

4

Wait, really?

Would a 175B model need more chat memory than a 405B model?

Show the answer

Yes: 604 GB versus 66 GB at 128K tokens.

GPT-3 kept keys and values for all 96 heads. Llama 3.1 405B uses grouped-query attention, so its 128 query heads share just 8 KV heads. How a model is built matters as much as its size.

Source: Ainslie et al., GQA, 2023

5

KV cache for one 128K-token conversation

Llama 3 70B42 GB
DeepSeek-V39 GB
Llama 3 70B: 42 GB; DeepSeek-V3: 9 GB.

DeepSeek-V3 uses latent attention: it squeezes each layer's keys and values into one 576-number vector per token, about 70 KB per token in all.

Source: DeepSeek-AI, DeepSeek-V3 Technical Report, 2024

6

< 4%

KV memory wasted with PagedAttention, down from 60-80%

Servers used to reserve room for each request's longest possible chat, mostly empty. vLLM's PagedAttention hands out cache in small pages on demand, like an operating system.

Source: Kwon et al., PagedAttention, SOSP 2023

7

Guess first

A 70B model in fp8 uses about 70 GB of an 80 GB H100. Roughly how many tokens of chat memory fit in what is left?

  1. About 2,500
  2. About 250,000
  3. About 25,000
Show the answer

About 25,000

About 8 GB remains after overhead. At 320 KiB per token that is roughly 25,000 tokens across all users. One long document fills it.

Source: Meta, The Llama 3 Herd of Models, 2024