Log inStart free
LESSON 29.C5 · 5 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Serving a 128K-token prompt

Watch one long prompt fill a GPU, then spread over many.


Pro lesson. Stage 1 is free to watch. Pro opens all 5 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 29.C5 · SERVING BAYCACHE 16 GIB · 30.96 GIB OF 80
01
Stage 1 of 5 · Cache size
Each token keeps 128 KiB of KV cache. 128K tokens need 16 GiB.
Explain it simply

Every token of the prompt leaves keys and values in all 32 layers, 128 KiB in all. Each bar is one GPU's memory: the weights first, then the cache. A long prompt can need more room than the weights. At 1M tokens a full bfloat16 cache is 128 GiB, more than a whole GPU.

1 memory bar. Each GPU holds 14.96 GiB of weights and 16 GiB of cache. It fits in 80 GiB.

tokens, cache, math timeweightstime, totals, sendsdoes not fitwaiting for sendsfree memory
GPU memoryGPU30.96 GiB80 GiBprompt: 131,072 tokenscache per GPU16 GiB cache + 14.96 GiB weights = 30.96 GiB ≤ 80 GiB29.0329.099.069.0829.1829.0711.14GPU memoryGPU30.96 GiB80 GiBprompt: 131,072 tokenscache per GPU16 GiB cache + 14.96 GiB weights = 30.96 GiB ≤ 80 GiB29.0329.099.069.0829.1829.0711.14
Toy: Llama 3 8B shape on 80 GiB H100s · one prompt alone
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
Mkv=T⋅btok / G\sy{kv}{data}{M_{kv}} = \sy{t}{data}{T} \cdot \sy{b}{param}{b_{tok}} \,/\, \sy{g}{param}{G}
Mkv=131072⋅128 KiB / 1=16 GiBM_{kv} = 131072 \cdot 128\,\text{KiB} \,/\, 1 = 16\,\text{GiB}

The cache per GPU is tokens times bytes a token, over the GPUs.

Common mix-ups

MYTHChunked prefill keeps every step short at any length.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With 1 GPU and no trick, how much shorter is the 32K TTFT than the 128K one?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
  • 4 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.