Log inStart free
LESSON 29.06 · 5 STAGES · 2 CONTROLS · 3 CHECKSPRO · PREVIEW

Prefix sharing and copy-on-write

Watch six requests share one system prompt's KV blocks, then copy before a write.


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

Go Pro · $8.25/mo
EXPLAINER · 29.06 · KV BAYPREFIX 10 TOKENS · 2 FULL BLOCKS + 2 SLOTS
01
Stage 1 of 5 · One prefix
The server computes the 10-token system prompt once. It fills 2 blocks and 2 slots of block 2.
Explain it simply

All six prompt rows start with the same ten words. A token's keys and values depend only on the tokens before it. So these ten tokens get the same cache in every request. The server works them out once and keeps them in the block grid.

Six prompt rows share their first 10 tokens. Blocks 0–2 hold them, with a count of 1.

cached tokens: system prompt strong, question faintfree slotdashed: token not in the cachereference countcopyanother request's token, or a preemption
prompts in logical blocksGPU: 32 blocks of 4 slots (128 slots)number under each: its physical block (the block table)the same 10 tokens in every prompt012serverR1R2R3R4R5R6011121345678910111213141516171819202122232425262728293031block 2count 1: servershort.··one prefixprompts in logical blocksGPU: 32 blocks of 4 slots (128 slots)number under each: its physical block (the block table)the same 10 tokens in every prompt012serverR1R2R3R4R5R6011121345678910111213141516171819202122232425262728293031block 2count 1: servershort.··one prefix
Toy: 29.C1's 6 requests, a 10-token system prompt, 128 slots
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
F=⌊10/B⌋,P=10 mod B\sy{f}{data}{F} = \left\lfloor 10 / \sy{b}{param}{B} \right\rfloor,\quad \sy{p}{data}{P} = 10 \bmod \sy{b}{param}{B}
F=⌊10/4⌋=2,P=10 mod 4=2F = \lfloor 10/4 \rfloor = 2,\quad P = 10 \bmod 4 = 2

The prompt fills F whole blocks and P slots of one more.

Common mix-ups

MYTHA shared block can take a write in place.

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

Predict, then reveal
3 CHECKS · PRO
Q01With blocks of 2 tokens, how many blocks does copy-on-write copy?

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 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.