advanced28 min studyLesson 711 in Engineering

Name the computation and traffic behind each scheduling unit

Separate prompt processing, autoregressive decode, weight traffic, KV reads, and transfer overhead before using token counts as a scheduling cost.

On this page

What you’ll understand

  • Distinguish prefill work from one decode iteration under a declared model.
  • Use FLOP and byte counts to form a scoped lower-bound estimate.
  • Explain why equal token counts need not imply equal service cost.

A scheduler sees tokens, requests, and available memory, but those units do not all consume the same resources. Prefill processes prompt positions together, while ordinary autoregressive decode adds one next token per active sequence per iteration. Batch size, context length, architecture, cache reuse, and kernels change the cost of each phase. Build a named model before optimizing a token budget. The quantities in this module's numerical examples are fictional or synthetic; they illustrate accounting rather than measured performance for a particular accelerator.

Separate useful operations from memory traffic

For a dense decoder's linear layers, a rough weight-multiply term often scales with parameter count times processed tokens. Attention adds work depending on prompt or existing context length, and the exact factor depends on which projections and arithmetic are counted. Name the included FLOPs rather than calling a single parameter-based approximation the complete model. Speculative decoding, sparse experts, sliding windows, quantization, and multimodal inputs can require different terms. The chosen scheduler cost should match the served architecture and execution path.

Decode can reuse loaded weights across several active sequences, while each sequence also reads its relevant KV history. Increasing batch size can amortize some weight traffic without making every added sequence free. Longer contexts can increase KV reads and retained state, changing both latency and feasible batch size. Prefill is often more compute-intensive than small-batch decode, as the original Sarathi and DistServe analyses discuss, but neither phase is universally tied to one bottleneck on every configuration.

tresource≥max⁡ ⁣(FP,DB)t_{\rm resource}\geq\max\!\left(\frac{F}{P},\frac{D}{B}\right)
F is the declared operation count in FLOP, P a stated FLOP/s ceiling, D bytes transferred at a specified memory boundary, and B its bytes/s ceiling. The result is seconds. This resource lower bound omits launch, scheduling, synchronization, communication, and imperfect utilization; ceilings are not achieved-rate measurements.↔ Scroll wide equations horizontally.

A phase boundary can add a new resource term

If prefill and decode run on different devices, the relevant KV state must become available to the decode side under the design's transfer protocol. That can reduce interference between phases but adds bandwidth, placement, coordination, and failure considerations. A model that counts only GPU compute can miss a transfer that dominates first-token delay. Conversely, shared devices avoid that transfer while coupling their scheduling and memory budgets. DistServe studies one such design space rather than proving one topology optimal for all workloads.

Distinguish work estimates from latency objectives. Time to first token includes relevant waiting and transport boundaries, not simply prefill kernel time. Inter-token gaps can include other requests' prefill chunks, scheduling, and delivery stalls. Record batch composition, context lengths, cache-hit policy, and the measured boundary when calibrating a cost model. An average per-token coefficient fitted to one workload should be checked again when the workload shifts or the scheduler changes the batch distribution.

ttransfer≥KBlinkt_{\rm transfer}\geq\frac{K}{B_{\rm link}}
K is bytes of state actually transferred and B_link a stated effective-link ceiling in bytes/s, giving seconds. Sharing, compression, protocol overhead, overlap, and placement change the relevant quantities. This bound does not by itself state whether transfer lies on the request's critical path.↔ Scroll wide equations horizontally.

Use a small roofline to challenge a bottleneck story

Choose controlled prompt and output-length classes, vary batch size, and compare resource counters with synchronized iteration timings. Keep output semantics and cache state comparable. A growing token count with flat iteration time can indicate amortization within a range, but not unlimited capacity. A change in latency can also reflect admission or queueing instead of a slower kernel. The scheduler needs the cost distribution and relevant tails under its operating conditions, not one isolated peak tokens-per-second result.

The roofline lab isolates a synthetic resource ceiling. Reset, set both intensity I=4 FLOP/byte and bandwidth B=80 GB/s, predict 320 GFLOP/s, then Play or Step. Reset and set both I=16,B=80 for the capped 1,000 GFLOP/s comparison. Playback traces the selected roof without running a kernel. The instrument has no prompt length, KV cache, batching, network transfer, or request latency; it illustrates why a named compute/bytes assumption is necessary before declaring a phase compute-bound or memory-bound.

Compare two declared resource budgets

A fictional prefill batch has F=20×10¹² FLOP and D=20×10⁹ bytes; a decode batch has F=2×10¹² FLOP and D=40×10⁹ bytes. Assume ceilings P=100×10¹² FLOP/s and B=1×10¹² bytes/s, with no claim that the bounds are achieved.

  1. Prefill's compute term is 20/100=0.2 s and memory term is 20×10⁹/10¹²=0.02 s. The resource lower bound is the larger value, 0.2 s.

  2. Decode's compute term is 2/100=0.02 s and memory term 40×10⁹/10¹²=0.04 s. Its resource lower bound is 0.04 s under these stated quantities.

  3. Compare the named terms rather than token totals: this hypothetical prefill bound is compute-dominated and decode bound memory-dominated. Actual iteration times can exceed both because the model excludes other costs and imperfect utilization.

The result

The bounds are 200 ms and 40 ms for these fictional batches. They are neither universal phase classifications nor predictions of measured p99 latency.

Explore the model

Interactive lab

Interactive lab · roofline

Inspect the stated resource ceiling

Fresh Reset → set both I=4,B=80 predicts 320 GFLOP/s; Reset → set both I=16,B=80 predicts the 1,000 GFLOP/s cap. Play or Step traces a synthetic roof, with no inference engine, KV state, transfer, queueing, or measured latency.

Inspect the stated resource ceilingSynthetic roofline ceiling min(1000, B·I), in GFLOP/s, with B in decimal GB/s and I in FLOP/byte. Playback traces the roof without changing the selected kernel. This upper-bound model is not a measured throughput prediction, hardware comparison or price model. Current readings: Attainable ceiling: 640 GFLOP/s; Ridge intensity: 12.5 FLOP/byte; Ceiling regime: Memory-bound ceiling. All parameters are adjustable with the labeled controls below.Hypothetical roofline upper bound: 640 GFLOP per second at operational intensity 8 FLOP per byte and bandwidth 80 gigabytes per second.0.1110641101001000Operational intensity · FLOP/byte · log scaleCeiling · GFLOP/s · log scalePeak: 1000
Attainable ceiling / kernelBandwidth roof / traceCompute ceiling
Attainable ceiling
640 GFLOP/s
Ridge intensity
12.5 FLOP/byte
Ceiling regime
Memory-bound ceiling
t = 0 s

Synthetic roofline ceiling min(1000, B·I), in GFLOP/s, with B in decimal GB/s and I in FLOP/byte. Playback traces the roof without changing the selected kernel. This upper-bound model is not a measured throughput prediction, hardware comparison or price model. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA compute/bytes model needs named quantities and a clear boundary between a ceiling and an achieved rate.

Check your understanding

Two batches process the same number of tokens but have different context lengths and phase composition. What follows?

Try it yourself

A disaggregated path must transfer 2 GiB of KV state over a hypothetical effective 16 GiB/s link with no compression. What transfer lower bound follows, and may it simply be added to every request's latency?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Use matching binary units, then ask whether the whole transfer is actually on the request's critical path or overlaps other work.

Compare with the solution

The transfer bound is 2/16=0.125 s, or 125 ms, under the stated link ceiling. It becomes an additive latency term only if the relevant transfer is serialized on that request's critical path with the other counted work. Overlap, shared prefixes, transfer granularity, and protocol overhead can change the accounting. A bandwidth ratio alone does not identify the end-to-end critical path or an observed percentile.

Take it with you

  • Prefill and decode need cost models that distinguish operations, bytes, context, and batch composition.
  • Phase disaggregation can trade interference for state-transfer and coordination costs.
  • Resource bounds and isolated throughput do not determine measured request-tail latency.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.