Skip to main content
ExplainerCompute InfrastructureExplainer· 3 min read· in Artificial Intelligence

How PagedAttention Partitions GPU Memory to Solve the LLM Context Bottleneck

Large language models generate text by storing previous tokens in a temporary memory bank called the KV cache. By dividing this memory into non-contiguous blocks, inference engines can eliminate fragmentation and quadruple the number of users a single server can handle.

By Sofia Matos

Inference Engine Developers 60%Hardware Architects 40%
Inference Engine Developers
Focus on maximizing hardware utilization and throughput.
Hardware Architects
Focus on memory bandwidth and physical silicon constraints.

Perspectives this story doesn't cover

  • Cloud Infrastructure Providers
  • Open-Source Model Developers

The inference scheduler sitting between a large language model and its hardware decides exactly how much memory to allocate to a user's prompt. It can partition the GPU's video RAM into rigid, contiguous chunks, or it can divide it into dynamic, non-contiguous pages. It makes this choice the millisecond a new request arrives, determining whether the server can handle ten concurrent users or a hundred.

When a model like Llama 3 or GPT-4 generates a response, it does not recalculate the entire conversation history for every new word. Instead, it stores the mathematical representations of past words in a temporary storage area known as the Key-Value (KV) cache.

As the model generates more text, this cache grows linearly. In 2023, researchers at UC Berkeley identified that the KV cache was consuming up to 30% of total GPU memory during inference, creating a severe bottleneck that limited concurrent user capacity.[1]

The traditional method for managing this memory was highly inefficient. Schedulers would allocate a large, contiguous block of memory for the maximum possible length of a conversation. If a user only asked a short question, the rest of that allocated memory sat empty and unusable by other requests.

This phenomenon, known as internal memory fragmentation, wasted massive amounts of expensive hardware capacity. According to the UC Berkeley team, "existing systems waste 60% to 80% of memory due to fragmentation and over-reservation."[1]

PagedAttention divides the KV cache into small blocks, eliminating the fragmentation caused by reserving maximum context lengths.

To solve this, developers introduced PagedAttention, an algorithm inspired by how traditional computer operating systems manage RAM. Instead of reserving one massive block, PagedAttention divides the KV cache into small, fixed-size pages.

Each page typically holds the attention keys and values for a specific number of tokens—often 16 or 32. Crucially, these pages do not need to sit next to each other on the physical silicon.[1]

Each page typically holds the attention keys and values for a specific number of tokens—often 16 or 32.

A central block table tracks where each page is located. When the model needs to reference a past token, the scheduler looks up the virtual address in the block table and translates it to the physical location on the GPU.

This mechanism practically eliminates internal fragmentation. Memory is allocated dynamically, one page at a time, only when the model actually generates a new token that requires storage.

The efficiency gains are measurable and immediate. By implementing PagedAttention in the open-source vLLM engine, developers reduced memory waste to under 4%.[1]

Freeing up that wasted memory allows the server to load more concurrent user requests into the same GPU. In benchmark tests on NVIDIA A100 GPUs, vLLM achieved 2x to 4x higher throughput compared to standard Hugging Face Transformers.[1]

By reducing memory waste, inference engines can process up to four times as many concurrent requests.

NVIDIA has since integrated similar paging techniques into its TensorRT-LLM software stack. In an August 2023 technical breakdown, NVIDIA engineers noted that optimizing the KV cache is critical because "memory bandwidth is the primary bottleneck for LLM inference."[2]

However, the paging mechanism introduces its own computational overhead. The scheduler must constantly update the block table and perform address translations during the highly latency-sensitive generation phase.

What remains unproven is how well PagedAttention scales as context windows expand from 128,000 tokens to over a million. At those extremes, the block table itself becomes a massive data structure that requires optimization.

The next generation of inference engines will have to decide how to compress the cache itself. Until hardware bandwidth catches up to model size, the software scheduler's ability to pack memory blocks tightly dictates the commercial viability of deploying frontier AI.

What to know

  1. The KV cache stores past tokens during generation but traditionally wastes up to 80% of memory due to fragmentation.
  2. PagedAttention divides this memory into small, dynamic blocks, allocating space only when needed.
  3. This optimization allows inference servers to handle up to four times as many concurrent users on the same hardware.

Key terms

KV Cache
A temporary memory bank where a language model stores the mathematical representations of past words to avoid recalculating them.
Inference
The phase where a trained AI model generates responses to user prompts.
Internal Fragmentation
Wasted memory that occurs when a system reserves a large block of space but only uses a small portion of it.
Throughput
The total number of requests or tokens a server can process in a given amount of time.

Reader questions

Why do language models need a cache?

Without a cache, the model would have to re-read and re-process the entire conversation history every time it generates a single new word, which is computationally expensive.

How does PagedAttention save memory?

It divides memory into small blocks and only allocates them when needed, rather than reserving a massive chunk of memory for every user just in case they write a long prompt.

Does this make the AI smarter?

No. PagedAttention is an engineering optimization that makes the AI cheaper and faster to run, but it does not change the quality of the model's answers.

Sources

Source coverage

3 outlets

2 viewpoints surfaced

Inference Engine Developers 60%Hardware Architects 40%
  1. [1]UC Berkeley vLLM TeamInference Engine Developers

    Efficient Memory Management for Large Language Model Serving with PagedAttention

    Read on UC Berkeley vLLM Team
  2. [2]NVIDIAHardware Architects

    Mastering LLM Techniques: Inference Optimization

    Read on NVIDIA
  3. [3]Factlen Editorial TeamInference Engine Developers

    Synthesis by Factlen editorial team

    Read on Factlen Editorial Team

Comments

Stay informed

Every angle. Every day.

Get Artificial Intelligence stories with full source coverage and perspective breakdowns delivered to your inbox.