TL;DR
Large Language Models (LLMs) are increasingly used for complex tasks, but serving them efficiently remains a challenge. EPIC introduces a novel system for Position-Independent Caching (PIC), allowing LLMs to reuse cached document representations even when they appear in different parts of a prompt. By utilizing the LegoLink algorithm to recompute only a tiny fraction of "attention sink" tokens, EPIC achieves up to 8× faster Time-To-First-Token (TTFT) and 7× higher throughput than state-of-the-art systems, all with negligible accuracy loss.
The Problem: The Rigidity of Prefix-Based Caching
Standard LLM serving relies heavily on "prefix-based" context caching. For example, if you have a 10,000-token document and ask three different questions about it, the system can cache the document's Key-Value (KV) vectors to save computation. However, this optimization only works if the document is located at the very beginning of the prompt.
In real-world applications like Retrieval-Augmented Generation (RAG) or few-shot learning, prompts are highly dynamic. A prompt might consist of a system message, a few-shot example, and then the core document. If you change the system message, the "prefix" changes, and traditional caching breaks. Because the document's KV vectors are position-dependent, moving them even one token to the right usually destroys the model's accuracy.
Existing solutions attempting Position-Independent Caching (PIC) either suffer from massive recomputation overhead (making them slow) or significant accuracy degradation (making them unreliable).
Methods: The EPIC System and LegoLink Algorithm
The authors formalize PIC into a two-step framework:
- Compile: Generating and storing KV vectors for a chunk starting from position zero.
- Link: Retrieving and stitching these chunks together for a specific user request.
The core innovation of the EPIC system is the LegoLink algorithm. Its design is rooted in a key observation regarding the "attention sink" effect. In LLMs, the first few tokens of any sequence tend to absorb a disproportionate amount of attention. When a cached chunk is moved from the start of a prompt to the middle, these initial tokens still "act" like they are at the beginning, preventing the model from properly attending to the new preceding context.
LegoLink solves this attention sink dilemma through:
- Static Sparsity: Instead of relying on complex runtime calculations to determine which tokens need updating, LegoLink simply recomputes the first $k$ tokens (where $k \le 32$) of every cached chunk except the first one.
- Complexity Reduction: This static approach shifts the recomputation complexity from $O(N^2)$ (quadratic) to $O(kN)$ (effectively linear), where $N$ is the prompt length.
The authors implemented this within the popular vLLM framework, adding an explicit API for users to manage cache IDs similarly to a distributed KV store.
Key Insights and Results
The researchers evaluated EPIC across six diverse tasks (including LongBench and Needle In A Haystack) using three different model architectures: Mistral 7B, Llama 3.1 8B, and Yi Coder 9B.
- The Power of Static Sparsity: Previous state-of-the-art methods like CacheBlend used dynamic sparsity, attempting to calculate which tokens to recompute on the fly. EPIC demonstrates that a simple, static rule (always recompute the first $k$ tokens) is not only more efficient but just as accurate.
- Massive Speed and Throughput Gains: EPIC achieves up to an 8× reduction in TTFT compared to CacheBlend. Furthermore, it provides up to 7× higher throughput when serving multiple concurrent requests, as the reduced computation dramatically frees up GPU resources.
- Maintained Accuracy: Accuracy loss was kept within a tight 0-7% margin across most tasks, which is considered negligible given the massive performance gains.
- Memory Efficiency and Scaling: Because LegoLink recomputes fewer intermediate results, it is much less likely to hit Out-Of-Memory (OOM) errors. EPIC successfully handled contexts up to 50,000 tokens, while competing methods crashed at 35,000. While competing methods scale quadratically with context length, EPIC’s TTFT grows almost linearly.
Limitations and Future Work
While highly effective, the authors noted a few limitations. For "chatty" models on certain tasks (like MultiNews), the model would provide the correct answer but then continue generating unrelated lengthy outputs, which artificially lowered automated ROUGE/F1 scores. The authors suggest this is a common side-effect of sparsity-based algorithms that requires further study.
Additionally, the system's success is inherently tied to the robustness of the underlying model. For instance, the Yi Coder model performed poorly across all caching methods simply because it struggled with general document understanding. Future work will investigate why sparsity-based linking occasionally triggers unnecessary lengthy generations and how to further refine the linking process.
Summary updated