InstCache: A Predictive Cache for LLM Serving

Longwei Zou, Yan Liu, Jiamu Kang, Tingfeng Liu, Jiangang Kong, Yangdong Deng

As Large Language Models (LLMs) move from novelty to infrastructure, the engineering challenge shifts from "how do we build them?" to "how do we serve them efficiently?" Caching is the classic solution to high-latency computation, but LLMs present a unique hurdle: users rarely ask the exact same question twice.

In their recent paper, InstCache: A Predictive Cache for LLM Serving, researchers from Tsinghua University and Didi Global propose a shift from reactive caching to predictive caching. By leveraging the model's own understanding of language probability, they’ve developed a system that "guesses" what users will ask next, achieving hit rates that far exceed traditional methods.

TL;DR

InstCache is a predictive caching mechanism that pre-populates instruction-response pairs by identifying high-probability queries within a model's representation space. It achieves hit rates up to 2.3x higher than the theoretical upper bound of traditional caches and reduces serving latency by up to 50%.

What Problem Does This Paper Address?

Traditional caching relies on temporal locality—the idea that if a piece of data was accessed recently, it will likely be accessed again soon. In web search, this works great because many people search for the same short keywords. However, LLM instructions are long, complex, and highly diverse.

As shown in the researchers' analysis of real-world datasets, exact repetition is incredibly rare (only ~3.7% in the WildChat dataset).

Figure 1: Subfigure (a) presents the token length distribution of first-turn instructions across three real-world conversation datasets. Subfigure (b) shows the frequency of instructions in the WildChat dataset, sorted in descending order. The analysis reveals that most instructions are relatively long and exhibit minimal repetition across requests.

While "semantic caching" (matching queries based on vector similarity) exists, it often suffers from high mismatch rates—returning a cached answer to a query that looks similar but asks for something fundamentally different. The authors found that up to 30% of semantic cache hits were actually mismatches.

Methods

The core innovation of InstCache is treating the entire space of possible text as a V-ary tree, where $V$ is the vocabulary size. Every possible instruction is a path from the root to a leaf.

Figure 2: Text space can be represented as paths in a V-ary tree of depth L, constructed by a language model with a vocabulary size of V and a maximum token length of L. In this V-ary tree, each node corresponds to a token, and each edge represents the probability of generating that token given the preceding context. The child nodes of any given node are ordered by their probabilities. Each path from the root to a leaf defines a unique text, collectively forming a sequential text space. Given the NLL of each path, these text sequences can be projected onto a one-dimensional space. For simplicity, the figure demonstrates a binary tree and assumes that each node’s children follow an identical probability distribution. Under this assumption, text2 and text3 share the same NLL.

The researchers use Negative Log-Likelihood (NLL) to navigate this tree. In simple terms:

  1. Reordering the Space: They use a fine-tuned LLM to calculate the probability of various instructions. High-probability instructions have low NLL.
  2. Inducing Spatial Locality: By focusing on instructions with low NLL, they "gather" the most likely user queries into a compact, predictable region of the text space.
  3. Pre-population: Using a depth-first search algorithm, they traverse the tree to find all instructions below a certain NLL threshold ($\sigma$). They then generate responses for these predicted instructions offline and store them in a high-speed hash table.

At runtime, when a user sends a request, the system first checks this "predictive" hash table. If it's a hit, the response is returned instantly, bypassing the expensive LLM inference entirely.

Datasets

The authors evaluated InstCache across four diverse, real-world conversation datasets:

  • WildChat: 1 million real user-ChatGPT interactions.
  • LMSys: 1 million conversations from the Chatbot Arena.
  • ShareGPT: 100,000 user-shared realistic conversations.
  • Moss: 1.1 million synthetic conversations generated via LLM paraphrasing.

To ensure realistic results, they filtered out "noise" like "hello" or "test" and de-duplicated instructions coming from the same IP addresses.

Key Insights and Ideas

  • LLMs as Address Remappers: The most profound insight is that an LLM can act as a memory address remapping mechanism. It transforms a sparse, chaotic access pattern (random user queries) into a dense, predictable pattern (high-probability NLL regions).
  • The Failure of Similarity: The paper provides a sobering look at semantic caching (like GPTCache). It demonstrates that "how big is the earth?" and "how large does a planet have to be?" are semantically similar in vector space but require different answers. InstCache avoids this by using exact matches on predicted queries.
  • Predictive Power: Unlike traditional caches that only store what they have already seen, InstCache can cache instructions that have never appeared before but are likely to appear based on the model's training.

Key Results

InstCache significantly outperforms traditional caching baselines:

  • Higher Hit Rates: On the WildChat dataset, InstCache achieved an 8.2% hit rate, which is 2.3x higher than the 3.6% theoretical limit of an exact-match cache.
  • Latency Reduction: When integrated with the vLLM serving engine, it reduced the "time per output token" by 42.0% on LMSys and 50.0% on Moss.
  • Scaling: The hit rate scales continuously with cache size. As storage becomes cheaper, the potential performance gains from InstCache grow.
Hit rates scale with cache size, significantly exceeding the repetition rate (dashed line).

Limitations and Future Work

While impressive, InstCache is not a "set it and forget it" solution:

  • Distribution Shift: User behavior changes over time (e.g., seasonal topics). A static InstCache will see its hit rate decline as the "real" distribution drifts away from the training data. The authors suggest periodic updates are necessary.
  • Pre-population Cost: Generating the cache requires significant offline computation, though the authors note that pre-populating 10,000 instructions takes only about a minute on an A100 GPU.
  • Timeliness: It is unsuitable for queries requiring real-time information (e.g., "What is the weather today?").
  • Privacy: The authors emphasize the need to filter personal identifiable information (PII) during the pre-population phase to prevent data leakage.

In the future, the team plans to develop distributed implementations to scale InstCache across even larger computer clusters.

Summary updated

BibTeX
@misc{zou2024instcache,
  author = {Longwei Zou and Yan Liu and Jiamu Kang and Tingfeng Liu and Jiangang Kong and Yangdong Deng},
  title = {{InstCache: A Predictive Cache for LLM Serving}},
  year = {2024},
  eprint = {2411.13820},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.13820},
}
Figure