Pidoku

KV Offloading and Transfer

Module 14 Lesson 14.k 1h 15m Difficulty 4/5

Prerequisites 12.e, 12.m, 9.b, 9.e

9.e owns the links and transfer libraries (GPUDirect, NIXL, LMCache, Mooncake); 19.b owns vLLM’s connector flags; 13.i places offloading among the other KV-saving techniques; 14.l covers caches shared between machines. This lesson is the tiering itself: what to move out of HBM, where to, and when fetching beats recomputing.


Before you start: words you need#

WordPlain meaning
OffloadingCopying KV cache blocks out of GPU memory (HBM) to a larger, cheaper tier, and copying them back when needed.
TierOne level of storage: HBM, CPU memory (DRAM), local SSD (NVMe), or a remote store. Each step down is bigger, cheaper and slower.
HitA new request whose prefix is already cached somewhere, so its KV can be loaded instead of computed (12.m).
RecomputeRunning the prefill again to rebuild KV that was thrown away.
Pinned memoryHost memory locked in place so the GPU’s copy engines can read and write it directly (5.d). Copies from ordinary memory are slower and may block.
DMADirect memory access: a copy done by the GPU’s copy engines, not by its compute cores, so it runs alongside kernels (9.b).
NVLink-C2CThe coherent chip-to-chip link between a Grace or Vera CPU and its GPUs, several times faster than PCIe.

1. What is it?#

An engine’s KV pool lives in HBM, and HBM is small: after the weights, a GPU may have tens of GB left for cache. When the pool is full, the engine evicts blocks that no running request is using, and their contents are lost. The next request that needed them pays the full prefill again.

KV offloading keeps those blocks instead: it copies them to CPU memory, then perhaps to SSD, and copies them back on a hit. It turns the prefix cache from “what fits in HBM” into “what fits in the whole machine”.

flowchart TB
  G[("GPU HBM<br/><small>running requests, hot prefixes</small>")] -->|"evict: async copy out"| C[("CPU DRAM<br/><small>warm prefixes, paused sessions</small>")]
  C -->|"evict"| N[("Local or shared SSD<br/><small>cold prefixes, long sessions</small>")]
  C -.->|"hit: copy back before the step"| G
  N -.->|"hit: staged through CPU"| C
  Q{"fetch faster than<br/>recompute?"} -->|"almost always"| F["load"]
  Q -->|"tiny prefix,<br/>slow tier"| R["recompute"]
  class G,C memory
  class N io
  class Q queue
  class F memory
  class R compute

In 2026 this is no longer an experiment. vLLM ships a native offloading connector (CPU since v0.11, CPU plus file, object-store and peer tiers since v0.22), LMCache and NVIDIA Dynamo’s KV Block Manager (KVBM) do the same for several engines, and DeepSeek reported that 56% of a day’s input tokens were served from its on-disk KV cache.

Facts checked on 13 November 2026.


2. Why does it exist?#

Three workloads made it necessary:

  • Shared prefixes. System prompts, tool definitions, retrieved documents and few-shot examples repeat across requests. A bigger cache means more hits.
  • Multi-turn and agent sessions. A conversation pauses between turns; an agent pauses while a tool runs. Without offloading, its KV is evicted during the pause and the whole history is prefilled again on the next turn. 24.h cites a study in which coding agents spent about 38% of their time regenerating KV that had been dropped during tool calls.
  • Long context. A 128k-token session can take 20 GB of cache (14.i). Only a few fit in HBM at once; the rest must live somewhere.

In every case the alternative is recomputing, which costs GPU time that could have served other users, not only latency for this one.


3. Simple analogy#

A desk, a filing cabinet and an archive.

The papers you are working on are on the desk (HBM). When the desk is full you do not shred the folder you will need after lunch; you put it in the cabinet beside you (CPU memory). Files you need next month go to the archive downstairs (SSD). Fetching a folder from the cabinet takes seconds; rewriting it from memory takes hours. You only shred something when rewriting it would be quicker than walking to get it, which is almost never.


4. Tiny example: one returning conversation#

A 70B model at TP 8 with an FP8 cache. A user’s conversation has 32,000 tokens of history; they reply after five minutes, by which time HBM has been reused for other users.

without offloading   prefill all 32,000 tokens again       ≈ 1.8 s of the whole 8-GPU replica
with a CPU tier      copy 5.2 GB back, 0.65 GB per GPU,
                     each over its own PCIe Gen5 link       ≈ 13 ms

The user’s first token arrives about 1.8 s sooner, and the replica keeps 1.8 s of compute for other requests. Section 6 does the same sum for other prefix lengths and tiers.


5. Technical explanation#

What offloading is for, and what it is not for#

  • For: blocks that are not being used right now. Cached prefixes, paused sessions, and finished requests whose prefix may come back.
  • Not for: the KV of sequences being decoded. Every decode step reads all of a sequence’s cache (or, with sparse attention, a selected part). Streaming 20 GB over PCIe per step would make each step hundreds of milliseconds. Active KV stays in HBM; 13.i explains why.

The one exception is research systems that keep distant tokens off the GPU and fetch only the blocks attention selects (24.c). These are emerging, not standard.

The tiers in 2026#

TierTypical size per 8-GPU serverAchieved bandwidth per GPUNotes
HBM0.6–2.3 TB total, much of it weights3–8 TB/sWhere running requests live
CPU DRAM over PCIe Gen5 x161–4 TB~50 GB/s one way (vLLM measured), ~83 GB/s both ways at onceEach GPU has its own link, so a TP group fetches in parallel
CPU over NVLink-C2C (Grace, Vera)~0.5 TB per Grace; up to 1.5 TB per VeraSeveral times PCIe (900 GB/s total on Grace, 1.8 TB/s on Vera, 7.c, 7.e)Makes the CPU tier nearly an extension of HBM
Local NVMe10–100 TB~3–14 GB/s per driveSurvives restarts; staged through CPU, or direct with GPUDirect Storage (3.g)
Shared or remote storeUnboundedNetwork-limited, ~45 GB/s per 400G NICShared between replicas: 14.l

Fetch or recompute#

recompute time = prefill FLOPs / (achieved FLOP/s × GPUs)
               ≈ (2 × params × S + 2 × layers × S² × hidden) / ...
fetch time     = KV bytes per GPU / tier bandwidth per GPU

Two things make fetching win by more than older rules of thumb suggest:

  • Recompute grows faster than the KV does. The KV grows linearly with the prefix length S; the attention part of prefill grows with S². The longer the prefix, the bigger the win.
  • Each GPU fetches only its own shard. With TP 8, each GPU holds one eighth of the KV and has its own PCIe link and NIC. The replica’s aggregate bandwidth is eight links, not one.

Where fetching can lose: very short prefixes on a slow tier, where the fixed cost of each lookup and I/O dominates; and transfers that land on the critical path instead of being overlapped.

How a good implementation works#

  • Copy out asynchronously. When blocks are full (or evicted) they are copied to pinned host memory on a separate stream with DMA, so the forward pass never waits. vLLM found DMA beats a custom copy kernel once blocks are large (its v0.12 layout made blocks 0.5–2.5 MB) and does not steal compute cores.
  • Load before the step. On a hit the scheduler allocates GPU blocks, starts the copy, and schedules the request when the data is there; other requests run meanwhile (19.b covers vLLM’s waiting state).
  • Store each block once. Blocks are named by the hash of their tokens (12.m), so identical prefixes share one copy in every tier.
  • Evict by value, not only by age. LRU (least recently used) is the default; ARC-style policies and time-to-live for paused agent sessions keep likely-to-return blocks longer (24.c, 24.h).
  • Handle hybrid models. Sliding-window layers need only their window, and linear-attention layers have a fixed state rather than per-token KV; current offloaders handle both (14.i).

What ships#

  • vLLM: --kv-offloading-size <GiB> turns on the native CPU tier; the OffloadingConnector with TieringOffloadingSpec adds file-system, S3-compatible object-store and peer tiers behind the CPU tier. On preemption vLLM V1 always recomputes, but blocks already offloaded are loaded back instead (17.c). Flags and options: 19.b.
  • LMCache: a KV management layer for vLLM and SGLang across CPU, disk, Redis/Valkey, S3 and Mooncake (9.e).
  • SGLang: HiCache, a hierarchical radix cache across GPU, host memory and storage back-ends.
  • NVIDIA Dynamo KVBM: offloads across GPU, CPU, SSD and remote storage for its back-ends (21.j).
  • Hardware: NVIDIA’s Inference Context Memory Storage platform (announced at CES 2026) is an Ethernet-attached flash tier managed by BlueField-4 DPUs, positioned between local and shared storage for agent context (vendor positioning; 14.l).

6. Under the hood: fetch or recompute, by tier#

The program compares recomputing a cached prefix on a TP 8 replica of a 70B dense model with loading it from each tier. Bandwidths are achieved per-GPU values (PCIe from vLLM’s measurements, the others assumed and labelled in the code).

Go
// kvtiers.go — fetch a cached prefix from a tier, or recompute it?
package main

import "fmt"

func main() {
	// 70B dense model, 80 layers, hidden size 8192, GQA-8, head dim 128, FP8 KV cache.
	const params, layers, hidden = 70e9, 80.0, 8192.0
	const kvPerToken = 2 * 80 * 8 * 128 * 1.0 // bytes: K and V, all layers
	const gpus = 8.0                          // TP=8: each GPU holds 1/8 of the KV
	const achieved = 400e12                   // FLOP/s per GPU actually sustained in prefill (assumed)

	// Achieved one-direction bandwidth PER GPU. Each GPU fetches its own shard over its own path.
	tiers := []struct {
		name string
		bw   float64 // bytes/s per GPU
	}{
		{"CPU/PCIe5", 50e9},  // measured by vLLM's offloading benchmarks
		{"CPU/C2C", 300e9},   // Grace-class NVLink-C2C (assumed achieved share)
		{"NVMe", 12e9},       // 8 Gen5 drives (~100 GB/s) shared by 8 GPUs
		{"RDMA-store", 45e9}, // one 400G NIC per GPU, remote store
	}

	fmt.Printf("%-8s %8s %10s", "prefix", "KV", "recompute")
	for _, t := range tiers {
		fmt.Printf(" %13s", t.name)
	}
	fmt.Println()
	for _, s := range []float64{1e3, 8e3, 32e3, 128e3} {
		// Prefill FLOPs: 2 x params per token, plus causal attention ~2 x layers x S^2 x hidden.
		flops := 2*params*s + 2*layers*s*s*hidden
		recompute := flops / (achieved * gpus)
		kv := s * kvPerToken
		fmt.Printf("%-8s %6.1fGB %8.0fms", fmt.Sprintf("%.0fk", s/1e3), kv/1e9, recompute*1e3)
		for _, t := range tiers {
			fetch := kv / gpus / t.bw
			fmt.Printf(" %6.1fms %4.0fx", fetch*1e3, recompute/fetch)
		}
		fmt.Println()
	}
}

Output:

prefix         KV  recompute     CPU/PCIe5       CPU/C2C          NVMe    RDMA-store
1k          0.2GB       44ms    0.4ms  108x    0.1ms  647x    1.7ms   26x    0.5ms   97x
8k          1.3GB      376ms    3.3ms  115x    0.5ms  689x   13.7ms   28x    3.6ms  103x
32k         5.2GB     1819ms   13.1ms  139x    2.2ms  833x   54.6ms   33x   14.6ms  125x
128k       21.0GB    12311ms   52.4ms  235x    8.7ms 1409x  218.5ms   56x   58.3ms  211x

How to read it:

  • Every tier beats recomputing, by 26x to over 1,000x, once each GPU fetches its own shard in parallel. Even SSD wins comfortably at these sizes.
  • The win grows with length because recompute has an S² term and the KV does not.
  • These are best cases. They ignore per-I/O latency, lookup time, contention with other traffic on the same links, and the cost of staging SSD reads through CPU memory. With one shared link instead of eight, divide the speed-ups by eight; small blocks on SSD can be dominated by per-request overhead. Measure your engine’s real load bandwidth.
  • The real limit is usually capacity and hit rate, not speed. A tier only helps if the block is still there when it is needed.

7. Performance implications#

  • TTFT on hits drops from a full prefill to a copy: vLLM reported 2x to 22x lower TTFT for Llama-3.1-8B on H100 depending on prompt size (project’s own benchmark).
  • Throughput is often the bigger gain: the GPU no longer spends compute rebuilding KV. vLLM reported up to 9x higher throughput at high CPU hit rates, and its September 2026 tiered benchmark (Qwen3.6-35B-A3B on 2 H100s, multi-turn) showed throughput falling sharply without offload once conversations no longer fit in HBM, with the SSD tier more than doubling it beyond that point (project’s own benchmarks).
  • Misses cost almost nothing when copy-out is asynchronous.
  • Host resources are not free. Pinned memory is taken from the OS, copies use PCIe bandwidth that the NIC may also need, and SSD tiers wear drives with writes.

8. Production implications#

  • Measure first: prefix-cache hit rate and eviction rate (17.f). If the pool is never full, offloading adds nothing.
  • Start with a CPU tier. One flag in vLLM; size it from host memory left after the OS and other processes, remembering it is pinned.
  • Add an SSD or shared tier for multi-turn chat and agents, where sessions return after minutes or hours.
  • Route sessions back to their cache (21.h). A CPU tier on replica A does not help a turn routed to replica B; that needs a shared store (14.l).
  • Check NUMA and PCIe placement: pinned buffers on the wrong socket halve copy bandwidth (3.c).
  • Treat offloaded KV as user data. It contains the content of prompts. Encrypt SSD and shared tiers, and keep tenants’ caches apart (23.i).

9. Common mistakes#

  1. Offloading the KV of running sequences and expecting decode to keep its speed.
  2. Assuming SSD is “slower than recomputing”. With per-GPU parallel paths and long prefixes it is usually much faster. Measure rather than assume.
  3. Using pageable instead of pinned host memory. Copies become slower and synchronous.
  4. Turning it on without measuring hit rate. A tier that is never hit just costs memory.
  5. Forgetting the router. A cache that requests are not routed back to is wasted.
  6. Ignoring hybrid layers. An offloader that does not understand sliding-window or linear- attention layers may disable the engine’s hybrid cache manager or store far more than needed.
  7. Leaving cached KV unencrypted on shared storage.

10. Hands-on exercise#

  1. Run kvtiers.go. Change gpus to 1 and the bandwidths to one shared link. At what prefix length does NVMe stop winning?
  2. Add a DeepSeek-style MLA model whose KV is about 70 KB per token in BF16 and is replicated, not split, across TP ranks (14.l). How does replication change the fetch times?
  3. Serve a model with vLLM, once without and once with --kv-offloading-size. Replay a multi-turn benchmark with more conversations than fit in HBM. Plot TTFT and throughput against the number of conversations.
  4. Measure host-to-device copy bandwidth with pinned and pageable buffers of 32 KB and 2 MB (cudaMemcpyAsync or torch.Tensor.to(non_blocking=True)). What does block size do?
  5. An agent’s 60k-token session pauses for 40 s while a tool runs. HBM is needed by other users in the meantime. Compare keeping it in HBM, offloading to CPU, and recomputing, in GPU-seconds.

11. Interview questions#

  1. What is KV offloading for, and why not for active sequences?
  2. Derive when fetching a prefix beats recomputing it. Why does the answer improve with length?
  3. Why does tensor parallelism make fetching faster?
  4. What does NVLink-C2C change about the CPU tier?
  5. How would you size a CPU tier and decide whether to add an SSD tier?
  6. Why is offloading often a throughput optimisation more than a latency one?
  7. What breaks if offloading is on but routing ignores where caches live?

12. Further reading#

Checked on 13 November 2026.

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in