TL;DR
QUOKA is a training-free, hardware-agnostic sparse attention algorithm designed to accelerate the computationally heavy prefill stage of LLM inference. By exploiting a novel geometric insight—that queries dissimilar to the mean query dominate the attention distribution—QUOKA drops up to 88% of key-value pairs, delivering up to a 5× attention speedup on GPUs and 7× on CPUs with virtually no loss in accuracy.
What Problem Does This Paper Address?
Large Language Model (LLM) inference suffers from high "time-to-first-token" (TTFT) latency, with the initial prefill stage often consuming over 70% of the total runtime. To make processing more manageable, modern deployments use chunked prefill, breaking long inputs into smaller blocks. However, because standard attention scales quadratically ($O(T^2)$) with sequence length, chunked prefill remains incredibly expensive on resource-constrained hardware like CPUs and consumer GPUs.
Existing sparse attention methods fall short: pattern-based approaches rely on rigid, custom hardware kernels that aren't easily portable, while query-dependent approaches are built for single-query token generation and degrade significantly when forced to select key-values (KVs) for an entire block of queries at once. QUOKA bridges this gap by providing an algorithm tailored for multi-query chunked prefill that runs on standard linear algebra operations.
Methods
QUOKA introduces a three-step pipeline that filters the KV cache before passing it to standard, highly optimized dense attention kernels like FlashAttention:
- Query Subselection: Instead of evaluating every query in a chunk, QUOKA filters out redundant ones. It ranks queries based on their angular distance from the average query vector and retains only a small, highly informative subset ($N_Q$).
- Cosine-Similarity Scoring: Rather than using standard dot products, which are scale-dependent and unstable under aggregation, QUOKA computes the cosine similarity between the subselected queries and keys as a stable, bounded proxy for attention relevance.
- Group-Aware Aggregation: To choose the final KV pairs, QUOKA takes the maximum score across the query axis to preserve rare but critical outlier interactions. For architectures using Grouped-Query Attention (GQA), it averages queries across KV groups before scoring, dramatically lowering compute and memory traffic.
Datasets
The authors evaluated QUOKA across a diverse set of long-context and reasoning benchmarks using model families like Llama 3.2, Qwen 2.5/3, SmolLM3, and GPT-OSS:
- Needle-In-A-Haystack (NIAH): Tests the model's ability to retrieve a single hidden fact within a massive body of irrelevant text.
- RULER: A rigorous synthetic benchmark that extends beyond basic retrieval to test multi-hop tracing and aggregation across long contexts.
- LongBench: A multi-task suite featuring real-world long-context tasks such as book summaries, technical reports, and multi-document QA.
- Math500: A dataset of high-level math competition problems used to evaluate multi-step mathematical reasoning during generation.
Key Insights and Ideas
- The Geometry of Queries: The core "aha!" moment of the paper is that queries are geometrically distinct. Queries that lie close to the average query vector concentrate their attention on a small, shared group of keys. In contrast, queries with low cosine similarity to the mean query vector interact strongly with a wide variety of keys and contribute the most to the final attention distribution.
- Max-Pooling Over Averaging: Because attention distributions are heavy-tailed, naively averaging scores across multiple queries washes out rare but vital query-key interactions. Using a
maxoperation ensures these critical outliers are preserved.
Key Results
- Massive KV Cache Reduction: QUOKA successfully approximates full attention while utilizing 88% fewer key-value pairs per evaluation.
- Substantial Speedups: On enterprise-class Nvidia A100 GPUs, QUOKA achieves a 5× attention module speedup and a 3× reduction in end-to-end TTFT.
- Cross-Platform Portability: Because it relies on standard linear algebra, it achieves up to a 7× speedup on Intel Xeon CPUs and 5-6× speedup on consumer Nvidia RTX 2080 GPUs.
- High Accuracy Retention: On the demanding LongBench suite, QUOKA outperforms existing sparse attention methods by 10–20%, maintaining near-baseline accuracy even under strict token budgets.
Limitations and Future Work
While QUOKA completely avoids the need for custom CUDA kernels, computing the initial query-key similarity matrix still introduces minor computational overhead. The authors note that future work could make this step even faster by exploiting channel sparsity or using learned low-dimensional projections. Additionally, QUOKA currently focuses on chunked prefill; integrating it with complementary KV cache eviction policies during the token generation phase remains an open and promising research direction.
Summary updated