Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 09 · AI · Serving LLMs · about 17 min to read

Play it as a journeyTutor comes with a plan

Prefix Caching (the same start, computed once)

Prefix Caching
Prefix Caching · Open board

Serving LLMs. Follows “The Two Clocks” (The Two Clocks (TTFT, TPOT, and why goodput is the number)), which put a name on the wait before a reply’s first word. This board takes that wait’s biggest fixed cost apart: the standing instructions every message to a chat product starts with, and the trick that pays for reading them only once.

Before you start. A model reads and writes in tokens: word-pieces, a few characters each, so “cancelling” might reach it as two of them. While it reads, it writes notes about every token it has already seen, so it never has to read those tokens again: that pile of notes is the KV cache from Inference (sampling, context, KV cache, hallucination). From The Two Clocks (TTFT, TPOT, and why goodput is the number) you need TTFT, time to first token: the wait before a reply’s first word, which is mostly one read of the whole prompt, called prefill.

Lesson 78 of 83 in AI

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • Two messages, one instruction sheet
  • 2023: a lab that watched the traffic notice it
  • The one idea: a transformer never reads ahead, so the shared start is a prefix
  • Pages, and the one walk that finds them
  • What it buys: 90 ms back, and the hit rate that decides how often
  • The rule this all rests on, and the two ways teams break it
  • What does the sheet leave behind?
  • How does the tree know two pages match?
  • Three users walk in
  • Where does the saving leak?
  • All of it in code

Terms it explains: prefix, pages, radix tree, hit rate.

Related paper

Review AI