Abstract
The deployment of Large Language Models (LLMs) with long context windows is currently limited by the "memory wall"—the significant overhead associated with loading the Key-Value (KV) cache during the decoding stage. We present Quest, a query-aware sparsity algorithm that dynamically identifies and loads only the most critical portions of the KV cache for each token generation. By employing a min-max metadata approach to estimate attention importance, Quest achieves a 7.03× speedup in self-attention kernels and a 2.23× reduction in end-to-end latency while maintaining high accuracy across long-context benchmarks.
Introduction
Modern LLMs are pushing the boundaries of context length, with windows reaching 128K or even 1M tokens. However, this expansion introduces a severe performance bottleneck during the auto-regressive decoding phase. For a Llama-7B model, a 32k context window necessitates a 16GB KV cache. The time spent moving this data from memory to the GPU often exceeds 50% of the total inference latency.
Previous attempts to solve this problem typically involved "eviction" strategies, where less important tokens are permanently deleted from the cache. While effective for short-range tasks, these methods struggle with long-range dependencies; a token that appears irrelevant during one step may be crucial for a query several thousand tokens later. Quest proposes a different paradigm: query-aware sparsity that reduces memory movement without permanently discarding information.
Methodology: The Quest Algorithm
Quest operates on the principle that only a small fraction of the KV cache is necessary for any given query. It implements a two-stage process to optimize memory access:
1. Criticality Estimation
Quest manages the KV cache in discrete "pages." For each page, the algorithm maintains metadata consisting of the minimum and maximum values for every feature dimension of the Key vectors. When a new Query vector arrives, Quest uses these min-max "bounding boxes" to calculate a mathematical upper bound of the potential attention score for that specific page. This allows the system to estimate importance without reading the full Key vectors.
2. Sparse Attention
Based on the estimated scores, Quest selects only the Top-K highest-scoring pages. Only these "critical" pages are loaded into the GPU's high-speed memory for the actual self-attention calculation. Because the selection is recalculated for every new query, the model can dynamically "rediscover" tokens that were previously ignored, making it far more robust than query-agnostic eviction methods.
Layer-Specific Optimization
Empirical analysis revealed that the initial layers of Transformer models require dense attention to maintain performance. Consequently, Quest applies its sparsity mechanism only to later layers, where more than 90% of tokens can typically be ignored without impacting accuracy.
Experimental Evaluation
Quest was evaluated using several benchmarks designed to test long-context capabilities:
- PG19: To assess language modeling perplexity.
- Passkey Retrieval (10k and 100k): A "needle-in-a-haystack" test requiring the model to find a specific code within a vast context.
- LongBench: A comprehensive suite covering single-document QA, multi-document QA, summarization, and few-shot learning.
Results
Efficiency and Speed
Quest demonstrates significant performance gains. The self-attention kernel itself sees a 7.03× speedup. When integrated into a full inference pipeline using 4-bit quantization (AWQ), Quest provides a 2.23× reduction in end-to-end latency for 32k context lengths.
Accuracy and Robustness
In the Passkey Retrieval task, Quest maintained 100% accuracy even when restricted to a token budget of only 1% of the total context. In contrast, existing methods like H2O and TOVA failed (0-4% accuracy) because they had permanently evicted the target "needle" from the cache. On the LongBench suite, Quest achieved performance parity with full-cache models while significantly reducing memory traffic.
Discussion and Limitations
The success of Quest stems from the observation that token criticality is dynamic. A token's relevance is not an intrinsic property but is defined by its relationship to the current query. By using the "bounding box trick," Quest provides a computationally cheap way to respect this dynamism.
However, some limitations remain. The min-max estimation is a heuristic; while effective, there may be scenarios where the upper bound is too loose, leading to suboptimal page selection. Additionally, the current implementation is optimized for specific NVIDIA architectures (RTX 4090 and Ada 6000). Finally, Quest focuses on the decoding stage; the prefill stage, which processes the initial prompt, still requires full attention and remains a target for future optimization.
Conclusion
Quest offers a scalable solution to the KV cache bottleneck in long-context LLMs. By shifting from query-agnostic eviction to query-aware sparsity, Quest enables faster inference and lower memory overhead without sacrificing the model's ability to handle complex, long-range dependencies.
Summary updated