Before you start: words you need#
| Word | Plain meaning |
|---|---|
| KV connector | A plug-in inside vLLM that can move KV cache blocks out of the engine and back in. |
| Prefill / decode | Reading the prompt (one big parallel pass) versus generating output tokens one step at a time (12.c). |
| Disaggregation | Running prefill and decode on different machines (14.j). |
| Offloading | Copying KV blocks to a bigger, slower tier (CPU memory, disk) so they survive GPU eviction (14.k). |
| RDMA | Remote direct memory access: one machine’s network card writes into another’s memory without either CPU copying the data (9.c). |
| NIXL | NVIDIA Inference Xfer Library: a transfer library that moves memory between GPUs and machines over RDMA, NVLink or storage. |
| Proxy | A small router in front of vLLM that sends each request first to a prefill instance, then to a decode instance. |
| Handshake | The exchange at connection time where two instances check they are compatible. |
1. What is it?#
Inside a single engine the KV cache lives and dies on one GPU. A KV connector is the extension point that lets cached blocks leave: to CPU memory or disk when the GPU is full, to another machine that will continue the request, or to a shared store every replica can read.
Three deployment patterns are built on it:
- Offloading makes the prefix cache larger than the GPU.
- Prefill/decode disaggregation puts the two halves of a request on different instances, so reading prompts never disturbs streaming.
- Shared caches let a prefix computed on one replica be used on another.
All three rest on the same hooks in the scheduler and worker, and on one question: is moving these bytes faster than recomputing them? The ideas are Module 14’s (14.j, 14.k, 14.l); this lesson is vLLM’s implementation. Facts checked on 12 November 2026 against vLLM v0.32.0.
flowchart LR
C[":i-users: Client"] --> PX[":i-route: <b>Proxy / router</b>"]
PX -->|"1. prompt, max_tokens=1"| PRE
PX -->|"3. request + kv_transfer_params"| DEC
subgraph PRE["Prefill instance"]
direction TB
P1[":nvidia: <b>vLLM</b><br/><small>large token budget</small>"]
end
subgraph DEC["Decode instance"]
direction TB
D1[":nvidia: <b>vLLM</b><br/><small>decode-only CUDA graphs</small>"]
end
P1 ==>|"2. KV blocks<br/>RDMA via NIXL"| D1
D1 -->|"4. streamed tokens"| C
P1 -.-> ST[(":i-database: <b>Offload tiers</b><br/><small>CPU RAM, disk,<br/>shared store</small>")]
D1 -.-> ST
class C neutral
class PX queue
class P1,D1 compute
class ST memory2. Why does it exist?#
Three pressures from earlier lessons:
- The GPU pool is small. A prefix evicted from the GPU (17.f) is gone, and the next request that needed it pays full prefill again.
- Prefills hurt decoders. In a shared engine every prefill chunk lengthens the step for every streaming request (17.b). Chunked prefill bounds the damage; it does not remove it.
- Replicas do not share caches. With N replicas, a conversation’s cached history is useful only on the one replica that holds it.
A connector addresses all three with one mechanism: blocks that can be loaded from somewhere other than this GPU’s own computation.
3. Simple analogy#
A library with a small reading room (the GPU).
- Offloading is the stack room downstairs: books that do not fit upstairs are kept, not thrown away, and fetched when someone asks.
- Disaggregation is a separate copying room. One team copies out the long reference pages (prefill) and hands the folder to the reading room, where readers work undisturbed (decode).
- A shared cache is an inter-library loan: another branch already has the book, so you borrow it instead of writing it again.
Each is worth it only if fetching the book is quicker than rewriting it.
4. Tiny example: one disaggregated request#
1. proxy → prefill instance: prompt (8,000 tokens), max_tokens=1,
kv_transfer_params = {"do_remote_decode": true}
2. prefill computes 8,000 tokens of KV; returns kv_transfer_params naming its engine,
host, port and block IDs; keeps the blocks pinned until they are read
3. proxy → decode instance: same request, with the returned kv_transfer_params
4. decode scheduler asks the connector: "8,000 tokens available remotely, load async"
→ allocates 500 blocks (16 tokens each), request waits in WAITING_FOR_REMOTE_KVS
5. NIXL reads the blocks over RDMA (pull mode); prefill is told it may free them
6. decode schedules the request as if it had an 8,000-token cache hit and streams tokens5. Technical explanation#
The connector interface#
A connector subclasses KVConnectorBase_V1
(vllm/distributed/kv_transfer/kv_connector/v1/base.py). It has two halves, one in each process
that touches the cache.
Scheduler side, in the engine core:
| Hook | Called | Purpose |
|---|---|---|
get_num_new_matched_tokens(request, num_computed_tokens) | When a waiting request is considered | “Beyond the local cache hit, how many more tokens can you supply?” Also says whether loading is asynchronous. |
update_state_after_alloc(request, blocks, num_external_tokens) | After blocks are allocated | Tells the connector which blocks will receive the loaded data |
build_connector_meta(scheduler_output) | End of schedule() | Packs this step’s load and save instructions for the workers |
request_finished(request, block_ids) | When a request ends | May ask the scheduler to delay freeing the blocks until a transfer completes |
Worker side, in the model runner:
| Hook | Called | Purpose |
|---|---|---|
register_kv_caches(kv_caches) | Startup | Hands the connector the real cache tensors |
start_load_kv(...), wait_for_layer_load(layer) | Before and during the forward pass | Copy external KV into the allocated blocks, layer by layer if it can |
save_kv_layer(...), wait_for_save() | During and after the forward pass | Copy newly computed KV out |
get_finished(...), get_block_ids_with_load_errors() | Each step | Report finished transfers, and blocks whose load failed |
You have met every scheduler call site: the waiting-request lookup asks the local prefix cache
first and then the connector (17.a), and the external tokens are the ext_comp segment of
allocate_slots (17.g).
A connector is chosen with --kv-transfer-config, a JSON object naming the connector, its role
(kv_producer, kv_consumer or kv_both) and its own settings in
kv_connector_extra_config. An out-of-tree connector adds kv_connector_module_path (19.f).
Asynchronous loads and the waiting state#
Fetching a gigabyte of KV from another machine takes time, and the engine must not stall for it.
When the connector answers “I can supply these tokens, asynchronously”, the scheduler
(vllm/v1/core/sched/scheduler.py) does this:
if load_kv_async:
# If loading async, allocate memory and put request
# into the WAITING_FOR_REMOTE_KV state.
request.status = RequestStatus.WAITING_FOR_REMOTE_KVS
# Set num_computed_tokens even though KVs are not yet loaded.
...
request.num_computed_tokens = num_computed_tokens
self._inflight_prefills.add(request)
self._set_kv_fetch_stage(request, KV_FETCH_IN_PROGRESS)
skip_request(request_queue)
continueBlocks are allocated at once, so the destination exists. The request is set aside in the
kv_holding_waiting queue while other requests run. When the worker reports the transfer done,
the request becomes schedulable with num_computed_tokens already covering the loaded prefix,
and proceeds as if it had a very large cache hit.
Three protections surround this, all in the source:
- Stricter admission. An in-flight load holds its blocks, makes no progress and cannot be preempted, so it is admitted only if it fits in free blocks minus what other in-flight loads have reserved, “to avoid deadlock and predictable preemptions.”
- Failures fall back to computing. Failed blocks are reported by the worker, the request’s
num_computed_tokensis rolled back to the last good position, and the rest is recomputed locally. A failure that cannot be recovered finishes the request withFinishReason.ERROR, which the API layer always turns into HTTP 500 so a client can retry. - Blocks are not cached until loaded.
delay_cache_blockskeeps partially loaded blocks out of the local prefix cache.
The engine loop’s one-millisecond sleep (16.g) exists for this case: requests are present, none can run, and the transfer threads need the Python interpreter.
Pattern 1: offloading#
When a block is evicted from the GPU, its contents are lost. With offloading, completed blocks are also copied to a larger tier with asynchronous DMA, and a later request whose prefix has left the GPU can have it copied back.
vllm serve <model> --kv-offloading-size 64 # GiB of host memory, summed across TP ranks--kv-offloading-backend chooses native (vLLM’s own, the default) or lmcache. For finer
control the same thing is the OffloadingConnector with two specs: CPUOffloadingSpec (pinned
host memory, the default) and TieringOffloadingSpec (CPU plus secondary tiers such as a
filesystem; only the CPU tier talks to the GPU). It runs on CUDA, ROCm and XPU. A request can cap
what it loads with max_load_tokens in kv_transfer_params; zero disables external loading for
that request.
Pattern 2: prefill/decode disaggregation#
Run two pools of vLLM instances: prefill instances only read prompts; decode instances only generate. The documentation gives two reasons and one warning:
- Tuning time-to-first-token (TTFT) and inter-token-latency (ITL) separately. …
- Controlling tail ITL. Without disaggregated prefilling, vLLM may insert some prefill jobs during the decoding of one request. This results in higher tail latency. …
Disaggregated prefill DOES NOT improve throughput.
It also notes that chunked prefill “can achieve the same goal, but in practice it’s hard to figure out the correct chunk size value.” The feature is still labelled experimental.
The NixlConnector is the usual transport. By default it is pull-based: the decode instance
reads blocks from the prefill instance with NIXL READ. NixlPushConnector is the push
alternative, in which the prefill instance writes straight into memory the decode instance has
pre-allocated. Push and pull use incompatible protocols and must never be paired.
Each pool is configured for its job:
| Prefill pool | Decode pool | |
|---|---|---|
| Token budget | Large | Small; no long prefills arrive |
max_num_seqs | Small | Large |
| CUDA graphs | Piecewise | FULL_DECODE_ONLY, saving the memory of piecewise graphs |
| MoE all-to-all (19.a) | deepep_high_throughput | deepep_low_latency |
| Parallelism | Whatever makes prefill fastest | Whatever gives the lowest step time |
What must match. The NIXL connector checks a compatibility hash in its handshake: vLLM and connector version, model (architecture, dtype, KV heads, head size, layers), attention backend, KV cache dtype, the speculative method, and push versus pull. Tensor-parallel size and block size may differ between prefill and decode, with restrictions (hybrid Mamba models need equal TP, and the hybrid KV cache manager needs equal block sizes); see the compatibility matrix.
Blocks must outlive the send. The prefill side cannot free a request’s blocks until the
decode side has read them. That is request_finished’s “delay free” return value, plus a lease
that expires if the decoder never comes (vllm:nixl_num_kv_expired_reqs counts those).
Pattern 3: a cache shared between replicas#
Move the request to the cache. Each engine can publish KV events (--kv-events-config):
BlockStored, BlockRemoved and AllBlocksCleared, with block hashes. A router listening to
them knows which replica holds which prefix and routes accordingly (21.h). To compute the same
hashes outside vLLM, use --prefix-caching-hash-algo sha256_cbor: the default sha256 hashes
Python pickle output, which other languages cannot reproduce. With a cryptographic hash and no
PYTHONHASHSEED, vLLM uses a fixed seed, so every replica agrees.
Move the cache to the request. A connector backed by a shared store (LMCache, Mooncake Store, FlexKV, 3FS) lets any replica fetch blocks another computed.
The first costs nothing per request but needs a smart router. The second works with any router but pays a transfer on every cross-replica hit.
The connectors that ship in v0.32.0#
| Connector | Transport or store | Typical use |
|---|---|---|
OffloadingConnector, SimpleCPUOffloadConnector | Host memory, optional further tiers | Extending the prefix cache |
NixlConnector (NixlPullConnector), NixlPushConnector | NIXL over UCX, GDS and other backends | Prefill/decode disaggregation |
LMCacheConnectorV1, LMCacheMPConnector | LMCache, in-process or a separate LMCache server | Shared and offloaded caches |
MooncakeConnector, MooncakeStoreConnector | Mooncake transfer engine; Mooncake store | Disaggregation; shared store |
MoRIIOConnector | AMD MoRI-IO | Disaggregation on ROCm |
FlexKVConnectorV1, HF3FSKVConnector | FlexKV; DeepSeek’s 3FS file system | Large multi-level caches |
MultiConnector | Several of the above, in order | NIXL for hand-off plus a store for reuse |
DecodeBenchConnector | Fills the cache with random values | Benchmarking a decode instance alone |
ExampleConnector | Files on shared storage | Learning and tests only |
6. Under the hood: is moving KV worth it?#
A connector helps only if moving the KV is faster than recomputing it.
KV bytes = tokens × bytes per token 8,000 × 128 KiB ≈ 1 GiB for an 8B model
transfer = bytes ÷ link bandwidth
recompute = tokens ÷ prefill speed// movekv.go — when does moving KV beat recomputing it?
package main
import (
"fmt"
"strings"
)
func main() {
type model struct {
name string
kvKiBPerTok float64 // 16-bit cache, whole model
prefillTokPS float64 // prompt tokens per second on the prefill side (assumed)
}
type link struct {
name string
gbitPS float64
}
models := []model{
{"1.5B (Qwen2.5 shape)", 28, 60000},
{"8B (Llama-3 shape)", 128, 20000},
{"70B (tp 4)", 320, 6000},
}
links := []link{
{"10 GbE", 10},
{"100 GbE", 100},
{"400 Gb RDMA", 400}, // also about a PCIe Gen5 x16 copy to host RAM (~50 GB/s)
}
const promptTokens = 8000
for _, kvBits := range []float64{16, 8} {
fmt.Printf("%d-token prompt, %d-bit KV cache\n", promptTokens, int(kvBits))
fmt.Printf(" %-21s %8s %9s", "model", "KV size", "recompute")
for _, l := range links {
fmt.Printf(" %21s", l.name)
}
fmt.Println()
for _, m := range models {
bytes := promptTokens * m.kvKiBPerTok * 1024 * kvBits / 16
recompute := promptTokens / m.prefillTokPS
row := fmt.Sprintf(" %-21s %4.2f GiB %7.2f s", m.name, bytes/(1<<30), recompute)
for _, l := range links {
transfer := bytes * 8 / (l.gbitPS * 1e9)
verdict := "transfer"
if transfer > recompute {
verdict = "recompute"
}
row += fmt.Sprintf(" %8.3f s %-10s", transfer, verdict)
}
fmt.Println(strings.TrimRight(row, " "))
}
fmt.Println()
}
}Output:
8000-token prompt, 16-bit KV cache
model KV size recompute 10 GbE 100 GbE 400 Gb RDMA
1.5B (Qwen2.5 shape) 0.21 GiB 0.13 s 0.184 s recompute 0.018 s transfer 0.005 s transfer
8B (Llama-3 shape) 0.98 GiB 0.40 s 0.839 s recompute 0.084 s transfer 0.021 s transfer
70B (tp 4) 2.44 GiB 1.33 s 2.097 s recompute 0.210 s transfer 0.052 s transfer
8000-token prompt, 8-bit KV cache
model KV size recompute 10 GbE 100 GbE 400 Gb RDMA
1.5B (Qwen2.5 shape) 0.11 GiB 0.13 s 0.092 s transfer 0.009 s transfer 0.002 s transfer
8B (Llama-3 shape) 0.49 GiB 0.40 s 0.419 s recompute 0.042 s transfer 0.010 s transfer
70B (tp 4) 1.22 GiB 1.33 s 1.049 s transfer 0.105 s transfer 0.026 s transferHow to read it:
- The link decides. On 10-gigabit Ethernet with a 16-bit cache, recomputing wins for every model here. On 100 GbE or RDMA, transferring wins by a factor of 5 to 25.
- An 8-bit cache halves every transfer, enough to flip two of the 10 GbE rows.
- Offloading to host memory is nearly always worth it. A PCIe Gen5 copy runs at about the speed of the 400 Gb column.
- The program ignores latency per transfer, the time to set up RDMA, and contention. Real systems also overlap transfer with compute layer by layer, which helps the transfer side.
7. Performance implications#
- Disaggregation buys tail latency, not throughput. Decode instances never run a long prefill, so p99 inter-token latency falls. Total tokens per GPU usually do not rise.
- The pool ratio matters. Too few prefill instances and time to first token climbs; too few decode instances and requests wait for blocks. The ratio depends on your prompt-to-output ratio and must be re-tuned when traffic changes.
- Asynchronous loads cost cache space while in flight. Blocks are allocated before the data
arrives. Watch
vllm:num_requests_kv_fetch_by_stage. - A failed load becomes a recompute, which shows up as a sudden slow prefill on the decode
side. Watch
vllm:nixl_num_failed_transfers.
8. Production implications#
- A second fleet and a proxy. Disaggregation needs a router that understands the two-step protocol: vLLM ships example proxies, and llm-d and NVIDIA Dynamo provide production ones (21.j).
- Network and drivers. RDMA needs working InfiniBand or RoCE, gdrcopy, UCX and NIXL on both
sides; v0.32.0 pins NIXL 1.5.0. Kubernetes pods often need
hostNetworkand privileged access. - Version lock-step. The handshake includes the vLLM version, so prefill and decode pools upgrade together.
- Security. Transfer ports carry raw cache contents. Keep them on a private network; v0.32.0
added limits on peer sessions for the P2P ZMQ transport (
VLLM_P2P_MAX_PEERSand timeouts) after a socket-exhaustion advisory.
9. Common mistakes#
- Expecting disaggregation to raise throughput. The documentation says plainly it does not.
- Disaggregating over a slow network. On 10 GbE, recomputing is often faster.
- Pairing a push connector with a pull connector, or mismatched KV cache dtypes. The handshake
rejects it; do not disable
enforce_handshake_compatto “fix” it. - Hashing with the default
sha256and expecting an external router to match it. Usesha256_cbor. - Forgetting that offloading space is summed across TP ranks.
--kv-offloading-size 64with TP 4 is 16 GiB per rank. - Sizing the decode pool’s cache for prompts only. Decode holds prompt plus output for every running request.
10. Hands-on exercise#
- Run
movekv.go. ChangepromptTokensto 100,000. Which cells flip, and why does this simple model not depend on prompt length? What real effect would make it depend on length? (Hint: attention cost in prefill grows with length squared.) - Add a “local NVMe” link at 50 Gbit/s. For which models is a disk tier worth having?
- Start a server with
--kv-offloading-size 8, fill the GPU cache with many distinct long prompts, then resend the first one. Compare its time to first token with and without offloading, and readvllm:prompt_tokens_by_source. - Start one instance with
--kv-transfer-config '{"kv_connector":"DecodeBenchConnector","kv_role":"kv_both"}'and benchmark decode on its own.
11. Interview questions#
- Which two processes contain a KV connector’s code, and what does each half do?
- What happens, step by step, when the decode side’s KV load fails half-way?
- Why does prefill/decode disaggregation not increase throughput, and when is it still worth it?
- What must match between a prefill and a decode instance, and what may differ?
- Two ways to make replicas share prefix caches; give the cost of each.
- Why is an in-flight asynchronous load admitted more strictly than a normal request?
12. Further reading#
Checked on 12 November 2026 against vLLM v0.32.0.
- Disaggregated prefilling (experimental)
- KV offloading usage guide
- NixlConnector usage guide and compatibility matrix
- NIXL push-mode KV transfer (design)
vllm/distributed/kv_transfer/kv_connector/v1/base.py— the connector interfacevllm/distributed/kv_transfer/kv_connector/factory.py— every registered connectorvllm/v1/core/sched/scheduler.py—WAITING_FOR_REMOTE_KVS, failed loads, deferred freesvllm/distributed/kv_events.py— the KV event types- NIXL