Efficient Memory Management for Large Language Model Serving with PagedAttention

Woosuk Kwon, Zhuohan Li, Siyuan Zhuang, Ying Sheng, Lianmin Zheng, Cody Hao Yu, Joseph E. Gonzalez, Hao Zhang, Ion Stoica

2023 · SOSP

Efficient Memory Management for Large Language Model Serving with PagedAttention

Problem

Framing

LLM serving wastes KV-cache memory through reservation, fragmentation, and duplicate prefixes, which caps batch size before FLOPs saturate. The paper closes this systems gap with PagedAttention: it virtualizes KV storage into fixed-size blocks with block tables and sharing, cutting waste to under 4%4\% and raising serving throughput by up to 24×24\times over Hugging Face Transformers.

Currently Used Methods

Foundational

Proposed Method

Architecture

vLLM splits serving into a scheduler, a KV cache manager, CPU/GPU block allocators, and worker processes that host model shards plus cache engines. PagedAttention stores each sequence's KV cache as logical blocks mapped by a block table to non-contiguous physical blocks, enabling prefix sharing and near-zero external compaction pressure.

vLLM system overview and PagedAttention block layout: scheduler and KV cache manager feed sharded workers, while query tokens attend to non-contiguous KV blocks via block tables.

Loss / Objective

The paper is a serving-systems design, not a training objective paper.Its core attention computation rewrites standard attention over paged KV blocks:

oi=jsoftmax(qiKjd)Vj\mathbf{o}_i = \sum_j \mathrm{softmax}\left(\frac{\mathbf{q}_i \mathbf{K}_j^\top}{\sqrt{d}}\right) \mathbf{V}_j

where Kj=(k(j1)B+1,,kjB)\mathbf{K}_j = (\mathbf{k}_{(j-1)B+1}, \ldots, \mathbf{k}_{jB}) and Vj=(v(j1)B+1,,vjB)\mathbf{V}_j = (\mathbf{v}_{(j-1)B+1}, \ldots, \mathbf{v}_{jB}) are block-wise KV tensors.

Sampling Rule / Algorithm

PagedAttention computes attention blockwise, then reduces partial results across KV blocks:

oi=jAijVj,Aij=(ai,(j1)B+1,,ai,jB)\mathbf{o}_i = \sum_j \mathbf{A}_{ij} \mathbf{V}_j, \qquad \mathbf{A}_{ij} = \left(a_{i,(j-1)B+1}, \ldots, a_{i,jB}\right)

This preserves exact attention while decoupling logical token order from physical memory contiguity.

Training Procedure

Evaluation

Datasets

Metrics

Headline results

Ablations

Method Strengths and Weaknesses

Strengths

Weaknesses

Suggestions from the authors

Links

Prior Papers

Further Papers