LESSON 29.04 · 6 STAGES · 2 CONTROLS · 3 CHECKSPRO · PREVIEW
KV-cache allocation and fragmentation
Watch six requests claim, waste and lose ranges of one GPU's KV-cache memory.
Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 2 controls and 3 checks, in this lesson and every other.
Go Pro · $8.25/moEXPLAINER · 29.04 · KV BAYSTEP 0 · R2 AT SLOT 24
01
Stage 1 of 6 · Cache layout
Each slot holds the keys and values of one token. R2's tokens fill one unbroken range from slot 24.
Explain it simply
Think of the GPU memory as one long shelf of 128 numbered slots. Each slot keeps the keys and values of one token. R2 gets one unbroken stretch that starts at slot 24. Its first 10 slots hold the system prompt, and the next 3 hold its question.
A grid of 128 slots in 4 rows. R2 holds slots 24 to 44: 10 system prompt tokens, 3 question tokens, then empty reserved slots.
cached tokensdashed: empty reserve or holefree slotwasted: never used or preempted; dashed: waitingtime cursor
Toy: 29.C1's 6 requests, a 10-token system prompt, 128 slots
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
Token i of a request sits i slots after its first slot.
PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
- 5 more stages and 2 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.