Log inStart free
LESSON 29.07 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Prefix caching

Watch seven prompts reuse the KV blocks of their shared first tokens.


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

Go Pro · $8.25/mo
EXPLAINER · 29.07 · KV BAYPROMPT TOKENS 123 · SYSTEM PROMPT 70
01
Stage 1 of 6 · Shared prompt
Every prompt starts with the same 10-token system prompt. Here 70 of 123 prompt tokens are that system prompt.
Explain it simply

Each row is one request's prompt, cut into blocks of 4 tokens. Solid teal cells are the system prompt, the fixed instructions, and faint teal cells are each question. An ochre cell is a time stamp, and cobalt cells are R1's earlier answer. Each row repeats the system prompt, so the server computes its keys and values again and again.

Seven prompt rows in blocks of 4 tokens. 70 of 123 tokens are the shared system prompt.

prompt tokens, blocks in usehashes, R1's answer tokenstime stampmiss, evicted blockcached free blockempty block
R1AR2BR3AR4BR5AR6BR7Ablock 0Youareatravelblock 1guide.Keepanswersblock 2short.Whenisblock 3Romeleastbusy?prompts in blocks of 4 tokensR1's prompt, block by blockGPU · 32 KV blocks · before step 001234567R1AR2BR3AR4BR5AR6BR7Ablock 0Youareatravelblock 1guide.Keepanswersblock 2short.Whenisblock 3Romeleastbusy?prompts in blocks of 4 tokensR1's prompt, block by blockGPU · 32 KV blocks · before step 001234567
Toy: 29.C1's 6 requests on 32 blocks of 4, plus R7, R1's second turn
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
n=s+q\sy{n}{data}{n} = \sy{s}{data}{s} + \sy{q}{data}{q}
nR1=10+6=16n_{R1} = 10 + 6 = 16

A prompt is the system prompt plus a question.

Common mix-ups

MYTHA cache hit needs only the same words somewhere in the prompt.

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

Predict, then reveal
3 CHECKS · PRO
Q01With a shared cache and the stamp at the end, how many tokens does R2 reuse?

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

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 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.