← Latest papers
💬 NLP

CompactAttention: Accelerating Chunked Prefill with Block-Union KV Selection

CompactAttention accelerates chunked prefill in long-context large language models by introducing a Block-Union KV Selection mechanism that converts 2D block-sparse masks into efficient, GQA-aware per-group KV block tables, thereby enabling in-place memory access without explicit compaction while maintaining near-dense accuracy and achieving up to 2.72× speedup.

Original authors: Jiwon Song, Dongwon Jo, Beomseok Kang, Jae-Joon Kim

Published 2026-05-19
📖 4 min read☕ Coffee break read

Original authors: Jiwon Song, Dongwon Jo, Beomseok Kang, Jae-Joon Kim

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are a librarian (the AI) trying to answer a question based on a massive library of books (the context). In the past, if you had a huge library, you'd have to read every single book to find the right answer, which takes forever. To speed this up, researchers invented a "chunked prefill" system: instead of reading the whole library at once, you read it in small batches (chunks), adding notes to a notepad (the KV cache) as you go.

However, a new problem arose: How do you quickly find the right pages in your notepad without reading everything again every time you get a new batch of questions?

This paper introduces CompactAttention, a new way to solve this problem. Here is how it works, using simple analogies:

The Problem with Old Methods

The paper identifies two main ways people tried to solve this, and why they failed:

  1. The "Sparse Kernel" Approach (The Inefficient Scanner):

    • The Idea: Imagine you have a map of the library with red dots marking only the important books. You try to skip the white spaces and only look at the red dots.
    • The Failure: When you are reading a huge library (long context) but only asking a tiny question (small chunk), this method gets slow. It's like having a scanner that is great for scanning a whole wall of text, but when you only have one sentence, the scanner takes too long to set up and calibrate. The overhead of "skipping" the white space actually makes it slower than just reading everything.
  2. The "Query-Subsampled" Approach (The Lazy Librarian):

    • The Idea: Instead of checking every question, you pick just a few random questions from your batch, find the important books for those, and assume those books are important for everyone.
    • The Failure: This is risky. If you pick the wrong few questions, you might miss a crucial book that only one specific question needed. Also, once you pick those books, you have to physically carry them from the shelves to a special table before you can read them. This "carrying" (copying data) takes a lot of time and energy.

The Solution: CompactAttention

CompactAttention changes the game by separating finding the books from reading them.

Step 1: The "Union" Strategy (Grouping the Search)

Instead of trying to execute a complex "skip list" (sparse kernel) or guessing based on a few questions, CompactAttention uses a smart grouping trick:

  • Imagine you have a team of detectives (query heads) working on a case. Each detective has their own list of "suspects" (KV blocks) they think are important.
  • Instead of letting each detective work alone, CompactAttention says: "Let's combine all the suspects from the whole team into one master list."
  • It does this in two steps:
    1. Q-Block Union: It combines the lists for all the questions in the current batch.
    2. Intra-Group Union: It combines the lists for detectives who work together.
  • The Result: You get a single, minimal "Master List" of suspects that covers everyone's needs. No important book is left behind because if any detective needed it, it's on the list.

Step 2: The "Zero-Copy" Execution (Reading in Place)

This is the magic part.

  • Old Way: Once you have your Master List, you have to physically move all those books from the shelves to a special table so you can read them quickly. This "moving" takes time.
  • CompactAttention Way: You don't move the books at all. You just hand the librarian a map (metadata) that says, "Go to Shelf A, Row 3, Book 5; then Shelf B, Row 1, Book 2."
  • The librarian (the computer kernel) goes directly to those spots on the shelves and reads them. This is called "Zero-Copy Paged Attention." It saves all the time and energy spent on moving data around.

Why It's a Big Deal

The paper tested this on a massive AI model (LLaMA-3.1-8B) with a context of 128,000 words (a very long document).

  • Accuracy: It was just as smart as reading the whole library (Dense Attention). It didn't miss any crucial details.
  • Speed: It was up to 2.72 times faster than the standard way of doing things.

The Takeaway

Think of CompactAttention as a smart librarian who stops trying to rearrange the library and instead just uses a perfect, combined index card.

By realizing that the "search" (finding the important blocks) and the "execution" (reading them) should be separate, and by using a "grouping" trick to ensure nothing is missed, they managed to make long-document AI processing significantly faster without losing any intelligence. They proved that the bottleneck wasn't just which books to pick, but how you go about picking them up.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →