NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

QuickLLaMA: Query-aware Inference Acceleration for Large Language Models

Jingyao Li, Han Shi, Sitong Wu, Chuanyang Zheng, Zhenguo Li, Xin Jiang, Hong Xu, Jiaya Jia

The QuickLLaMA mascot, representing the system's ability to 'skim' through massive datasets efficiently.

Abstract

The capacity of Large Language Models (LLMs) to comprehend and reason over long contexts is pivotal for advancements in diverse fields. Yet, they still struggle with capturing long-distance dependencies within sequences to deeply understand semantics. To address this issue, we introduce Query-aware Inference for LLMs (Q-LLM), a system designed to process extensive sequences akin to human cognition. By focusing on memory data relevant to a given query, Q-LLM can accurately capture pertinent information within a fixed window size and provide precise answers to queries. It doesn’t require extra training and can be seamlessly integrated with any LLMs. Q-LLM using LLaMA3 (QuickLLaMA) can read Harry Potter within 30s and accurately answer the questions. On widely recognized benchmarks, Q-LLM improved by 7.17% compared to the current state-of-the-art on LLaMA3, and by 3.26% on Mistral on the ∞-bench. In the Needle-in-a-Haystack and BABILong task, Q-LLM improved upon the current SOTA by 7.0% and 6.1%.

1. Introduction: The Context Bottleneck

As Large Language Models (LLMs) are increasingly deployed for complex tasks such as repository-level coding, legal document analysis, and scientific research, the "context window"—the volume of text a model can process simultaneously—has become a critical bottleneck. While modern models claim to support windows of 128K or even 1M tokens, they frequently suffer from the "lost in the middle" phenomenon, where the model's attention is diluted by noisy, irrelevant information.

Existing solutions typically rely on expensive retraining or "sliding window" mechanisms that discard older data. Even advanced memory-based methods often utilize a static focal point, processing documents identically regardless of the specific user query. QuickLLaMA introduces Query-aware Inference (QLLM), a training-free system that enables LLMs to process million-token contexts by mimicking human skimming behavior: looking at the question first and then searching the text for relevant sections.

2. Methodology: Query-aware Inference (QLLM)

The core of the QLLM framework is its ability to perform purpose-driven retrieval without requiring any fine-tuning of the underlying base models (e.g., LLaMA3 or Mistral). The system partitions long input contexts into discrete "memory blocks" and employs a Query-aware Context Lookup strategy.

2.1 Relevance Scoring and Dynamic KV Cache

When a user submits a query, QLLM calculates a relevance score for each memory block based on its semantic match with the query and the current local context. Instead of feeding the entire document into the model's attention mechanism, QLLM constructs a compact, high-utility Key-Value (KV) cache consisting of:

  • Global Tokens: System prompts and task instructions.
  • Query Tokens: The user's specific question.
  • Query-related Blocks: Chunks of the document identified as highly relevant.
  • Local Tokens: The most recent tokens to maintain conversational coherence.

2.2 Efficient Offloading

To handle massive sequences on standard hardware, QLLM utilizes an offloading strategy. Essential blocks are maintained in GPU memory, while the bulk of the document is stored in CPU memory. Blocks are only fetched into the GPU when the lookup strategy deems them necessary for the current query.

3. Evaluation Benchmarks

Paul Graham, whose essays are a primary source for the long-context 'Needle-in-a-Haystack' retrieval tasks. Source, p. 2

Paul Graham, whose essays are a primary source for the long-context 'Needle-in-a-Haystack' retrieval tasks.

QLLM was evaluated across several rigorous long-context benchmarks:

  • ∞-Bench: Features extremely long contexts averaging 145K tokens.
  • LongBench: A comprehensive suite for long-context understanding (avg. 12.8K tokens).
  • Needle-in-a-Haystack: Tests the ability to retrieve a specific, tiny fact hidden within up to 128K tokens.
  • BABILong: Requires reasoning over facts distributed across very long documents.

4. Key Results

4.1 Performance and Accuracy

QLLM demonstrates significant performance gains over existing state-of-the-art (SOTA) methods. On the ∞-bench, it improved performance by 7.17% for LLaMA3 and 3.26% for Mistral. In the Needle-in-a-Haystack test, QuickLLaMA achieved a 100% success rate across all tested lengths up to 128K tokens. Furthermore, it improved upon SOTA by 7.0% on Needle-in-a-Haystack and 6.1% on BABILong tasks.

4.2 Speed and Scalability

The system is remarkably efficient, capable of processing 100K tokens in just 25.6 seconds (effectively "reading" Harry Potter in under 30 seconds) while using only 22.3GB of memory on a single A800 GPU. It successfully scaled to handle sequences of up to 1,024,000 tokens without the accuracy degradation typically seen in standard sliding-window models.

5. Discussion and Limitations

While QLLM offers a significant leap in inference acceleration, it currently relies on a fixed window size. If a query requires synthesizing information from a number of blocks that exceeds this window, some information loss may occur. Future work will explore dynamic segmentation, where the model determines block boundaries based on semantic meaning rather than simple heuristics, and improving reasoning capabilities for tasks that require connecting dots across hundreds of disparate blocks.

Conclusion

QuickLLaMA proves that LLMs do not necessarily need more parameters or longer training to handle massive contexts; they need better inference strategies. By making the attention mechanism query-aware, QLLM filters out document noise and focuses on the signal, providing a fast, scalable, and training-free solution for the next generation of long-context AI applications.

Summary updated

BibTeX
@inproceedings{li2025quickllama,
  author = {Jingyao Li and Han Shi and Sitong Wu and Chuanyang Zheng and Zhenguo Li and Xin Jiang and Hong Xu and Jiaya Jia},
  title = {{QuickLLaMA: Query-aware Inference Acceleration for Large Language Models}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2025},
  url = {https://openreview.net/forum?id=36usw155si},
}
Figure