Continue where you left off ×
Paged Attention: The Cache in Blocks
Walk through it, one picture at a time 10 short steps
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 .
The idea in 30 seconds
A slab reserves a full window per request up front. Most of it sits empty, so 37 percent of reserved positions held nothing in this toy.
The vLLM paper measured only 20.4 to 38.2 percent of cache memory holding real token states in earlier systems, so 60 to 80 percent was waste.
Paging cuts the cache into fixed blocks from one pool, and a block table lists which blocks hold a request’s positions, in order.
A request takes a block only when it writes into one, so waste falls to the unfilled end of the last block, 8 percent here.
Paging admits more requests than the pool can finish, so it must preempt: free the newest request’s blocks and recompute it later.
Read the story
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 plans Already 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.
Review AI
Mark as read Saved in this browser, and to your account when you sign in.