What is key-value (KV) cache offloading?

KV cache offloading is moving the key and value tensors stored for earlier tokens in language model inference to system memory or disk when GPU memory runs short or they are idle, then bringing them back when needed.

Unlike KV cache quantisation, which shrinks the cache by storing it in fewer bits, offloading moves it unchanged to cheaper, larger memory; the two can be combined. CPU offloading is a broader approach also covering weights.

Topic
Inference and performance
Also known as
KV cache swapping

How key-value (KV) cache offloading works

  1. The inference engine tracks each request's KV cache in blocks.
  2. When GPU memory fills, blocks of waiting or low-priority requests move to system memory.
  3. When the request resumes, blocks reload to the GPU, with transfer overlapped with compute where possible.
  4. Some systems keep frequently shared prefixes in system memory or on disk to avoid recomputation.

In more detail

Interconnect bandwidth versus recomputation

KV cache offloading performance depends heavily on interconnect bandwidth: transferring tens of gigabytes over PCIe Gen4/Gen5 (~32 to 64 GB/s per direction) is orders of magnitude slower than reading from GPU HBM (>3 TB/s), whereas coherent CPU-GPU links such as NVLink-C2C (up to ~900 GB/s) or RDMA over InfiniBand/RoCEv2 significantly narrow this gap. If reload time exceeds the recomputation time of the prefill stage, recomputing the KV cache on the GPU can be faster than loading it from slow storage.

Multi-tier KV hierarchies and disaggregated serving

Modern inference stacks extend offloading beyond single-node swapping into multi-tier KV hierarchies (GPU HBM → host DDR5 RAM → local NVMe → distributed object/RDMA stores) and disaggregated prefill/decode architectures. In disaggregated serving, dedicated prefill nodes compute the initial KV cache and stream it directly to decode nodes, avoiding interference between latency-sensitive token generation and compute-heavy prompt ingestion.

Request-level swapping and layer-wise prefetching

Offloading can operate either at the request level, swapping entire blocks of paused requests out of VRAM or at the layer level, streaming each layer's KV cache from host memory just ahead of attention computation via asynchronous CUDA streams. Layer-wise prefetching lets very long contexts run even when a single request's KV cache alone exceeds GPU VRAM.

Commonly confused terms

TermHow it differs
Prefix cachingPrefix caching reuses matching initial prompt blocks already stored across requests, whereas offloading is the memory-tiering mechanism that determines whether those blocks live in GPU HBM, host RAM or NVMe/network storage.

Why key-value (KV) cache offloading matters for on-premises AI

The KV cache grows with context length and concurrent requests; poorly managed, it limits batch size and throughput. A study of high-throughput serving shows each request's cache is large and grows and shrinks dynamically, with inefficient management wasting memory through fragmentation and duplication. A system for limited GPUs combined GPU, CPU and disk memory and compressed the attention cache to 4 bits to run a very large model on a single 16 GB GPU. The cost is transfer latency.

ON-PREMISES EXAMPLE

A legal technology company's in-house assistant processing long contracts moves waiting sessions' KV cache to system memory when GPU memory fills; when a user returns the cache reloads and time to first token is tracked.

Common questions

Does KV cache offloading add latency?

Yes, there can be waiting while the cache reloads to the GPU; overlapping transfer with compute reduces the effect.

When is KV cache offloading needed?

When long contexts and many concurrent sessions exceed GPU memory and adding GPUs is not possible.

Sources

In the glossary: Glossary, E to L

What does this term mean for your infrastructure?

We can work out together in a technical assessment how it maps onto your data, hardware and security requirements.

Request a technical assessment →

This site sets no cookies. Visitor numbers are counted in aggregate using a cookieless method that does not identify anyone. See the Privacy Policy for details.