AI engineering and inferenceLoading progress…

Disaggregated prefill and decode

Compare kernel, parallelism and disaggregated-serving choices using memory, communication and latency constraints.

Splitting prefill from decode

Prefill is compute-heavy and bursty; decode is memory-bandwidth-bound and steady. Disaggregated serving runs them on separate machines, each tuned for its job, so a big prompt does not stall requests that are decoding. The price: after prefill the request's KV state (512 MiB in the reference example) must be sent to the decode machine, and that transfer adds to the new request's time to first token. Over 32 GiB/s it is 15.6 ms; over 2 GiB/s it is 250 ms.

link bandwidth (GiB/s)32prompt tokens2000
prefill + decode on one machineprefill machine → KV transfer → decode machine
new request waitsprefill onlyprefill + 15.63 ms transfer
running decodesstalled about 200 ms by the prefillnot stalled
512 MiB / 32 GiB/s = 15.625 ms the transfer is smaller than the stall it avoids; the new request itself always waits 15.6 ms longer

Separating phases lets each machine specialise, but the KV state has to cross a network, and that needs coordination and bandwidth. It is not a win for free on a slow link.

Slow the link and watch the benefit disappear.

Predict first. Is separating phases always beneficial regardless of network speed?

Chapter context

Scaling serving changes how work is placed and moved. An operation can be mathematically unchanged while its memory traffic changes dramatically. Device count alone does not describe the performance of the resulting system.

Chapter reference: math, worked example & code

This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.

Math and notation

A weight-traffic lower-bound estimate is

tstep≳Mread/BW.t_{step}\gtrsim M_{read}/BW.

This assumes the stated bytes really traverse the bottleneck bandwidth. KV transfer adds roughly bytes_to_move/network_bandwidth before protocol and synchronization overhead. Batching and caching can change the bytes per produced token.

Worked example

A fictional 14-GB dense weight scan across a sustained 700-GB/s memory path takes at least 14/700=0.02 seconds, giving a 50-step/s bandwidth ceiling under the one-scan-per-step assumption. Real execution includes other memory traffic and work. A 512-MiB KV transfer over 32 GiB/s has a payload-only lower bound of 1/64 second.

Reference code

The following example uses the Python standard library and does not call a remote service.

from math import isclose
assert isclose(14/700,.02)
assert isclose(1/(14/700),50)
transfer=(512*1024**2)/(32*1024**3)
assert isclose(transfer,1/64)

Python examples are provided for study and local execution; this page does not execute Python.

Common mistakes

Peak device bandwidth is not guaranteed sustained application bandwidth. Exact attention can be computed with different memory layouts. Additional GPUs can add communication bottlenecks.