Paged Attention Meets FlexAttention: Unlocking Long-Context Efficiency in Deployed Inference

Thomas Joshi, Herman Saini, Neil Dhillon, Antoni Viros i Martin, Kaoutar El Maghraoui
6/8/2025
cs.LGcs.AI

No confident code implementation found for this paper.

Abstract

Large Language Models (LLMs) encounter severe memory inefficiencies during long-context inference due to conventional handling of key-value (KV) caches. In this work, we introduce a novel integration of PagedAttention with PyTorch's FlexAttention, addressing internal fragmentation and inefficiencies associated with monolithic KV cache allocations. Implemented within IBM's Foundation Model Stack (FMS), our fused attention kernel efficiently gathers scattered KV data. Our benchmarks on an NVIDIA L4 GPU (24GB) demonstrate significantly reduced inference latency, growing only linearly (~2x) with sequence length from 128 to 2048 tokens when utilizing a global KV cache, compared to exponential latency increases without caching. While peak memory usage remains largely unchanged for single-step evaluations (dominated by model weights and activations), paged attention causes minimal incremental memory usage, observable only at sequence lengths exceeding 2048 tokens due to its power-of-two cache allocations. We open-source the full implementation and discuss its implications for future long-context model deployment.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{joshi2025paged,
  title  = {Paged Attention Meets FlexAttention: Unlocking Long-Context Efficiency in Deployed Inference},
  author = {Thomas Joshi and Herman Saini and Neil Dhillon and Antoni Viros i Martin and Kaoutar El Maghraoui},
  year   = {2025},
  eprint = {2506.07311},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2506.07311v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2506.07311.svg)](https://codeofpaper.com/paper/2506.07311)

Discussion