KV cache offloading is the technique of moving the key and value tensors that a transformer stores during inference out of scarce GPU high-bandwidth memory into a cheaper, larger tier such as CPU DRAM, local NVMe drives or networked storage, and bringing them back when they are needed. In AI infrastructure, it is one of the main tools for serving long contexts, many concurrent users and reusable prompts without buying more accelerators.
The technique trades memory capacity for transfer latency. Every token kept in a slower tier frees GPU memory for larger batches, but it must cross a PCIe, NVLink or network link before the attention layers can use it again, so the design goal is to hide that transfer behind useful computation.
Why the KV cache outgrows GPU memory
The KV cache grows linearly with sequence length, batch size and model depth, because every layer stores one key vector and one value vector per token and per attention head group. For a 70-billion-parameter model with grouped-query attention, a single 128,000-token context can need tens of gigabytes in 16-bit precision, which rivals the weights themselves.
When the cache cannot fit, a server must reject or preempt requests, shrink batches, or recompute evicted tokens through a fresh prefill phase. Offloading adds a fourth option: keep the data, but park it in a slower tier until the next decoding step or the next conversation turn requires it.
The economics follow from the price gap between tiers. A gigabyte of host DRAM costs far less than a gigabyte of HBM, and NVMe capacity is cheaper still. Reloading a cached prefix also costs much less energy than running the attention and feed-forward computation again, so offloading often lowers cost per token as well as latency for repeated prompts.
Offloading also changes capacity planning. Instead of sizing a GPU cluster for peak cache demand, operators can size GPU memory for active decoding only and let the slower tiers absorb idle sessions, which makes utilization more predictable during traffic spikes.
How KV cache offloading works
An offloading system manages the cache in fixed-size blocks, similar to pages in operating system memory, which is why it pairs naturally with PagedAttention. A cache manager tracks where each block lives, decides which blocks to evict, and schedules asynchronous copies so that transfers overlap with computation on other layers or other requests.
The following table lists the storage tiers commonly used and their rough characteristics; exact figures depend on hardware generation and topology.
| Tier | Typical capacity per node | Approximate bandwidth to GPU | Best use |
|---|---|---|---|
| GPU HBM | 80-192 GB per GPU | Several TB/s (local) | Active decoding tokens |
| CPU DRAM | 0.5-2 TB | About 50-450 GB/s via PCIe or chip links | Paused sessions, recent prefixes |
| Local NVMe SSD | Several to tens of TB | About 5-25 GB/s across drives | Long-lived prompt prefixes |
| Networked storage | Effectively unbounded | Depends on RDMA fabric | Cluster-wide shared prefixes |
Systems usually apply an eviction policy such as least recently used, sometimes weighted by prefix popularity. Some designs prefetch layer by layer: while layer n runs attention, the blocks for layer n+1 are already in flight, which hides much of the copy time during long prefill computations.
Main offloading strategies
KV cache offloading is not one algorithm but a family of strategies that differ in what they move and when. Choosing among them depends on whether the bottleneck is concurrency, context length or repeated prompts.
| Strategy | What is offloaded | Primary benefit |
|---|---|---|
| Session offloading | Whole caches of idle conversations | Fast resume of multi-turn chats |
| Prefix offloading | Shared system prompts and documents | Avoids repeated prefill work |
| Layer-wise offloading | Older layers during long prefill | Fits very long single contexts |
| Sparse retrieval offloading | Low-attention tokens of long contexts | Loads only relevant blocks back |
| Disaggregated transfer | Caches from prefill to decode nodes | Separates compute-heavy phases |
Open-source serving stacks such as vLLM and companion libraries provide CPU and disk connectors, while some deployments add a distributed cache layer so that any node in a GPU cluster can fetch a prefix computed elsewhere.
Comparison with related memory techniques
Offloading is often combined with other techniques that reduce memory pressure, and each addresses a different part of the problem. The table below separates their effects.
| Technique | How it saves GPU memory | Main cost |
|---|---|---|
| KV cache offloading | Moves blocks to slower tiers | Transfer latency and bandwidth |
| KV cache quantization | Stores values in 8 or 4 bits | Possible accuracy loss |
| PagedAttention | Removes fragmentation waste | Indexing overhead, little else |
| Prompt caching | Reuses computed prefixes | Needs storage, often offloading |
| Recomputation | Discards cache and rebuilds it | Extra GPU compute per request |
In practice, quantization and offloading stack well: a 4-bit cache moves four times fewer bytes than a 16-bit one, which directly shortens transfer time. Offloading becomes attractive whenever reloading is cheaper than recomputing, which is typically true for prefixes of several thousand tokens.
Configuration choices and performance trade-offs
Tuning an offloading setup means balancing time to first token, time per output token and overall goodput. The decision table below summarizes common situations.
| Situation | Recommended approach | Reason |
|---|---|---|
| Many idle multi-turn chats | Offload sessions to CPU DRAM | Resume is faster than full prefill |
| Shared long system prompt | Persist prefix on NVMe or cluster store | Reuse across users and nodes |
| Strict per-token latency goals | Keep decoding cache on GPU | Transfers would stall decoding |
| Short prompts, short answers | Skip offloading | Overhead exceeds benefit |
The most common failure is bandwidth saturation: if many requests reload large caches at once, the PCIe link becomes the bottleneck and latency spikes. Other pitfalls include pinned-memory exhaustion on the host, cache invalidation errors after model updates, and storing tenant data without proper isolation and encryption.
A plain-language summary
When a language model reads your text, it keeps working notes about every word. These notes sit in the graphics card’s memory, which is very fast but small.
With long documents or many users, the notes no longer fit. KV cache offloading moves some notes to a bigger, slower shelf, such as the computer’s main memory or a fast disk. When they are needed again, they come back. It is like moving older files from your desk to a nearby cabinet. The desk stays clear, and nothing has to be rewritten.
An example from practice
A company runs an internal assistant on a server with eight GPUs. Every request starts with the same 20,000-token policy manual as context, and employees often pause conversations for several minutes before asking follow-up questions.
Without offloading, the server recomputes the manual for each new session and evicts paused chats under load, so first responses take several seconds. The operations team enables prefix caching with CPU and NVMe offloading, assigning about 1 TB of host memory and a local SSD array to cached blocks.
After the change, most requests load the manual from host memory instead of recomputing it, paused chats resume without a fresh prefill, and the cluster serves noticeably more concurrent users. The team keeps active decoding entirely on the GPUs, so per-token latency stays unchanged.