Phase 05/Moving bytes between GPUs and nodes/Disaggregated prefill/decode and KV transfer
PHASE 05 · Moving bytes between GPUs and nodes

Disaggregated prefill/decode and KV transfer

0%
10 h6 subtopics3 lessons · 2 required
In plain English

Answering a prompt has two very different halves. First the model reads the whole prompt in one burst of heavy arithmetic (prefill), then it writes the answer one word at a time, each word needing only a little arithmetic but a lot of memory traffic (decode). Running both halves on the same GPU is like a bakery where the same person both kneads dough and serves customers at the counter. Every time a big kneading job arrives, the people waiting at the counter for their next slice stall. Disaggregation splits the bakery into a kitchen and a counter. Prefill GPUs do the kneading, decode GPUs do the serving, and the finished dough (the KV cache, the model's working memory for that prompt) is carried from kitchen to counter over a very fast link. The carrying is the hard part, and this topic is about when the split pays off and how the hand-off is engineered.

Why it matters

Prefill/decode disaggregation is how Mooncake, NVIDIA Dynamo, llm-d and several frontier labs now keep inter-token latency flat under bursty traffic. The job descriptions ask for exactly this (KV transfer over RDMA, NIXL, debugging stalled prefill and decode nodes), and the failure modes are new: a slow InfiniBand link now shows up as a TTFT regression.

Hiring signal

Together AI's inference reliability posting describes triaging InfiniBand issues when prefill and decode nodes stall exchanging KV cache over RDMA, and Baseten's model-performance role lists disaggregated serving as a custom benchmark suite you are expected to run and automate.

Skills this topic builds, with the number of the 46 analysed job postings that ask for each. Companies asking: Anthropic, Baseten, Cerebras, Cohere, CoreWeave, Crusoe, Cursor, Databricks, ElevenLabs, Fireworks, Liquid AI, Modal, nvidia, OpenAI, Perplexity, Poolside, Thinking Machines, Together AI, xAI.See all skills →

Learning objectives

  • Explain why colocated prefill and decode interfere and quantify the effect on inter-token latency with a simulator.
  • Compute KV cache bytes per prompt for a given model and the transfer time over NVLink, InfiniBand and Ethernet.
  • Compare the designs of DistServe, Splitwise and Mooncake and name the trade-off each makes.
  • Describe how NIXL, Mooncake Transfer Engine and LMCache move KV blocks and where they plug into vLLM.
  • Decide, for a stated workload and SLO pair, whether disaggregation beats a colocated fleet of the same GPU count.

Key concepts

Prefill/decode interference
A long prefill inserted into a continuous batch stretches every running request's next decode step; the root cause disaggregation removes.
Goodput
Requests per second that meet both the TTFT and the ITL SLO; the metric DistServe optimises instead of raw throughput.
KV transfer
Copying the prompt's key and value tensors from the prefill GPU to the decode GPU, ideally layer by layer while prefill is still running.
Prefill-to-decode ratio
How many GPUs go to each pool; set by the ratio of prefill compute time to decode time for the workload.
NIXL
NVIDIA Inference Xfer Library, a transfer API that abstracts NVLink, RDMA and storage backends for KV movement, used by Dynamo and vLLM.
Mooncake Transfer Engine
The RDMA-based KV cache transfer layer from Moonshot AI's Kimi serving system, with a distributed KV store on CPU memory and SSD.
LMCache
A KV cache offload and sharing layer for vLLM that stores reusable KV in CPU memory, disk or remote stores and supports P/D transfer.
Layer-wise streaming
Sending layer i's KV as soon as layer i finishes prefill so transfer overlaps compute rather than following it.
Conditional disaggregation
Routing only long prompts to the prefill pool while short prompts run colocated, as Dynamo does; avoids transfer cost when it does not pay.

Subtopics

  1. 1. Why colocation hurts

    Prefill is compute-bound, decode is bandwidth-bound; chunked prefill softens but cannot remove the stretch of decode steps under bursty prompt arrival.

  2. 2. Goodput and the two-SLO view

    Defining TTFT and ITL SLOs separately, measuring goodput per GPU, and why maximum throughput is the wrong target.

  3. 3. The papers

    DistServe (placement search per phase, goodput), Splitwise (phase splitting on heterogeneous GPUs, KV transfer over InfiniBand), Mooncake (KV-centric architecture, CPU and SSD KV store, early rejection).

  4. 4. KV transfer mechanics

    Bytes per token per model, NVLink versus RDMA versus TCP, GPUDirect, layer-wise overlap, and the latency floor of many small block transfers.

  5. 5. Transfer libraries and engine integration

    vLLM KV connector interface, NIXL connector, Mooncake connector, LMCache; how a request is tagged with a transfer target and how the decode side waits for arrival.

  6. 6. Operating a disaggregated fleet

    Prefill-to-decode ratio tuning, routing and rendezvous, failure of a transfer mid-request, fabric counters and timeouts, when to fall back to colocated.

Resources

paper
repo

Hands-on lessons

L1

Simulate colocated versus disaggregated serving and compute goodput

CPU · your Macnotebook150 minrequired

Goal · A discrete-event simulator that serves the same request trace on 4 colocated GPUs and on 2 prefill plus 2 decode GPUs, and reports goodput under a TTFT and an ITL SLO.

  1. 1Model one GPU step as prefill_time = 0.04 ms per prompt token (chunked to at most 2048 tokens per step) plus decode_time = 15 ms plus 0.3 ms per running sequence; a colocated step runs both, a decode-pool step runs only decode.
  2. 2Generate 4000 requests with Poisson arrivals, log-normal prompt lengths (median 1500, p99 8000) and output lengths uniform in 64 to 512.
  3. 3Implement the colocated engine with continuous batching and chunked prefill, and the disaggregated engine where prefill GPUs finish a prompt, add a transfer delay of prompt_tokens multiplied by 320 KB divided by 50 GB/s, then hand the request to the least-loaded decode GPU.
  4. 4Record TTFT and every inter-token interval per request; define SLOs TTFT under 500 ms and ITL p99 under 50 ms per request.
  5. 5Sweep arrival rate from 1 to 12 requests per second; compute goodput (requests meeting both SLOs per second) and total throughput for both layouts.
  6. 6Plot goodput versus arrival rate for both, and ITL p99 versus arrival rate; mark the first rate at which each layout violates each SLO.
  7. 7Change the split to 1 prefill plus 3 decode and 3 prefill plus 1 decode; record how the best ratio depends on the prompt length distribution.
Deliverable
pd_sim.ipynb with the goodput plot, the ITL plot and a table of best prefill-to-decode ratio for median prompt lengths 500, 1500 and 4000.
Check
In the colocated layout the ITL SLO is violated at a lower arrival rate than the TTFT SLO; at the highest arrival rate where disaggregated still meets both SLOs, its goodput is at least 20 percent higher than colocated goodput at that rate; the best ratio shifts toward more prefill GPUs as median prompt length grows.
L2

Hand a KV cache from a prefill process to a decode process

CPU · your Macscript120 minrequired

Goal · Two torch.distributed processes on gloo where rank 0 prefills GPT-2 small, sends past_key_values to rank 1, and rank 1 decodes 32 tokens that match single-process greedy generation; plus a KV transfer budget table for Llama-3-70B.

  1. 1Write kv_handoff.py; init gloo from torchrun environment; both ranks load gpt2 with the same weights.
  2. 2On rank 0 run the prompt with use_cache=True and extract the per-layer key and value tensors; record their total bytes and compare with 2 * 12 layers * 12 heads * 64 * 4 bytes per token.
  3. 3Send each layer's K and V with dist.isend as soon as it is available (simulate layer-wise streaming by sending inside a loop over layers) and time the full transfer.
  4. 4On rank 1 receive into preallocated tensors, build the past_key_values object, and greedy-decode 32 tokens starting from the last prompt token's logits (also sent by rank 0).
  5. 5On rank 1 compare the 32 token ids with a single-process model.generate(max_new_tokens=32, do_sample=False) on the same prompt.
  6. 6Write kv_budget.py that prints KV bytes per token and per 4096-token prompt for Llama-3-70B (80 layers, 8 KV heads, head_dim 128, bf16) and transfer time over 450 GB/s NVLink, 50 GB/s InfiniBand (400 Gb/s) and 12 GB/s Ethernet.
  7. 7Add the prefill time estimate for the same prompt on 8 H100s at 60 percent of 990 TFLOPS dense bf16 and compute transfer time as a fraction of prefill time per link.
Deliverable
kv_handoff.py, kv_budget.py and a markdown table of (link, transfer ms, fraction of prefill).
Check
The 32 decoded token ids are identical to the single-process reference; measured KV bytes per prompt token for GPT-2 small equal 73,728; kv_budget reports about 327,680 bytes per token and about 1.34 GB per 4096-token prompt for Llama-3-70B, with transfer time about 27 ms over 50 GB/s and about 112 ms over 12 GB/s.
L3

Run vLLM disaggregated prefill on two GPUs

Rented multi-GPUexperiment150 minoptional

Goal · Serve a small model with one vLLM prefill instance and one decode instance connected by a KV connector, and measure TTFT and ITL against a single colocated instance under the same load.

  1. 1Rent a 2-GPU instance (2x L4 or 2x A10G); install vLLM and the connector dependency the docs name for the version you installed (LMCache or NIXL).
  2. 2Follow the vLLM disaggregated prefilling example to start a prefill server on GPU 0 and a decode server on GPU 1 with the KV connector configured, plus the provided proxy that forwards each request to both.
  3. 3Run `vllm bench serve` against the proxy with 200 requests at concurrency 16 using a prompt length distribution with median 1500 tokens; record TTFT and ITL percentiles.
  4. 4Stop both servers and start one colocated server on GPU 0 only, then one with tensor_parallel_size 2; repeat the benchmark against each.
  5. 5Scrape the connector's transfer metrics or logs and compute the average KV transfer time per request; compare with your l2 kv_budget estimate for this model and PCIe bandwidth.
  6. 6Write a paragraph on which layout gave the best ITL p99 at this scale and why two GPUs is too few to see the full benefit.
Deliverable
A markdown report with three benchmark tables (disaggregated, single GPU, TP=2), the measured transfer time and the comparison with the budget estimate.
Check
Disaggregated ITL p99 is lower than the single-GPU colocated ITL p99 at concurrency 16; measured transfer time per request is within 3x of the kv_budget estimate for the measured link bandwidth.
Fallback
Extend the l1 simulator with the real step-time coefficients you measured in Phase 3 benchmarking for a small model on a T4 (prefill ms per token and decode ms per step), and rerun the goodput sweep; report the arrival rate at which each layout breaks each SLO with those measured coefficients.

Build your own

Build your own disaggregated P/D simulator

PythonCPU · your Mac~7 h

A discrete-event model of colocated versus prefill/decode-disaggregated serving with KV transfer cost, SLO goodput curves and a pool-sizing search, calibrated with step times you measured on a real GPU.

The real thing: github.com/LLMServe/DistServe ↗

How you know a stage passes

Write tests/test_pd.py first. Traces are generated from a seed so results are deterministic; tests check single-request latencies against the closed form, trace statistics against their parameters, and goodput-curve shapes. The CLI `pdsim run <config>` writes results/*.csv and plots, and the last stage compares simulated numbers with your Phase 3 T4 measurements. Run `pytest -q`.

Stages, in order. Each one leaves you with something that runs.0/7
  1. 01trace and step-time model
    Poisson arrivals with lognormal prompt and output lengths, and a step-time model where prefill ms = a + b * tokens and decode step ms = c + d * batch + e * KV tokens in the batch.
    test · A lone request gets TTFT equal to a + b * prompt within 1e-9; for 10,000 requests the mean prompt and output lengths are within 5 percent of the configured means.
  2. 02colocated continuous batching
    One engine per GPU runs iteration-level scheduling where new prefills (optionally chunked) join running decodes, with a KV memory cap on admission.
    test · One request alone reproduces s1 exactly; at high arrival rate ITL p99 exceeds 1.5x ITL p50 because of prefill interference, and enabling chunked prefill with 512-token chunks lowers ITL p99 by at least 20 percent.
  3. 03disaggregated pools with KV transfer
    A prefill pool and a decode pool; after prefill the KV (bytes per token * prompt) is transferred over a link with a bandwidth and a fixed latency before decode admission.
    test · TTFT distribution is unchanged when decode load doubles; a 2,048-token Llama-3-70B KV (327,680 bytes per token) over a 400 Gbps link costs 13.4 ms plus latency, asserted to 0.1 ms.
  4. 04SLO goodput curves
    Goodput counts requests per second that meet both a TTFT SLO and an ITL SLO; a sweep over arrival rate finds the knee for each layout by bisection.
    test · Each goodput curve rises monotonically then falls after the knee; the knee rates for 4 colocated GPUs and 2+2 disaggregated are printed and plotted to results/goodput.png.
  5. 05pool sizing search
    For N GPUs the simulator tries every prefill-to-decode split and reports the one maximising goodput under the SLOs.
    test · A long-prompt short-output trace chooses more prefill GPUs than decode GPUs, a short-prompt long-output trace chooses the reverse, and the table of goodput per split is in the README.
  6. 06layer-wise transfer overlap
    KV transfer is issued per layer as prefill finishes each layer, so only the last layer's transfer adds to TTFT.
    test · With overlap on, the TTFT penalty of disaggregation drops to one layer's worth of transfer time plus latency (asserted within 5 percent); the goodput knee moves right and the shift is recorded.
  7. 07calibrate against a real GPU
    Replace a, b, c, d and e with values fitted to the prefill and decode timings you recorded on the Colab T4 in Phase 3 and rerun the whole sweep.
    test · Simulated single-request TTFT and ITL for the small model match the T4 measurements within 15 percent; the README reports the arrival rate at which each layout breaks each SLO with the calibrated coefficients.

Knowledge check

QWhy does chunked prefill not fully solve prefill/decode interference?

Chunking caps how much prefill lands in one step, but every chunk still shares the step with decode, so each decode step is longer than a decode-only step; under bursty arrivals the ITL still rises.

QWhat is goodput and why does DistServe optimise it instead of throughput?

Goodput counts only requests that meet both the TTFT and the ITL SLO; maximising raw throughput encourages large batches that break the ITL SLO, so it rewards the wrong behaviour.

QRoughly how much KV cache does a 4096-token prompt produce for Llama-3-70B in bf16, and how long does it take to move over 400 Gb/s InfiniBand?

About 1.3 GB (327,680 bytes per token), which takes about 27 ms at 50 GB/s; small compared with the prefill time of such a prompt.

QWhat does layer-wise KV streaming buy you?

Transfer of layer i overlaps prefill of layers i+1 onward, so most of the transfer is hidden and the decode side can start almost as soon as prefill ends.

QName two new failure modes a disaggregated fleet has that a colocated one does not.

A transfer that stalls or times out mid-request because of a fabric fault, and a mis-sized prefill-to-decode ratio that leaves one pool idle while the other queues.

Completion

  • All 6 subtopics marked done
  • All 2 required lessons done
  • Lesson l1 simulator reproduces the ordering (ITL SLO breaks first when colocated) and the goodput gain.
  • Lesson l2 hand-off produces identical tokens and the KV budget numbers match.
  • Can explain in two minutes when disaggregation is worth it and what link bandwidth it needs.
Topic progress is derived; it reaches 100% when both checks above pass.Next recommended topic →