Not All Tokens Are Worth Caching: Learning Semantic-Aware Eviction for LLM Prefix Caches
This paper introduces SAECache, a semantic-adaptive prefix cache eviction policy that leverages the varying reuse values of different token types through a multi-queue architecture and online learning to significantly improve LLM serving efficiency while eliminating the need for manual parameter tuning.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you are running a very busy, high-end coffee shop (the Large Language Model or LLM) that serves millions of customers every day. To make coffee quickly, you have a special "memory shelf" (the GPU Memory) where you keep the pre-made ingredients and instructions for orders you've already started. This is called Prefix Caching.
If a new customer orders a latte that is 90% the same as a previous order, you don't need to grind new beans or steam new milk; you just grab the pre-made base from the shelf. This makes the first sip (the First Token) appear almost instantly.
However, your shelf is tiny. You can't keep every single pre-made base forever. Eventually, you have to throw some things away to make room for new orders. This is the Eviction Policy.
The Problem: The "One-Size-Fits-All" Mistake
For a long time, coffee shop managers used a simple rule: "Throw away the oldest item first." (This is the LRU policy).
The paper argues this is a bad idea because not all items on the shelf are equally valuable.
- The System Prompt: Imagine a "Standard Menu" that every customer sees. It never changes. It's incredibly valuable because everyone orders it.
- The Chain-of-Thought: Imagine a customer's messy, internal monologue about why they want a latte. This is unique to that one person and that one moment. It's almost never useful for the next customer.
The old rule treated the "Standard Menu" and the "Messy Monologue" exactly the same. If the Monologue was slightly newer than the Menu, the old rule would throw away the Menu to make room for the Monologue. This is a disaster because the next customer will need the Menu immediately, but the Monologue is useless to them.
The Solution: SAECache (The Smart Manager)
The authors created a new system called SAECache. Think of it as a smart manager who doesn't just look at when an item was last touched, but what the item actually is.
Here is how it works, using simple analogies:
1. The Four Specialized Bins (Multi-Queue Architecture)
Instead of one big shelf, SAECache organizes the shelf into four distinct bins, each with its own rules:
- The "Trash" Bin: Holds items that are almost never reused (like the messy monologue or the final steps of a drink). These get thrown away first.
- The "Template" Bin: Holds standard instructions and system prompts (like the menu). These are kept very carefully because they are reused constantly.
- The "Chat" Bin: Holds conversations where people talk back and forth.
- The "Agent" Bin: Holds complex tasks where the AI is doing work (like coding or using tools).
2. The "Value Score" (Semantic-Aware Weighting)
The manager doesn't just guess which bin is important. It learns!
- If the manager throws away a "System Prompt" and then immediately gets asked for it again, the system learns: "Oops! I threw away something valuable. I should give System Prompts a higher score next time."
- If it throws away a "Chain-of-Thought" and no one asks for it, it learns: "Good job! That was junk. I'll keep giving it a low score."
This happens automatically, like a manager adjusting the shelves based on what customers actually buy, without needing a human to tell them what to do.
3. The "Time Machine" (Adaptive Timing)
The system also learns when people come back.
- Chat sessions might have long pauses (like a customer taking a coffee break).
- Agent sessions might be very fast and frantic.
The system learns the specific "heartbeat" of each type of session. It knows that if a Chat session hasn't returned in 10 minutes, it's probably gone forever. But if an Agent session hasn't returned in 10 seconds, it might just be thinking. It adjusts its eviction rules in real-time to match the rhythm of the traffic.
The Results: Faster Coffee, Less Waste
The paper tested this new manager against the old "oldest-first" rule and other smart-but-rigid systems.
- Speed: The new system made the first sip of coffee appear 1.4 to 2.7 times faster in busy, mixed environments.
- Adaptability: The old systems broke when the type of customers changed (e.g., if the shop suddenly got more single-order customers instead of chatters). The new system adapted instantly.
- Efficiency: It saved a massive amount of "wasted" memory by not hoarding junk (like the messy monologues) and by keeping the valuable stuff (like the menu) safe.
Summary
In short, the paper says: Don't treat all memory blocks the same. Just because two things were touched at the same time doesn't mean they are equally useful. By teaching the computer to understand the meaning of the data (is this a menu? is this a joke? is this a tool?) and letting it learn from its own mistakes in real-time, we can make AI much faster and more efficient.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.