Sparse Attention as a Range Searching Problem: Towards an Inference-Efficient Index for KV Cache

Mohsen Dehghankar, Abolfazl Asudeh

TL;DR

This paper reformulates the problem of sparse attention in Large Language Models (LLMs) as a classic computational geometry problem: halfspace range searching. The authors introduce Louver, a novel, hardware-optimized KV cache index structure that guarantees zero false negatives above a relevance threshold, preventing the catastrophic accuracy drops common in prior top-$k$ or approximate sparse attention methods while outperforming highly optimized dense baselines like FlashAttention-2.

What Problem Does This Paper Address?

As LLMs handle increasingly long contexts, the Key-Value (KV) cache becomes a massive computational and memory bottleneck during the autoregressive decoding phase. Every newly generated token must attend to all previous tokens, causing the cost to scale linearly with sequence length.

While attention is inherently sparse—meaning only a small subset of "active tokens" truly matter at any given step—prior attempts to exploit this sparsity fall short. Existing methods typically enforce a fixed token budget (like top-$k$ retrieval) or rely on approximate nearest neighbor (ANN) search. The authors reveal two fatal flaws in these approaches:

  1. Extreme Sensitivity to False Negatives: Missing even a single critical token can cause sharp spikes in model error, particularly in long-output reasoning tasks.
  2. Highly Dynamic Attention Tails: The number of relevant tokens oscillates wildly across decoding steps. A fixed budget $k$ is either wasteful during localized computations or insufficient during complex reasoning transitions.
Figure 1: (a) Effect of dropping tokens. We remove either (i) one relevant token (a randomly selected number in the list) or (ii) one randomly selected non-relevant token. Dropping a relevant token significantly increases the error. (b) Error spike in fixed-K sparse attention as the list size N increases. The green line corresponds to retaining all relevant tokens (no false negatives). (c) Top-k coverage across decoding steps, showing significant oscillation and indicating that the number of relevant tokens varies per step (see Observation 2). See Appendices C and D for details.

Methods

To solve this, the authors abandon the top-$k$ paradigm and instead frame sparse attention as identifying all keys whose inner product with the query exceeds a dynamic threshold ($\langle qt, k \rangle \ge \tau$). Geometrically, this is exactly halfspace range searching.

Figure 2: Illustrating the reduction of sparse attention to halfspace range searching (Example 2).

Because traditional geometric range-searching data structures carry too much overhead for LLM inference, the authors designed Louver, a lightweight, hardware-aware index framework:

  • Subspace Decomposition: Louver breaks the high-dimensional key space into $S$ smaller, contiguous coordinate subspaces to amplify pruning efficiency.
  • Balanced PCA Trees & Ball Enclosing: Within each subspace, keys are clustered into fixed-size groups ($r$) using a balanced Principal Component Analysis (PCA) tree. Each cluster is enclosed in a tight bounding ball defined by a center and a radius.
  • Two-Phase Filtering: At query time, Louver cheaply tests the bounding balls against the query halfspace. If a ball doesn't intersect the halfspace, the entire cluster is pruned. Only keys that survive the filter across all subspaces undergo an exact dot-product check.
  • Dynamic Updates: To handle streaming tokens during decoding without rebuilding the index from scratch, Louver buffers new keys and appends them incrementally via concurrent GPU streams.
Figure 3: Louver index architecture.

Datasets

The authors evaluated Louver across several demanding benchmarks using state-of-the-art open-weight models (including Llama-3.1-8B, Llama-3.2-3B, Qwen2.5-7B/14B, and DeepSeek-R1-Distill-Llama-8B):

  • Long-Context Understanding: LongBench v1 (a multi-task QA benchmark) and RULER (testing needle-in-a-haystack and variable tracking up to 32k tokens).
  • Long-Output Reasoning: AIME 2024 and MATH-500, which force models to generate extended chain-of-thought traces where the KV cache grows continuously.

Key Insights and Ideas

  • The Danger of Normalization: Standard similarity search techniques (like cosine similarity or MIPS) require normalizing vectors. However, LLM key vectors vary drastically in norm across layers and token positions. Forcing normalization distorts the model's learned representations. Halfspace range searching treats queries and keys as distinct geometric objects, preserving raw magnitudes.
  • Subspace Pruning Power: Testing bounding balls in lower-dimensional subspaces is mathematically more effective than in full dimensions because a ball of fixed radius subtends a smaller solid angle relative to a halfspace, leading to higher cluster rejection rates.
  • Hardware-Aware Design: By enforcing a fixed cluster size ($r$), Louver avoids irregular memory access patterns and conditional branching, making it highly compatible with vectorized CPU (AVX/FP16) and GPU (CUDA) execution.

Key Results

  • Perfect Recall: Louver empirically achieves $\ge 99.9\%$ recall of top-$k$ attention keys across all tested models, validating its zero-false-negative theoretical guarantee.
  • Accuracy: On reasoning tasks (MATH-500), Louver-TA actually surpassed dense attention accuracy (62.0% vs 58.0%), demonstrating that exact thresholding filters out distracting noise while retaining critical context.
  • Speedups: At a 40k context length, Louver achieves up to a 15.3× speedup over Torch Eager on GPU (outperforming FlashAttention-2) and a 10.3× speedup over Torch SDPA on CPU.
  • KV Cache Offloading: In CPU-offloading setups, Louver keeps only parent cluster centers on the GPU, achieving a 38.9% average F1 score on LongBench, significantly outperforming baselines like InfLLM (26.2%) and MagicPIG (25.2%).

Limitations and Future Work

The primary limitation of Louver is its memory overhead. Storing the parent cluster centers and radii introduces a non-zero GPU memory footprint (about 28% extra metadata overhead for a 1 GB KV cache).

To eliminate this overhead entirely, the authors suggest a promising direction for future work: replacing synthetic cluster centroids with actual, existing key vectors to act as "navigating nodes," similar to how hierarchical graph-based ANN indices (like HNSW) operate.

Summary updated

BibTeX
@inproceedings{dehghankar2026sparse,
  author = {Mohsen Dehghankar and Abolfazl Asudeh},
  title = {{Sparse Attention as a Range Searching Problem: Towards an Inference-Efficient Index for KV Cache}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=htJoIGk2K0},
}
Figure