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 08 · AI · Serve the GPT you built · with code: Python · about 49 min to read

Watch: Attention in production: KV cache, MQA, GQA and MLA
▶ VideoPlay it as a journeyTutor comes with a plan

Paged Attention: The Cache in Blocks

Walk through it, one picture at a time 10 short steps

Inference at Scale
Inference at Scale · Open board

The Inference at Scale board draws a card’s memory filling up with other people’s saved notes. This lesson builds the fix it points at: hand the memory out in small blocks, and keep a table of who holds which. Stage 3 of the serving series, after Build Your Own Inference Engine.

Before you start. Serve 01: The KV Cache built the cache, the two arrays of saved keys and values, and Batching: A Slot That Frees Early filled the engine’s slots from a queue the moment one freed. Both quietly assumed that every slot owns one fixed stretch of memory, big enough for the longest reply the model can read. This lesson asks what that assumption costs. Inference at Scale (why an LLM is fast, and cheap) told the PagedAttention story without code. The operating-system idea underneath is in The address book every process carries.

Lesson 73 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

  • October 2023: the cache was the problem, and most of it was empty
  • The sizes that make it matter, and the toy that cannot
  • What the run shows
  • Preemption: what happens when the pool runs dry
  • What the toy cannot show
  • One party takes its benches
  • Find a character’s bench yourself
  • How much of a slab sits empty
  • Why the slab wastes 37 percent, not 25
  • When the room runs out
  • All of it in code
  • Break it: a bench as big as a slab

Terms it explains: Reserved, Internal fragmentation, External fragmentation, slab, pages, page table, block, pool, block table, preemption.

Related paper

Review AI