Skip to content
StackDecode
System Design
19. AI System Design and LLM InfrastructureAnimated

Paged Attention

Manage the KV cache in fixed-size blocks.

The idea

Like virtual memory pages, blocks are allocated on demand, removing fragmentation.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

GPU memory for the KV cache (each square is a fixed-size block)freefreefreefreefreefreefreefreefreefreefreefreefreefreefreefree

Memory is split into small blocks, like pages in an operating system.

used:
0
free:
16
1/12

PagedAttention (vLLM) removes the fragmentation that wastes most KV-cache memory.

Step by step

  1. 1Split the KV cache into blocks
  2. 2Allocate as the sequence grows
  3. 3Free blocks when done
  4. 4Share blocks for shared prefixes

Where it is used

vLLM-style serving.

Watch out for

Block table lookup adds a little overhead.

Related