Efficient Memory Management for Large Language Model Serving with PagedAttention

Woosuk Kwon, Zhuohan Li, Siyuan Zhuang, Ying Sheng, Lianmin Zheng +4 more
9/12/2023
cs.LGcs.DC

Abstract

High throughput serving of large language models (LLMs) requires batching sufficiently many requests at a time. However, existing systems struggle because the key-value cache (KV cache) memory for each request is huge and grows and shrinks dynamically. When managed inefficiently, this memory can be significantly wasted by fragmentation and redundant duplication, limiting the batch size. To address this problem, we propose PagedAttention, an attention algorithm inspired by the classical virtual memory and paging techniques in operating systems. On top of it, we build vLLM, an LLM serving system that achieves (1) near-zero waste in KV cache memory and (2) flexible sharing of KV cache within and across requests to further reduce memory usage. Our evaluations show that vLLM improves the throughput of popular LLMs by 2-4$\times$ with the same level of latency compared to the state-of-the-art systems, such as FasterTransformer and Orca. The improvement is more pronounced with longer sequences, larger models, and more complex decoding algorithms. vLLM's source code is publicly available at https://github.com/vllm-project/vllm

View on arXivView PDF

Code Implementations(2)

PyTorchApache-2.0

A high-throughput and memory-efficient inference and serving engine for LLMs

79,03316,401C, C++Feb 9, 20234 weeks agoApache-2.0
amdblackwellcudadeepseekdeepseek-v3+15 more
BSD-3-Clause

Fast and memory-efficient exact attention

23,5882,665C, C++May 19, 20221 months agoBSD-3-Clause

Cite this paper

@article{kwon2023efficient,
  title  = {Efficient Memory Management for Large Language Model Serving with PagedAttention},
  author = {Woosuk Kwon and Zhuohan Li and Siyuan Zhuang and Ying Sheng and Lianmin Zheng and Cody Hao Yu and Joseph E. Gonzalez and Hao Zhang and Ion Stoica},
  year   = {2023},
  eprint = {2309.06180},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2309.06180v1}
}

Discussion