Loading diagram…

Reference

← All guides

PagedAttention

PagedAttention stores the KV cache in fixed-size blocks. A block table maps each sequence’s logical positions to physical blocks in GPU memory.

Overview

How it works

A request’s blocks do not need to be adjacent. The server allocates more as its sequence grows, and the attention kernel follows the block table to read them in order. The attention equation stays the same.

Details

Unused reservations

Response lengths are not known in advance. Reserving one large contiguous region per request can leave unused space or produce gaps too small for another request. Paging reduces these allocation problems.

Details

Block allocation

Divide the cache into blocks with a fixed number of token slots. Allocate the next block when needed. In this simplified layout, unused space is limited to the final block of each sequence.

Details

Shared blocks and copy-on-write

Compatible requests can point to the same cached prefix blocks. Before modifying a shared block, a request receives a private copy. Appending beyond a full shared block only requires a new block for the continuation.

Details

Serving more requests

Paging reduces allocation waste and can avoid duplicate prefix storage. It does not compress the keys and values themselves. The server needs attention kernels that can follow block tables. Actual throughput depends on the workload and implementation.

Sources