Home / Learn / AI Infrastructure / KV Cache Offloading Explained
On this page
The problem it addressesHow it worksThe tiersWhen offloading pays offBenefitsWhat makes it difficultSharing across serversWhy it matters most for long contexts and agentsWhat it asks of the infrastructureRelated techniquesCommon questionsRelated guidesKV Cache Offloading Explained
KV cache offloading moves a language model’s cached conversation state out of accelerator memory to cheaper memory or storage, and brings it back when it is needed. Accelerator memory is fast, scarce and expensive. The KV cache for many simultaneous conversations can consume most of it. Offloading keeps caches that are not in active use on lower-cost tiers, which lets each accelerator serve more users and avoids recomputing work that has already been done.
The problem it addresses
A language model stores intermediate results for every token in a conversation so that it need not recompute them. This is the KV cache.
The cache is large, and there is one for each conversation. An inference server has three unsatisfactory options when accelerator memory fills up.
- Keep every cache in accelerator memory. The number of concurrent users is then limited by memory, well below what the accelerator’s arithmetic could support.
- Discard caches when a response is finished. When the user sends another message, the whole conversation must be processed again from the start. That costs compute and makes the user wait.
- Buy more accelerators solely to obtain more memory.
Offloading is a fourth option: keep the cache, but somewhere cheaper.
How it works
- Identify inactive caches. A conversation whose user is reading or typing does not need its cache in accelerator memory at that moment.
- Move them out. The cache is copied to a lower tier and the accelerator memory is freed for active work.
- Keep an index. The system records which cache is stored where.
- Bring them back. When the conversation resumes, the cache is loaded into accelerator memory and generation continues from where it left off.
The saving is that loading a cache is much quicker than recomputing it, provided the path from the lower tier is fast enough.
The tiers
| Tier | Speed | Capacity | Cost per gigabyte | Typical role |
|---|---|---|---|---|
| Accelerator memory | Fastest | Smallest | Highest | Active generation |
| Host system memory | Fast | Larger | Lower | Recently used caches |
| Pooled or expanded memory | Fast | Large | Lower | Shared capacity across servers |
| Local solid-state storage | Slower | Much larger | Low | Paused conversations |
| Networked storage | Slower, shared | Very large | Lowest | Long-lived and shared caches |
Systems typically use several tiers together, keeping the most recently used caches closest to the accelerator.
When offloading pays off
The decision is a comparison of two times.
- Time to recompute. Running the prefill phase again for the whole context. This grows with context length and uses accelerator compute.
- Time to reload. Reading the cache from the lower tier into accelerator memory. This depends on the cache’s size and the speed of the path.
For short contexts, recomputing is quick and offloading gains little. For long contexts, such as lengthy conversations, large documents or agent sessions, recomputation is expensive and reloading is far quicker, as long as the transfer is fast.
That last condition is the heart of the matter. Offloading only works well when data can move between tiers at high speed.
Benefits
- More users per accelerator. Memory is no longer tied up by idle conversations.
- Faster responses on resumption. The time to the first token is shorter than it would be after recomputation.
- Less wasted compute. Prefill work is done once.
- Lower cost. Cheaper memory and storage substitute for accelerator memory.
- Sharing. A cache held in shared storage can be used by any server, not only the one that created it.
- Resilience. A conversation can continue on a different machine if one fails.
What makes it difficult
- Transfer speed. Caches are large. Moving them quickly needs high-bandwidth, low-latency paths, ideally directly between storage or network and accelerator memory without passing through the CPU.
- Deciding what to move. Predicting which conversations will resume soon and which will not.
- Latency on return. A user whose cache has been offloaded waits while it is reloaded.
- Indexing and lookup. Finding the right cache among a very large number, quickly.
- Granularity. Managing the cache in blocks so that partial matches, such as a shared prefix, can be reused.
- Consistency. A cache is only valid for the exact model and settings that produced it.
- Security. A cache contains a representation of the user’s conversation. It must be isolated between tenants and protected when stored.
Sharing across servers
Storing caches centrally changes how an inference cluster behaves.
Without sharing, a follow-up request performs best if it is sent to the same server that handled the earlier ones, because that server holds the cache. This constrains load balancing.
With a shared cache tier, any server can fetch the cache. Requests can be routed more freely, capacity can be added or removed more easily, and common content, such as a widely used system instruction or a popular document, needs to be processed only once for the whole cluster.
Why it matters most for long contexts and agents
Two trends raise the stakes.
Longer context windows. Models that accept very long inputs produce very large caches. Keeping these in accelerator memory for every user is impractical.
Agentic workloads. AI agents make many model calls in sequence over a long, slowly growing context. Between calls, they wait for tools or other steps. Their caches are large, long-lived and intermittently used, which is exactly the pattern that offloading suits.
What it asks of the infrastructure
Offloading turns memory, storage and networking into direct contributors to inference performance.
- Fast storage with low latency.
- High-bandwidth networking between inference servers and cache storage.
- Direct data paths into accelerator memory.
- Efficient processing of storage and network traffic, so it does not consume the CPU capacity the server needs for other work. This is one of the roles of DPUs.
- Software that manages tiers, tracks caches and routes requests with cache location in mind.
The design of this data path is as important to the result as the accelerators themselves.
Related techniques
Offloading is often combined with other ways of reducing cache cost.
- Compression of the cache before storing it.
- Prompt caching, which reuses caches for shared prefixes.
- Separating prefill from decode, so that different hardware handles each.
Common questions
Does offloading slow down responses?
Reloading a cache takes some time, so a resumed conversation starts slightly later than one whose cache stayed in accelerator memory. It is usually much faster than recomputing the cache from scratch.
Where is an offloaded KV cache stored?
In host system memory, pooled memory, local solid-state drives or networked storage, depending on how soon it is likely to be needed.
Is offloading useful for short prompts?
Less so. When the context is short, recomputing is quick, and the overhead of moving the cache may not be worthwhile.