Skip to content

PagedAttention

Definition

PagedAttention is a memory management algorithm for KV-cache that borrows the concept of virtual memory: the cache is divided into fixed-size blocks that are placed in physical memory independently of the logical sequence. Implemented in the vLLM engine.

Problem

Traditional allocation of a contiguous buffer for KV-cache leads to internal and external fragmentation. With variable generation lengths, a significant portion of VRAM remains unused.

Scheme

flowchart LR
    A[Logical blocks] --> B[Page table]
    B --> C[Physical blocks VRAM]
    C --> D[Attention calculation]

Blocks can be shared between sequences with a common prefix (copy-on-write), providing savings during parallel generation with the same system prompt.

Effect

  • Reduces memory fragmentation to single-digit percentages.
  • Increases the number of simultaneous requests with the same amount of VRAM.
  • Compatible with Continuous Batching and Prefix Caching.

See also