Part III / Inference Engineering

Keep the factory full

Batching amortizes weight movement across requests. Scheduling decides who waits, who runs, and whether raw throughput becomes useful work inside an SLO.

14
Batch

Work executed together to reuse hardware effort.

Scheduler

Admission, ordering, token budget, and preemption policy.

Success

Quality-gated work completed within its SLO.

A bus, not a private car

Moving one passenger in a bus wastes most seats. Waiting forever to fill every seat gives terrible service. A serving system balances those costs continuously. Batching lets many sequences share a model-weight pass; queueing gives the scheduler candidates to combine; latency budgets limit how long it can wait.

Mental model

Batching buys efficiency by sharing fixed work. Scheduling spends latency and memory to assemble that sharing opportunity.

Static batching groups requests and runs them to completion together. Variable output lengths create padding or make short sequences wait for the longest. Dynamic batching waits briefly for arrivals, forms a batch, then runs it. Continuous batching, also called iteration-level scheduling, reconsiders the active set at token-step boundaries. Finished sequences leave and waiting work can enter without a global batch barrier.[source]

Interactive and background investigations share a fleet

Concrete example

A user waits on one live incident while an RL job generates eight attempts for thousands of seeded incidents. The interactive request needs a fast first token. The background job values tokens per GPU hour and can tolerate more queueing.

A single FIFO queue can let long background prefills block latency-sensitive work. Separate classes, priorities, token budgets, or reserved capacity can protect the interactive SLO. But strict priority can starve background work and lower utilization. A production scheduler needs a throughput target, explicit fairness, and defined overload behavior.

Requests consume different resources over time. Prefill consumes a chunk of compute; decode occupies one slot per token step and holds KV memory throughout. Token counts and available KV blocks therefore drive admission because request counts hide the size and phase of each request. A scheduler that admits too much can trigger memory pressure, preemption, or cache swapping that destroys latency.

Admission
Can this prompt and expected decode fit the current token and memory budget?
Ordering
FIFO, priority, shortest-job bias, deadline, fairness, or a workload-specific hybrid.
Preemption
Pause, recompute, or evict a sequence when higher-priority work needs capacity.
Chunking
Split long prefills so they do not monopolize a scheduling iteration.

Throughput has a frontier

As concurrency rises, the GPU reuses weights across more sequences and total tokens per second usually improves until another resource saturates. Per-request latency also rises from queueing and larger batches. The result is a latency-throughput Pareto frontier: at a given hardware and workload, improving one side eventually costs the other.

"Faster" must specify a point on that curve. An interactive coding assistant may operate at low concurrency for low inter-token latency. An offline rollout generator may choose a high-concurrency point for low cost per token. Comparing providers at one arbitrary concurrency can reverse at another point.

Tail latency matters because averages hide unlucky requests. Report p50, p90, p95, or p99 for queue time, TTFT, ITL, and completion by workload class. Long prompts and output lengths create heavy tails; retries and cold starts create multimodal distributions. Averages alone are insufficient for capacity planning.

Goodput adds the contract

Throughput counts work performed. Goodput counts work that meets the usefulness contract: a successful request completed within its service-level objective. DistServe explicitly frames serving around goodput under per-phase SLOs.[source] A system can increase raw tokens per second while admitting so much work that more users miss TTFT deadlines.

Quality can also enter the goodput definition. A speculative or quantized configuration that serves more tokens but fails task-quality gates does not create useful throughput. For agent rollouts, valid, fresh, gradeable trajectories per GPU hour may be a better numerator than tokens.

goodput = completed work satisfying correctness and SLO / wall-clock resource Define "work" and "satisfying" for the application before optimizing the ratio.

Chunked prefill reduces head-of-line blocking

A 100,000-token prompt can occupy a large prefill step and delay decode tokens for many active users. Chunked prefill splits that work across iterations so the scheduler can interleave decode. Sarathi-Serve develops this idea as part of stall-free scheduling.[source] The tradeoff includes extra scheduling complexity and potentially less efficient individual prefill chunks.

Other policies separate prefill and decode onto different workers, which chapter 18 covers. The underlying principle is the same: workloads with different shapes interfere when forced through one undifferentiated queue.

Misconception: maximum batch size is capacity

A request count ignores prompt length, output length, KV allocation, phase, priority, and SLO. Capacity is a workload distribution under a service contract, not one batch-size integer.

Benchmark the scheduler as a system

Replay an arrival process with realistic prompt and output distributions, prefix reuse, cancellation, priorities, and tool gaps. Sweep offered load until SLOs fail. Report the highest sustainable goodput and the latency distribution at that point. Keep model, precision, runtime settings, hardware, and scheduler policy fixed when comparing one variable.

For RL rollouts, include environment time. If a rollout worker blocks a GPU while a tool sandbox sleeps, utilization may look poor even though the model runtime is fast. Decouple model inference from environment actors or schedule other sequences during external waits.

References