Papers
Topics
Authors
Recent
Search
2000 character limit reached

Paged Attention Kernels

Updated 17 May 2026
  • Paged Attention Kernels are memory management paradigms that partition LLM KV caches into fixed-size pages to support variable-length sequences and reduce fragmentation.
  • They integrate compile-time and runtime techniques like JIT fusion and virtual memory mapping to optimize throughput on GPUs, TPUs, and other accelerator architectures.
  • Empirical results demonstrate significant reductions in latency and memory overhead during long-context inference, making these kernels vital for high-throughput LLM serving.

Paged Attention Kernels are a class of memory management and compute paradigms for attention mechanisms in LLM inference that structure the key-value (KV) cache as dynamically allocated fixed-size pages rather than contiguous monolithic buffers. This approach enables efficient support for variable-length sequences, mitigates memory fragmentation, significantly improves throughput for long-context inference, and facilitates efficient implementations on GPUs, TPUs, and other accelerator architectures. Modern paged attention kernel designs integrate compile-time and runtime components for page-table indirection, often leveraging JIT fusion, hardware virtual memory, or highly-optimized block-sparse GEMM routines. These kernels constitute the foundation of high-throughput, high-capacity production LLM serving frameworks.

1. Formal Definition and Mathematical Structure

PagedAttention partitions the dynamically growing KV cache for each decoding sequence into fixed-size blocks (pages) of size PP tokens. Each token t∈{0,…,N−1}t\in\{0,\dots,N-1\} is addressed by:

b=⌊tP⌋,o=t mod P,p=PT[b]×P+ob = \left\lfloor \frac{t}{P} \right\rfloor, \quad o = t \bmod P, \quad p = \mathrm{PT}[b] \times P + o

where bb is the page index, oo is the offset within the page, and PT[⋅]\mathrm{PT}[\cdot] is a per-sequence page-table mapping logical blocks to physical pages. When decoding, appending a new token t=Nt=N extends the page table only when bnew≥PT.sizeb_{\mathrm{new}}\geq \text{PT.size}, resulting in the allocation of a new page—a true page-fault event. All other token accesses are O(1)O(1) index computations within the fused kernel (Joshi et al., 8 Jun 2025).

The paged KV cache stores all KtK_t and t∈{0,…,N−1}t\in\{0,\dots,N-1\}0 vectors within a single or multi-layer physical buffer, with page allocation and release managed by a global, lock-free free-list per accelerator device. The overall memory usage per layer for t∈{0,…,N−1}t\in\{0,\dots,N-1\}1 tokens is:

t∈{0,…,N−1}t\in\{0,\dots,N-1\}2

with t∈{0,…,N−1}t\in\{0,\dots,N-1\}3, t∈{0,…,N−1}t\in\{0,\dots,N-1\}4 the per-head dimension, and t∈{0,…,N−1}t\in\{0,\dots,N-1\}5 bytes for FP16.

2. Kernel Architecture and Implementation Patterns

PagedAttention kernels can be implemented via several distinct mechanisms, including:

  • JIT-fused CUDA/Triton: The arithmetic for page-table indirection is inlined into a single fused attention kernel (e.g., in FlexAttention), where mask and index calculation (mask_mod, index_mod) are callable hooks, and all memory access indirection is performed on the device (Joshi et al., 8 Jun 2025, Dong et al., 2024, Ringlein et al., 7 Oct 2025).
  • Virtual Memory Management (VMM)-backed kernels: Using low-level CUDA VMM APIs, vAttention and vTensor reserve a contiguous virtual address space and dynamically map physical memory to active portions of the KV cache via page tables managed on the CPU. This allows use of any contiguous, high-performance compute kernel (e.g., FlashAttention) without modification, while transparently managing physical memory as pages (Prabhu et al., 2024, Xu et al., 2024).
  • Paged block-tiled attention for TPUs: Ragged Paged Attention (RPA) employs a software pipeline that fuses cache updates and attention, using fine-grained tile packing and distribution-aware JAX/Pallas kernel specialization to maximize memory and FLOP utilization under ragged serving conditions (Jiang et al., 16 Apr 2026).
  • Autotuned Triton/DSL kernels: Unified Triton-based kernels leverage hierarchical tiling, shared-memory staging, prefetching, and parameter auto-tuning to attain cross-vendor efficiency for block-tiled (paged) attention, often exceeding established baselines such as FlashAttention 3 (Ringlein et al., 7 Oct 2025).

A typical attention kernel thus processes each query token as a sequence of page-sized blocks from the KV cache, fusing score calculation, softmax normalization, and value aggregation within tile-local operations to maximize arithmetic intensity and minimize global memory traffic.

3. Memory Management Schemes

PagedAttention's memory strategy centers on power-of-two-sized pages (for efficient bitwise indexing), global or local page-allocating buffers, and per-sequence page tables. Key aspects:

  • Fragmentation: With t∈{0,…,N−1}t\in\{0,\dots,N-1\}6, worst-case internal fragmentation per sequence is t∈{0,…,N−1}t\in\{0,\dots,N-1\}7. For operational values (t∈{0,…,N−1}t\in\{0,\dots,N-1\}8), this is usually t∈{0,…,N−1}t\in\{0,\dots,N-1\}9 overhead (Joshi et al., 8 Jun 2025).
  • Compaction and compression: Extensions such as KV-Compress enable block-wise or per-head variable-rate eviction and compaction within paged-attention allocations. By moving maximal KV blocks into contiguous memory and freeing newly-emptied pages, theoretical compression rates can be matched in hardware with minimal slack (Rehg, 2024).
  • Virtualized/decoupled paging: Virtual memory mechanisms decouple physical and virtual allocation, minimizing fragmentation, supporting dynamic extension and lazy deallocation, and enabling prefix sharing by reusing page table metadata alone (Xu et al., 2024, Prabhu et al., 2024).

PagedAttention enables efficient multi-GPU scaling by partitioning the global KV cache per device and employing distributed freelists.

4. Performance Evaluation and Comparison

PagedAttention kernels exhibit substantial improvements over monolithic or statically padded KV-caching by both reducing memory use and mitigating unbounded latency growth in long-context inference. Representative empirical metrics:

Sequence Len No Cache (ms) PagedAttention (ms) Latency Scaling
128 5 5.1 b=⌊tP⌋,o=t mod P,p=PT[b]×P+ob = \left\lfloor \frac{t}{P} \right\rfloor, \quad o = t \bmod P, \quad p = \mathrm{PT}[b] \times P + o0 equal
256 50 6.8 b=⌊tP⌋,o=t mod P,p=PT[b]×P+ob = \left\lfloor \frac{t}{P} \right\rfloor, \quad o = t \bmod P, \quad p = \mathrm{PT}[b] \times P + o1 vs linear (b=⌊tP⌋,o=t mod P,p=PT[b]×P+ob = \left\lfloor \frac{t}{P} \right\rfloor, \quad o = t \bmod P, \quad p = \mathrm{PT}[b] \times P + o2)
512 500 8.2 b=⌊tP⌋,o=t mod P,p=PT[b]×P+ob = \left\lfloor \frac{t}{P} \right\rfloor, \quad o = t \bmod P, \quad p = \mathrm{PT}[b] \times P + o3 vs linear
1024 5,000 12.0 b=⌊tP⌋,o=t mod P,p=PT[b]×P+ob = \left\lfloor \frac{t}{P} \right\rfloor, \quad o = t \bmod P, \quad p = \mathrm{PT}[b] \times P + o4 vs linear
2048 50,000 10.2 b=⌊tP⌋,o=t mod P,p=PT[b]×P+ob = \left\lfloor \frac{t}{P} \right\rfloor, \quad o = t \bmod P, \quad p = \mathrm{PT}[b] \times P + o5 vs linear

On NVIDIA L4, end-to-end latency grows only b=⌊tP⌋,o=t mod P,p=PT[b]×P+ob = \left\lfloor \frac{t}{P} \right\rfloor, \quad o = t \bmod P, \quad p = \mathrm{PT}[b] \times P + o6 as context increases b=⌊tP⌋,o=t mod P,p=PT[b]×P+ob = \left\lfloor \frac{t}{P} \right\rfloor, \quad o = t \bmod P, \quad p = \mathrm{PT}[b] \times P + o7, whereas recomputing attention from scratch grows exponentially (Joshi et al., 8 Jun 2025).

Memory overhead remains minimal (e.g., b=⌊tP⌋,o=t mod P,p=PT[b]×P+ob = \left\lfloor \frac{t}{P} \right\rfloor, \quad o = t \bmod P, \quad p = \mathrm{PT}[b] \times P + o8160 MB per layer at b=⌊tP⌋,o=t mod P,p=PT[b]×P+ob = \left\lfloor \frac{t}{P} \right\rfloor, \quad o = t \bmod P, \quad p = \mathrm{PT}[b] \times P + o9 for LLaMA-7B) compared to >10 GB for model weights, with slack appearing predominantly beyond 2048 tokens.

Extensions such as KV-Compress achieve up to bb0 cache compression with bb1 accuracy loss and up to bb2 throughput gains for typical LLMs and accelerators (Rehg, 2024).

Highly-tuned Triton paged attention kernels attain bb3 of baseline FlashAttention-3 throughput on NVIDIA and match baseline performance on AMD, confirming low overhead from paging when appropriately optimized (Ringlein et al., 7 Oct 2025).

5. Integration in Modern LLM Serving Systems

PagedAttention has become a standard primitive in production LLM serving stacks. Key integration points include:

  • Drop-in replacement: PagedAttention kernels can be exposed as configuration toggles in PyTorch or model serving frameworks (IBM FMS, vLLM), requiring no architectural changes or model retraining (Joshi et al., 8 Jun 2025).
  • Compiler-driven extensibility: FlexAttention supports plug-in mask_mod/score_mod functions and page-table logic, enabling composition with arbitrary attention variants (Alibi, document masking) at negligible kernel overhead (Dong et al., 2024).
  • Serving-optimized memory schedulers: vTensor and vAttention frameworks leverage CPU-driven virtual memory mappers to simultaneously support multiple LLMs, elastic batch sizing, and memory sharing for activations and embeddings with peak memory reclamation of bb4 versus baseline paged kernels (Xu et al., 2024, Prabhu et al., 2024).
  • TPU and cross-accelerator support: Custom paged attention kernels have been developed for modern TPUs, making full use of hardware tiling and multi-phase pipeline specialization for decode, prefill, and mixed workloads. Empirical results confirm up to bb5 memory bandwidth utilization (MBU) and bb6 model FLOPs utilization (MFU) (Jiang et al., 16 Apr 2026).

6. Limitations, Trade-Offs, and Future Directions

Despite significant improvements, PagedAttention kernels exhibit certain limitations:

  • Inference-only in most systems: Current implementations generally support only inference; paging for training activations and optimizer state is future work (Joshi et al., 8 Jun 2025).
  • Static page-size constraints: Fragmentation overhead at sequence lengths far exceeding bb7 tokens becomes visible due to power-of-two page allocation, motivating investigation into hierarchical or adaptive page sizing.
  • Kernel overheads in tightly-coupled implementations: Handwritten paged attention kernels (e.g., early vLLM implementations) incur up to bb8 penalty vs non-paged baselines due to runtime block-table lookups and additional CPU coordination (Prabhu et al., 2024). Compiler-fused methods (FlexAttention, vTensor) nearly eliminate this penalty.
  • Hardware and software dependencies: Optimal performance requires modern GPU/TPU architectures, support for JIT-fused or highly parameterized kernels (Triton, JAX/Pallas), and system-level support for CUDA VMM or equivalent APIs.
  • Scope: Many results pertain to decoder-only models. Experimental results in encoder–decoder or multimodal settings are less conclusive (Joshi et al., 8 Jun 2025).

Future research directions outlined in recent works include training-time paging, hierarchical page structures, cross-device memory tiering (disk, host, device), and context-partitioned paging for modular and multimodal architectures.

7. Extensions: Compression and Integration with Sparse/Kernel Attention

PagedAttention kernels provide the infrastructure upon which advanced KV compression, selection, and patching methods can be realized:

  • KV-Compress leverages per-head, per-layer page compaction with variable-rate block eviction, realizing theoretical memory savings and throughput gains with minimal accuracy loss. Pages are always evicted/compacted as full contiguous runs to sustain physical memory efficiency (Rehg, 2024).
  • MAC-Attention composes with any paged-KV manager to achieve bb9 or oo0 per-step KV access by reusing previously computed attention outputs for matched queries, delivering up to oo1 KV skip rate, oo2 kernel phase speedups, and oo3 end-to-end latency reduction for very long context LLMs (Yao et al., 31 Mar 2026).
  • Sparse/compact kernel regression views. Paged attention in the context of kernel design yields exact, context-adaptive sparsity (e.g., in α-entmax/sparsemax/kNN variants), reducing compute to oo4 (for typical in-support size oo5) and improving length generalization in both synthetic and downstream tasks (Santos et al., 30 Jan 2026).

Paged attention thus underlies not only memory and performance scaling, but also theoretical advances in sparse and locality-sensitive attention mechanisms.


References

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Paged Attention Kernels.