Accelerating Iterative Retrieval-augmented Language Model Serving with Speculation

Zhihao Zhang, Alan Zhu, Lijie Yang, Yihua Xu, Lanting Li, Phitchaya Mangpo Phothilimthana, Zhihao JiaICML 2024

TL;DR

RaLMSpec is a novel framework designed to significantly speed up iterative retrieval-augmented language models (RaLMs). By leveraging "speculative retrieval" from a fast local cache and "batched verification" against the full knowledge base, it achieves up to a 7.59x speedup in token-level tasks and up to 2.39x in document-level tasks. Crucially, it provides mathematically guaranteed exact same output quality as standard iterative methods.

The Bottleneck in Iterative RaLM

Retrieval-Augmented Generation (RAG) empowers Large Language Models (LLMs) by granting them access to external, up-to-date information. While "one-shot" RAG (retrieving once at the start of a prompt) is common, iterative RaLM—where the model retrieves new information multiple times during the generation process—yields much higher accuracy for complex tasks.

However, iterative RaLM is notoriously slow. Because LLMs generate text token-by-token, the system must pause and wait for a slow external database query to finish before it can generate the next segment of text. These sequential, context-dependent queries create a massive latency bottleneck. The authors ask: Can we reduce this overhead without sacrificing the generative quality that makes iterative retrieval so effective?

Comparison of standard Iterative RaLM and RaLMSpec

The RaLMSpec Solution

To solve this, the authors introduce RaLMSpec, applying the concept of speculative execution (common in computer architecture) to the retrieval process. The framework consists of several key components:

  1. Speculative Retrieval: Instead of querying the slow, massive external knowledge base every time, RaLMSpec first looks in a small, fast local retrieval cache. This cache stores recently or frequently accessed documents.
  2. Batched Verification: After a certain number of speculative steps (the "stride"), the system performs a single batched query to the external knowledge base to verify if the speculative guesses were correct. Batching is significantly more efficient than sequential queries because it exploits hardware parallelism.
  3. Optimal Speculation Stride Scheduler (OS³): A fixed stride isn't always efficient. OS³ dynamically adjusts the number of speculative steps based on the current "hit rate" of the cache and the relative speeds of the model and the retriever.
  4. Cache Prefetching: The system proactively fetches the "top-k" documents into the local cache during verification to increase the likelihood of future speculative hits.
  5. Asynchronous Verification: To further hide latency, RaLMSpec can run the verification of previous steps in the background while the model continues to speculate on the next steps.
Asynchronous verification and rollback mechanism

Key Insights: Why It Works

  • Exploiting Locality: The "aha moment" is the observation of temporal and spatial locality in retrieval. LLMs often need the same or consecutive documents over several generation steps. A local cache is highly effective because the "working set" of information for a single prompt is usually small.
  • Batching over Sequential: In modern systems, the cost of one batch of 5 queries is often not much higher than the cost of 1 query. RaLMSpec turns a sequential bottleneck into a parallel advantage.
  • Lossless Acceleration: Unlike other acceleration methods that might approximate the output to save time, RaLMSpec includes a "rollback" mechanism. If the verification step finds a mismatch (as seen in the figure above), the model rolls back to the last correct state and regenerates, ensuring the final output is identical to a standard iterative RaLM.

Performance and Results

The researchers evaluated RaLMSpec across several standard benchmarks (Wiki-QA, Web Questions, Natural Questions, Trivia QA, and WikiText-103) using three types of retrievers: Exact Dense (DPR), Approximate Dense (DPR-HNSW), and Sparse (BM25).

The performance gains vary based on the type of retriever used, with slower retrievers seeing the most benefit from speculation:

  • Document-Level Serving:
    • Exact Dense Retriever: 1.75x to 2.39x speedup.
  • Sparse Retriever: 1.31x to 1.77x speedup.
  • Approximate Dense Retriever: 1.04x to 1.39x speedup.
  • Token-Level Serving (kNN-LM): Achieved a massive 7.59x speedup for exact dense retrievers and 2.45x for approximate dense retrievers.

The OS³ scheduler proved essential across these tests, allowing the system to maintain speedups even when the cache hit rate fluctuated.

Limitations and Future Work

The speedup is intrinsically tied to the ratio of retrieval latency versus model decoding latency. If the retriever is already extremely fast (like some approximate methods), the overhead of managing the speculative cache can diminish the gains. Additionally, the authors noted that the Global Interpreter Lock (GIL) in Python prevented them from fully realizing the benefits of asynchronous verification in their current implementation. Future directions include exploring more sophisticated cache update policies and extending the framework to multi-GPU environments to further decouple retrieval and generation.

Summary updated

BibTeX
@inproceedings{zhang2024accelerating,
  author = {Zhihao Zhang and Alan Zhu and Lijie Yang and Yihua Xu and Lanting Li and Phitchaya Mangpo Phothilimthana and Zhihao Jia},
  title = {{Accelerating Iterative Retrieval-augmented Language Model Serving with Speculation}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=CDnv4vg02f},
}
Figure