Topic: inference-and-serving

Reading: 34 min, plus 3 in closed details. The map of LLM serving: one request's prefill and decode, why decode is slow, every lever on one screen (batching, the KV cache, scheduling, quantisation, speculation, parallelism, routing, scaling) with the child page that owns it, the engines compared, and what a deployment costs. Tools that span the children: a serving simulator checked against vLLM's scheduler, an engine bench measured on an Apple M1 Pro, and a capacity planner calibrated on MLPerf. Data as of October 2026.

0. The map

The idea in one sentence. Every decode step reads all the model's weights to produce one token per user, so serving is the craft of putting as many users as possible on each read of the weights, while their KV caches fit in the memory left over and each user's latency stays inside its promise.

The running example. A chat assistant built on Llama 3.1 70B (70.6 billion parameters, 80 layers; config.json, an open mirror of Meta's gated repository), stored in FP8 (one byte per weight) on NVIDIA H200 GPUs (141 GB of memory at 4.8 TB/s, NVIDIA). Every request carries a 2,000-token prompt whose first 1,000 tokens are the same system prompt, and gets a 300-token answer. It is the deployment the Capacity planner opens with, so every number here can be checked there, and the children reuse it. A token is the unit the model reads and writes, about three quarters of an English word on average.

Fig. 1 is the page: one request's path through a serving fleet, each part lit where it acts, with the child page that owns it.

  1. The map: one request, one fleet. Users and agents send prompts and get a stream of tokens back. A router picks one of several replicas (copies of the model); inside the replica a serving engine (vLLM, SGLang, TensorRT-LLM, llama.cpp, MLX: the same five parts, built differently, compared in section 7) turns the prompt into tokens on one GPU or many; a laptop beside them runs the same loop for one user. Drawn: three H200 replicas and one laptop illustrative layout; the numbers are the running example's. Each step lights one part and links the child page whose own figure teaches it.
  2. Router: send the request to its cache. Pick a replica for each request: round-robin ignores the cache, while a prefix-aware router sends a returning conversation back to the replica that holds its prefix, weighed against load; an autoscaler adds replicas when queues grow, before users wait. On eight real requests over three replicas, round-robin computed 13,000 prompt tokens and the prefix-following rules as few as 5,804 (section 10). Owner: LLM serving in production, whose Fig. 2 steps those requests (sections 2 to 4); Distributed and disaggregated serving's Fig. 2 scores workers by cache against load, and its section 8 covers the serving layers above engines (Dynamo, llm-d).
  3. Scheduler and KV cache manager: who runs this step, and where their memory goes. On one H200 the 72.66 GB of FP8 weights land first; about 54 GB is left for the KV cache, cut into blocks, room for 141 conversations (bars to scale). Every step the scheduler builds the batch: who decodes, which prompt chunks join, who waits or is preempted; the cache manager hands out blocks, keeps shared prefixes and offloads cold ones. Owner: Batching, KV cache and scheduling, whose Fig. 1 builds one engine step and Fig. 3 lays block tables over one pool; the real code is vLLM's Fig. 2 (one engine step, recorded) and SGLang's Fig. 2 (a radix tree). Sections 4 and 5.
  4. Model runner, prefill: the whole prompt in one pass. All 2,000 prompt tokens go through the 80 layers together (drawn as 8 glass plates of 10 layers) and write their keys and values into the pool, 625 MiB. One read of the weights serves 2,000 tokens, 3,956 operations per byte, so the arithmetic sets the pace (compute-bound): 0.42 s, the time to first token. This page owns it: sections 1 and 2, Figs. 2 and 3.
  5. Model runner, decode: one token per user per step. Each step feeds only the newest token of every running request; the weights are read once for all of them, plus each request's own cache (bandwidth-bound). Alone: 21.6 ms a step, 46 tokens a second, 2 operations per byte; 141 users on the same read get 2,982 tokens a second between them (section 5). One engine step with prefill chunks and decodes mixed is Batching's Fig. 1; eight requests in four seats, static against continuous batching, its Fig. 2.
  6. Sampler: 128,256 scores become one token. The last layer gives a score for every token in Llama 3.1's vocabulary; temperature, top-p, penalties and grammar masks pick one, which is streamed to the user and fed back as the next step's input. Owner: Sampling and decoding, whose Fig. 1 runs one real distribution through the decoder and Fig. 3 draws a grammar mask.
  7. Drafter (optional): several tokens per read. Decode leaves the arithmetic idle, so a cheap draft guesses k tokens and the model checks them all in one pass, keeping the run it agrees with; the output stays exactly the model's. It pays while checking k tokens costs little more than one: on the laptop a Qwen3-4B pass over 4 tokens cost 2.2 times a pass over 1 measured here (section 8). Owner: Speculative decoding, whose Fig. 1 runs one round on real tokens and Fig. 3 shows the gain fade as the batch grows.
  8. One GPU or many: replicas, slices and two pools. One copy serves 2.11 requests a second inside the running example's promises, so 20 at peak need 10 H200s (section 6). When one GPU's memory or speed is not enough, the model is sliced (tensor, pipeline or expert parallelism), or prefill and decode move to separate pools and the finished cache crosses between them: 625 MiB for a 2,000-token prompt, about 13 ms over a 400 Gb/s link (section 9). Owner: Distributed and disaggregated serving, whose Fig. 1 draws five ways to spread serving and Fig. 6 colocated against disaggregated; the pool following the traffic is Production's Fig. 3.
  9. A laptop: the same loop for one user. On a machine you own there is usually one user, so decode speed is memory bandwidth over the bytes read per token: Qwen3-0.6B at Q4_K_M generates 196 tokens a second on this M1 Pro measured here. The weights arrive as a file in some format and precision. Owner: Local and on-device inference, whose Fig. 1 puts one model in this laptop's memory and Fig. 3 sets bytes per token against tokens per second (files and GGUF types: sections 3 to 5); number formats: Quantization and Precision.

A map, not a mechanism: each step lights the part one child page owns and links that child's own figure. Judged on: time to first token, time per output token, goodput under a latency promise, and dollars per million tokens (LLM serving in production, section 1). This page's Capacity planner computes all four for any model and GPU; its Serving simulator runs the engine box; its Engine bench measured real engines. Counts drawn (three replicas, eight layer plates, the blocks, the users) are illustrative; the bar heights in step 3 are the page's numbers to scale.

You need (only if new to you): why a KV cache exists at all, recompute the prefix against keep it, on The transformer from zero (section 9); FLOPs and bytes per token on Performance math. Everything else is defined here.

New terms
Prefill: the prompt in one pass; writes the KV cache, yields the first token.
Decode: one pass per further token, reading the weights and the cache.
KV cache: the keys and values every past token keeps in every layer.
TTFT, TPOT: time to first token; time per output token after it.
Continuous batching: re-forming the batch every step.
Paged cache: the cache in fixed-size blocks found through a block table.
Prefix caching: keeping a prompt's cache for the next request that starts the same way.
Goodput: the load served while the latency promise holds.
Replica: one copy of the model behind a router.
How numbers are labelled: measured here, vendor, independent, derived, illustrative
measured here on the M1 Pro laptop this page was built on (llama.cpp, MLX, vLLM on CPU; absolute speeds are 20 to 100 times below a datacenter GPU but the shapes transfer, as the Engine bench explains); vendor figures from whoever sells the product, dated; independent figures from someone without that stake; derived with the formula or tab that computes it; illustrative inputs that only show a mechanism. Sources fetched on 2026-10-08.

Fig. 2 · Prefill takes 0.42 s for 2,000 tokens; the 300-token answer then takes fifteen times as long

Times are derived from the Capacity planner's step model for this deployment (step time = the larger of bytes read / (bandwidth × 0.8) and FLOPs / (FP8 peak × 0.345), plus 2.5 ms; the two efficiencies are fitted to MLPerf runs on that tab). Prefill and decode are drawn on different time scales: the 299 decode steps after the first token take about 15 times as long as the prefill.

1. One request: prefill, then decode

A language model returns a probability for every token in its vocabulary (128,256 for Llama 3.1) being the next one. To answer, the server calls it, picks one token (the sampler, Sampling and decoding), appends it and calls it again: autoregressive decoding, one token at a time, each depending on the last. Prefill reads all 2,000 prompt tokens through all 80 layers in one pass and stores every token's key and value vectors (the KV cache); decode then feeds only the newest token, which attends to the cache and adds its own entry. Fig. 2 follows the running example alone on one H200:

  1. The request arrives. An HTTP request with the chat messages and settings (max_tokens 300, temperature). Nothing has run on the GPU yet.
  2. Tokenize. The chat template wraps the messages in special tokens and the tokenizer turns the text into 2,000 token ids, on the CPU, in well under a millisecond of GPU time.
  3. Queue. The request waits for a seat in the next batch and for cache blocks. Alone on the GPU it waits for nothing; under load this is where TTFT goes (section 5).
  4. Prefill: all 2,000 prompt tokens in one pass. Every layer computes keys and values for all 2,000 tokens at once and stores them: 625 MiB of KV cache. The weights are read once for 2,000 tokens, so the arithmetic units are the limit (compute-bound): 423.5 ms.
  5. The first token. Prefill ends with probabilities for the first answer token; one is sampled, turned back into text and streamed. This moment is the time to first token, TTFT = 423.5 ms.
  6. Decode, one token per step. Each step feeds only the newest token, reads all 72.66 GB of weights plus the cache, and appends one key and value per layer. The read sets the pace: 21.6 ms per token (memory-bound), the time per output token.
  7. 299 steps later. The answer reaches 300 tokens. Each step re-read the weights: the request has caused over 20 TB of memory reads to produce 300 tokens, against one read for its whole prompt.
  8. Done: the cache is freed. End-to-end latency 6.88 s: 0.42 s of prefill, then 299 decode steps. Its 719 MiB of cache are released for the next user (or kept as a prefix cache, section 4).

Five numbers describe everything that follows: two that a user feels, one the owner pays for, one that runs out, and the bill.

TTFT
0.42 s

Time to first token: queueing plus prefill.

TPOT
21.6 ms

Time per output token after the first (inter-token latency, ITL, is one gap): 46 tokens a second, faster than anyone reads.

Throughput
46 → 2,982 tok/s

Output tokens per second for the GPU: one user alone, against 141 users decoding together (section 5).

KV cache
320 KiB / token

What each token of each active conversation holds (section 4); it decides how many users fit.

Cost
$0.54 / M tokens

Blended over input and output at $4.47 per H200-hour (section 6).

All five are derived for the running example by the Capacity planner; the same quantities measured here on a laptop are on the Engine bench. Exact definitions (TPOT as (end-to-end latency − TTFT) / (output tokens − 1), percentiles, goodput) are on LLM serving in production, section 1. Each token is detokenized and streamed as soon as it exists, usually as server-sent events (Streaming and real-time); the request ends at an end-of-sequence token or max_tokens, and its cache is freed.

Fig. 3 · The same weights: busy arithmetic in prefill, idle arithmetic in decode

One pass through the 80 layers, drawn in 8 groups of 10. Bytes, operations and time are derived from the Capacity planner's step model (weights 72.66 GB in FP8; KV cache read at the token's position; efficiencies 0.8 of bandwidth and 0.345 of FP8 peak, plus 2.5 ms per step). The busy bar is operations / (peak × 0.345) over the step time.

2. Why decode is slow: three regimes

A GPU has two budgets: arithmetic per second and bytes read from memory per second. One H200 does 1,979 trillion FP8 operations per second but reads only 4.8 TB/s, so it can do 412 operations in the time it reads one byte 1,979 / 4.8. Work below that ratio (its arithmetic intensity) is memory-bound; above it, compute-bound (the roofline: Performance math). Each weight does one multiply and one add per token. A decode step has one token per user, so the chip reads all 72.66 GB of weights for 2 operations per byte: the arithmetic idles more than 99% of the time and the step lasts as long as the read, 21.6 ms. Prefill shares one read among 2,000 tokens, 3,956 operations per byte: compute-bound, 423.5 ms, about 0.2 ms per token, a hundred times cheaper per token than decoding.

  1. 2,000 tokens enter together. The whole prompt enters the first layer at once. Each weight will be read from memory once and used 2,000 times.
  2. Layers 1 to 10. This group's weights stream in from memory while 2,000 tokens multiply against them: the arithmetic units, not the memory, set the pace.
  3. All 80 layers. Every group the same: 72.66 GB read, and the arithmetic units busy almost the whole time (3,956 operations per byte, far above the H200's 412).
  4. Done: 423.5 ms for 2,000 tokens. About 0.21 ms per token, compute-bound. Switch to decode to see the same weights serve one token.
Predict: a new GPU has twice the H200's arithmetic speed and the same memory bandwidth. How much faster does one user's answer stream on it?

The split shows on any hardware: on the laptop measured here, Qwen3-0.6B reads a 512-token prompt at 3,240 tokens per second and generates at 196, 17 times slower measured here (Engine bench). The ratio is larger on a datacenter GPU because arithmetic has grown faster than bandwidth: the M1 Pro does about 30 operations per byte read (5.0 TFLOP/s over 165 GB/s, measured on Topic: hardware), the H200 412.

RegimeBound byTypical workloadWhat helps
Prefillarithmeticlong prompts, short answers (retrieval, classification, summarisation)faster arithmetic (FP8, FP4), prefix caching, chunking so it does not stall others
Decodememory bandwidthchat and reasoning with long answersmore users per read (batching), fewer bytes (quantisation), more tokens per read (speculation)
Decode at batch size 1 on a small or fast modelfixed cost per step: launching hundreds of kernels and schedulingone local user; latency-critical single streamsfewer launches: CUDA graphs, fused kernels, a decode megakernel

Name the regime before choosing a fix. The third is easy to miss: on the laptop the fixed cost was 2.18 ms of a 5 ms Qwen3-0.6B step measured here, and the planner charges 2.5 ms per H200 step; fewer bytes do not help there. To check where you are, measure prompt-processing and generation speed separately (llama-bench reports pp and tg; vLLM's benchmark reports TTFT and TPOT); if single-stream tokens per second times bytes read per token is close to the memory bandwidth, decode is at its roofline (on this M1 Pro, rated 200 GB/s, plain decode of Qwen3-1.7B in F16 reached 187 GB/s, Local and on-device inference, section 1) and only fewer bytes or more users per read will help.

Megakernels and on-chip memory: published batch-1 figures (vendor, dated)
Cohere reports 292 tokens per second at batch 1 on an H100 with a whole decode step fused into one kernel, 62% of the hardware's speed-of-light limit and 1.58 times vLLM (Cohere, 2026-09-08); Inferact's TPU v7 megakernels 1.4 to 2 times a GB200 baseline at batch 1 to 8 (Inferact, 2026-09-23). The hardware answer keeps the weights in on-chip SRAM: Cerebras serves Qwen3.8-27B at about 1,800 tokens per second for one stream (AlphaSignal, 2026-09-11). The Engine bench's 147 GB/s is a different number from the 187 above: a line fitted to a 0.6B model as its context grows.

3. Every lever on one screen

Each technique in this topic attacks one of the limits of section 2 (decode's idle arithmetic, the memory the cache needs, prefill's arithmetic, the fixed cost per step) or a limit of the fleet (traffic, latency promises, many models). Read across a row for the trade; follow the last column for the mechanism.

LeverAttacksBuysCostsOwner
Continuous batchingdecode's idle arithmeticthroughput: 64 users give 42 times the tokens per step on the H200 modelevery user's step gets a little longerBatching, section 1
Paged KV cachecache memory reserved but emptymore users per GPU (old slab allocators used only 20.4% to 38.2% of it for tokens)a block table to follow; preemption when blocks run outBatching, section 2
Prefix cachingprefill of a prompt seen beforeTTFT: 1,426 ms to 77 ms on a shared prefix, measured herememory held by cached blocks; the request must reach the replica that holds themBatching, section 3; SGLang, section 2
Offload tierscache memory on the GPUa larger cache in CPU memory or SSD, restored on a hittransfer time on every restoreBatching, section 4
Chunked prefilla long prompt freezing everyone's streamsmooth TPOTa slightly later first token for the long promptBatching, section 5
Admission, preemption, prioritiesmemory that runs out mid-answer; tenants that competea server that degrades instead of failingwork thrown away and recomputedBatching, sections 6 and 7
KV cache in 8 or 4 bitscache memorytwice or four times the tokens per GBquality, model by modelBatching, section 8
Weight-only 8 or 4 bitsdecode's bytesfaster decode, smaller GPUsquality, larger on small models; prefill no fasterLocal inference, sections 4 and 5; Quantization and Precision
FP8 or FP4 weights and activationsprefill's arithmetic and decode's bytesboth phases fasterneeds Hopper, Blackwell or MI300-class tensor cores; calibrationQuantization and Precision
Speculative decodingdecode's idle arithmetic at small batchseveral tokens per read of the weightsthe gain shrinks as the batch growsSpeculative decoding
CUDA graphs, fused kernelsthe fixed cost per stepsmall-batch latencycapture time at start-up; per-model engineeringCUDA graphs; Writing kernels
Replicas and prefix-aware routingtraffic beyond one copy; cache missesthroughput in proportion to copies; cache hitsa router that weighs cache against loadProduction, section 2
Tensor parallelismweights that do not fit; latencybigger models, each GPU reads 1/n of the weightsNVLink-class links; one serverDistributed serving, section 3
Pipeline and expert parallelismcapacity across servers; huge mixture-of-experts modelsmodels larger than a serveridle stages; uneven experts; all-to-all trafficDistributed serving, sections 4 and 5
Prefill and decode on separate GPUsthe two phases slowing each othercontrol of TTFT and tail inter-token latencymoving the cache; two pools to balanceDistributed serving, sections 6 and 7
Autoscaling, warm replicastraffic that rises and fallsa bill that follows the trafficcold starts of tens of seconds to minutesProduction, sections 3 and 4
Multi-LoRAmany fine-tunes of one modelone base model serves them all in one batchbatching rules per engine; adapter loadingProduction, section 5; vLLM, section 5

Figures: the batching gain is derived from the Capacity planner (section 5); the slab waste is from PagedAttention, Fig. 2; the prefix-caching times are llama.cpp on Qwen3-1.7B with a 1,500-word shared prefix (vLLM's CPU backend went from about 6.7 s to under 1 s) measured here (Engine bench, "Prefix caching").

Along the frontier or outward. Baseten's framing is the test for any of these: batch size, quantisation level or speculation settings move a deployment along the latency-throughput frontier, while better kernels, cache management or architecture push the frontier outward (Baseten, 2026-09-02). Only the second is a free win.

4. Memory: the KV cache decides how many users fit

Every token of every active conversation keeps one key and one value vector in every layer:

KV bytes per token = 2 × layers × KV heads × head size × bytes per number
2
one key and one value
KV heads
with grouped-query attention (GQA) several query heads share one, which is why Llama 3.1 70B has 64 query heads but only 8 KV heads
bytes
2 for FP16/BF16, 1 for an FP8 cache

For Llama 3.1 70B that is 2 × 80 × 8 × 128 × 2 = 327,680 bytes, 320 KiB per token, so one 2,300-token conversation holds 719 MiB 2,300 × 320 KiB. The formula matches a real engine: for Qwen3-0.6B it gives 114,688 bytes, exactly what llama.cpp allocated measured here (448 MiB at 4,096 tokens, Engine bench). On one H200 with FP8 weights, vLLM's default 92% of 141 GB leaves about 54 GB for the cache after weights and activations: room for 141 conversations of the running example, with the shared system prompt stored once Capacity planner, section 1. The 142nd user waits, and since more users per step means more throughput (section 5), the cache size is the throughput ceiling. Model design moves it most: GQA cut Llama's cache 8 times against full multi-head attention, and DeepSeek's latent attention stores one 576-number vector per layer. The cache of any model at any context, against the weights, is on Long context's KV calculator; the attention designs behind it on Attention variants.

How engines make the most of it, each owned by Batching, KV cache and scheduling in depth:

Paging (section 2)PagedAttention cuts the cache into fixed blocks (16 tokens by default in vLLM) found through a per-request block table, so waste falls to one partly filled block per request (PagedAttention paper page).
Prefix caching (section 3)Blocks are named by a hash of their tokens and their predecessor's hash (vLLM) or kept in a radix tree (SGLang), so a request that starts like an earlier one skips that prefill.
Offload (section 4)Cold blocks move to CPU memory or SSD and come back on a hit (LMCache, Mooncake's store, llm-d's tiered cache).
When the pool is full (section 6)Evict unused cached blocks first, then stop admitting, then preempt a running request and recompute or swap it back.
Fewer bytes (section 8)An 8-bit cache halves the bytes (llama.cpp: 60,928 bytes per token against 114,688); dropping tokens only saves memory when whole blocks are freed, the realisable saving that page measures.

Drawn on the owners: block tables over one pool in Batching's Fig. 3 and admission and preemption in a full pool in its Fig. 5; vLLM's free queue, recorded, in Fig. 3; SGLang's radix tree in Fig. 2. The cache as physical memory is on Memory technology; measured cache size against context in the Engine bench, section "KV cache memory against context".

5. Batching and scheduling: one read of the weights, many users

A decode step reads 72.66 GB of weights to produce one token for one user. Let many users' next tokens ride on the same read: the weights are read once per step whatever the batch, and each extra user adds only its own cache bytes and a little arithmetic. On the H200 model, one user alone gets 46 tokens per second; 141 users together get 2,982, each at 21, and 64 users give 42 times the tokens of one for 1.54 times the step time Capacity planner. On the laptop measured here each extra sequence cost about 1.2 ms per step on top of the weight read, so 64 sequences gave 7 times the throughput of one measured here (Engine bench, "Batching"). More throughput for the owner against slower tokens for each user is the central dial of serving; past the knee, more users add latency without adding throughput.

Continuous batching (Orca, Yu et al., OSDI 2022: 36.9 times FasterTransformer's throughput at the same latency on GPT-3 175B, their measurement) re-forms the batch every step, so a finished request leaves and a waiting one joins at once; static batching ran until the longest answer ended, and dynamic batching (wait to fill, then run as a unit) suits one-pass models such as classifiers and embedders, not generation. Every engine here batches continuously by default. The before and after on the same requests is drawn on Batching, KV cache and scheduling in depth, section 1 (Fig. 2: eight requests, four seats, two ways), with paging's in its section 2; one engine step mixing prefill chunks and decodes is its Fig. 1, and one long prompt against eight decoding users under three token budgets its Fig. 4.

The scheduler builds each step's batch. Its four decisions, and who owns each:

DecisionThe choiceOwner
Admission and orderfirst come, first served by default (vLLM's fcfs); vLLM admits a request when its prompt fits, TensorRT-LLM's default only when its maximum length fits, so it never evicts but runs fewer at onceBatching, section 6
Chunked prefillcap the tokens per step and cut long prompts into chunks; decodes go first (Sarathi-Serve; on by default in vLLM v0.31.0, off in TensorRT-LLM v1.2.1)Batching, section 5
Preemptionwhen the cache runs out mid-answer, evict a running request and recompute it later or swap it back (vLLM v1 only recomputes)Batching, section 6
Priorities and fairnessinteractive before batch, shortest first, SLO-aware; SGLang's cache-aware order runs the most-cached requests firstBatching, section 7; SGLang, section 4

The real code: vLLM's scheduler loop and block pool, recorded step by step on the real engine, are vLLM: inside the default engine, sections 2 and 3 (its Fig. 2 is one engine step, recorded); SGLang's two queue orders round by round are its Fig. 3; every switch on your own traffic is this page's Serving simulator.

6. Latency promises and the bill

A service level objective (SLO) is the latency promise, written on a percentile: "99% of requests see their first token within 2 seconds" is a p99 TTFT target. Percentiles matter because a user who sends twenty messages meets the slow tail. One request measured here shows why: under 16 concurrent users on llama-server (Qwen3-0.6B, a 412-token prompt, 128 tokens out) it saw a TTFT of 0.96 s and a mean TPOT of 43.9 ms, yet a median gap of 31.4 ms and a longest gap of 803 ms, a step where another user's prompt was being read measured here (Engine bench, "One request alone, and the same request under load"). MLPerf's targets for Llama 3.1 8B are p99 TTFT 2 s and p99 TPOT 100 ms, and 0.5 s and 30 ms in its interactive scenario (MLPerf inference rules). Goodput (DistServe's term) is the highest request rate at which the target share of requests meets the SLOs: throughput that breaks the promise is not worth having.

GPUs = ⌈ peak requests/s ÷ requests/s one copy serves within the SLO ⌉ × GPUs per copy
$ per million tokens = $ per GPU-hour × GPUs ÷ (millions of tokens per hour at average traffic)

For the running example the Capacity planner finds that one H200 serves 2.11 requests per second within p99 TTFT 2 s and TPOT 50 ms (at that load TTFT p99 1.05 s, TPOT 46.8 ms), so 20 at peak need 10 H200s: $44.70 an hour at $4.47 per H200-hour, $0.54 per million tokens at half the peak on average, against $33.12 an hour for the same traffic at $0.40 per million from the cheapest API listed on 2026-10-08 planner, worked example "Chat assistant". For this workload the API is cheaper. The 50 ms TPOT target, not memory, sets the number of copies: relaxing it to 100 ms cuts the fleet from 10 GPUs to 8 ($35.76 an hour). Utilisation, not peak speed, decides self-host against API: one H200 at full batch makes 10.7 million output tokens an hour, $0.42 per million, but only if it is full every hour. Self-hosting wins with high and steady use, reserved or cheaper GPUs, heavy prefix reuse, a model no provider hosts, or data that cannot leave your network; add the engineers' time. How these definitions are measured, the cost slider and the break-even point are on LLM serving in production, section 1, whose Fig. 1 follows one request through the service; laptop numbers do not transfer to these dollars, only ratios and the shapes of the curves do (the Engine bench's "What transfers").

7. The engines compared

A serving engine is the program in the middle of the hero: an OpenAI-compatible HTTP front end, a tokenizer, the scheduler, the cache manager and a model runner that calls GPU kernels. Engines share sections 4 and 5 and differ in hardware, model coverage and what they optimise. Versions: latest GitHub releases on 2026-10-08.

EngineWhat it isCache and schedulerRuns on
vLLMThe default open engine; Python with CUDA, Triton and vendor kernels; began as the PagedAttention paper (UC Berkeley); a PyTorch Foundation hosted project since May 2025 (PyTorch blog, 2025-05-07)Paged blocks, hashed prefix cache, chunked prefill, recompute preemption; CUDA graphs for decodeNVIDIA, AMD and Intel GPUs, x86 and Arm CPUs; Google TPU, Intel Gaudi, Huawei Ascend and others through plugins
SGLangEngine from the SGLang paper (LMSYS); strong on large MoE models with expert parallelism and on prefix-heavy agent workloadsRadix-tree prefix cache (RadixAttention; default class UnifiedRadixCache), chunked prefill; first come, first served by default, cache-aware ordering (lpm) opt-inNVIDIA, AMD, TPU; its CPU backend targets Intel Xeons with AMX
TensorRT-LLMNVIDIA's engine; the stack behind most NVIDIA entries in MLPerf InferencePaged cache, in-flight batching; by default admits only what is guaranteed to fit, chunked prefill offNVIDIA only
DeepInferThe engine behind DeepSeek's own API, open-sourced (Apache 2.0) as an offline-inference release; originally built mostly on vLLM; serves one model, DeepSeek-V4.1-FlashData-parallel attention and expert parallelism balanced by EPLB, DSpark speculative decoding, a batch-invariant (deterministic) mode on NVIDIA; the KV cache system, prefill/decode split and cross-replica balancing are left outNVIDIA SM100 (Blackwell) and Huawei Ascend 950
llama.cppC/C++ engine for quantized GGUF models; local and edge firstllama-server: a fixed number of slots with continuous batching, per-slot prompt cache plus a host-memory prompt cacheCPU, Apple Metal, CUDA, Vulkan, ROCm and more
OllamaA local model manager and server; one command to pull and run a model. At v0.40 it runs upstream llama-server as a subprocess for GGUF models, and MLX models through its own MLX runner, the default on Apple silicon since v0.40.0llama-server's slots, with its own launch flags (one slot and a context set by free memory); aimed at one machineMac, Windows, Linux; CPU and consumer GPUs
MLX / mlx-lmApple's array framework and its LLM package; mlx_lm.serverBatched decode (32 at once by default), prompt cache; a quantized cache disables batchingApple silicon only
LMDeployShanghai AI Laboratory's engine (InternLM); C++ TurboMind and a PyTorch back endPaged cache, continuous batchingNVIDIA (TurboMind), Huawei Ascend (PyTorch engine)
TGIHugging Face's Text Generation Inference, once the common choice; in maintenance mode since 2025-12-11 and archivedContinuous batching, paged attentionNVIDIA, AMD, others
Versions and status of each engine on 2026-10-08, and where the defaults come from

Defaults quoted from source at the tagged versions (vLLM v0.31.0, TensorRT-LLM v1.2.1 llm_args.py, SGLang v0.5.21) and from the help output of the versions run on the Engine bench (llama-server 0.5.0, mlx_lm.server 0.32.0). The MLPerf observation is a count over the Capacity planner's extract of single-node LLM results, v5.1 to v6.1: most NVIDIA rows list TensorRT or TensorRT-LLM, the AMD rows mostly vLLM.

EngineStatus
vLLMv0.31.0, 2026-10-05; active
SGLangv0.5.21, 2026-10-02; active
TensorRT-LLMv1.2.1, 2026-04-20 (v1.3.0 release candidates since)
DeepInferno tagged release (built from source); open-sourced 2026-10-20
llama.cppv0.6.0, 2026-10-05 (measured here: 0.5.0)
Ollamav0.40.1, 2026-10-07
MLX / mlx-lmmlx 0.32.3, mlx-lm 0.32.0 (PyPI)
LMDeployv0.18.0, 2026-09-28
TGIRetired: maintenance mode from 2025-12-11 (its README recommends vLLM, SGLang, llama.cpp or MLX), last release v3.3.7, and the repository archived read-only on GitHub (last push 2026-03-21)

DeepInfer is an engine of a new kind on this list: a frontier lab's own production engine made public, but for one model and two vendors' chips, and without the parts that join engines into a service. How its layout works, and what it withholds, is on Distributed and disaggregated serving, section 5.

Above the engines sits a layer that routes across replicas and nodes: NVIDIA Dynamo, llm-d (Kubernetes-native around vLLM), KServe, Ray Serve and Triton Inference Server, whose dynamic batching is not continuous batching (it delegates that to a TensorRT-LLM or vLLM backend); all on Distributed and disaggregated serving, section 8. On a desktop, LM Studio puts a GUI over llama.cpp and MLX.

Choosing. Start from the hardware and the model, not from a benchmark chart:

  • Datacenter GPUs, a popular open model, an API this afternoon: vLLM, the widest model and chip support; most cloud stacks wrap it (vLLM: inside the default engine).
  • A large MoE across many GPUs, or agents resending long prefixes: SGLang or vLLM; SGLang published the most detailed expert-parallel recipe, DeepSeek-V3 on 96 H100s (vendor), and which engine is faster depends on the workload (SGLang, sections 9 and 10).
  • NVIDIA only, one model, every last percent: TensorRT-LLM (or NIM containers on it), at the price of lock-in (Distributed and disaggregated serving, section 8).
  • A laptop, desktop, phone or CPU server: llama.cpp or Ollama; on a Mac also MLX. Measured here, the two decode alike alone (196 and 199 tokens per second at 4 bits), but under overload mlx_lm.server ran out of GPU memory and its generation thread died while llama-server queued and slowed measured here (Local and on-device inference, sections 6 to 8).

New request shapes and release notes (decision-model routes added in October 2026, for example) are tracked in tech news, 2026-10-19.

8. Cheaper tokens: fewer bytes, or more tokens per read

Since decode is limited by bytes read, a token gets cheaper in two ways: read fewer bytes per token (quantisation), or get more than one token per read (speculative decoding). What matters for serving is which numbers are made smaller and what the hardware does with them:

QuantisedFormatsSpeeds upWatch
Weights onlyINT4, INT8 with a scale per small group (AWQ, GPTQ, GGUF k-quants), unpacked to 16 bits inside the kerneldecode, 2 to 4 times fewer bytes; not prefillquality, larger on small models
Weights and activationsFP8; FP4 on Blackwell (NVFP4, MXFP4), on tensor cores at two or four times BF16 speeddecode and prefillneeds the hardware
KV cacheFP8, INT8, INT4more users per GPUquality per model: on Qwen3-1.7B an 8-bit cache left WikiText-2 perplexity at 15.18 and a 4-bit one raised it to 19.42 (Batching, section 8)

Measured here on Qwen3-0.6B (llama.cpp, M1 Pro GPU): generation went from 113 tokens per second at F16 to 140 at Q8_0 and 196 at Q4_K_M, while prompt processing fell from 3,618 to 3,240; WikiText-2 perplexity went from 20.88 to 20.86 at Q8_0 and 22.59 at Q4_K_M measured here (Engine bench, "Quantization: speed and quality"). Eight bits is close to free; four bits is a real trade. Number formats and the methods (GPTQ, AWQ, rotations) are owned by Quantization and Precision; what a GGUF type name means and every type measured, by Local and on-device inference, sections 4 and 5.

Speculative decoding uses decode's idle arithmetic: a cheap draft proposes k tokens, the target model scores all of them in one pass, keeps the longest run it agrees with and adds one of its own, and a modified rejection-sampling rule keeps the output distribution exactly the target's (Leviathan et al. 2023). It pays only while checking k tokens costs little more than producing one, so the gain shrinks as the batch grows; on this laptop a Qwen3-4B pass over 4 tokens cost 2.2 times a pass over 1, so a 0.6B draft made llama.cpp slower on free text and at best 1.32 times faster on a highly predictable list measured here (a llama.cpp Metal effect of the Q4_K weights; on Qwen3-1.7B at Q8_0 a pass over 4 tokens cost 1.25 times one token) (Engine bench, "Speculative decoding"). The step, the acceptance rule and why it is exact, the worked example, every kind of drafter and the batch-size crossover are on Speculative decoding (one round on real tokens in its Fig. 1, the crossover in Fig. 3, where each drafter gets its guesses in Fig. 4); good small drafts on Distillation and small language models.

Kernels and graphs remove the overhead around the bytes: FlashAttention computes attention in on-chip memory (paper page; split-KV decode kernels on Writing kernels), paged attention kernels read keys and values through the block table, and CUDA graphs record a decode step's hundreds of launches once and replay them (Streams, CUDA graphs and multi-GPU; compilers on Compiler stack).

9. More than one GPU

One GPU stops being enough for three different reasons, each with its own fix: the weights do not fit, the cache for enough users does not fit, or one GPU is too slow for the latency target. The running example shows the second: Llama 3.1 70B in BF16 is 141 GB, so on H100s (80 GB) it needs two GPUs, and the two then have room for the cache of only 2 conversations Capacity planner, TP 2 on H100 in BF16.

SchemeEach GPU holdsTalks per stepBuysCostsOwner section
Replicas (data parallel)a whole copynothingthroughput, linearlythe model must fit one copy's GPUs2
Tensor parallel (TP)a slice of every layertwo all-reduces per layerbigger models, lower latency (each GPU reads 1/n of the weights)needs NVLink-class links; stays inside one server; Llama's 8 KV heads cap useful TP at 83
Pipeline parallel (PP)a run of whole layersactivations between stagescapacity across servers over slower linksno lower latency for one request; idle stages without enough micro-batches4
Expert parallel (EP)some of a mixture-of-experts model's expertsall-to-all: tokens to their experts and backhuge MoE models; big batches per expertload imbalance across experts; network heavy5
Prefill / decode splitprefill GPUs and decode GPUs, each with its own parallelismthe KV cache, once per requestno prefill stalls in decode; each phase sized on its ownmoving the cache; two pools to balance6, 7

Sections of Distributed and disaggregated serving, whose Fig. 1 draws the five splits and what crosses per token, Fig. 3a and Fig. 3b cut one model across every layer and by depth, Fig. 5 sends tokens to their experts and Fig. 6 sets colocated against disaggregated; the parallelism forms themselves (Megatron's split, all-reduce, all-to-all) are owned by Distributed Training, the links by Interconnects and scaling.

Disaggregated serving puts prefill and decode on different GPUs because they want different things (compute against bandwidth, section 2) and because a prefill in a decode step stalls every stream. The prefill GPU sends the finished cache to a decode GPU: 2,000 tokens of the running example are 625 MiB, about 13 ms over a 400 Gb/s network link or under 1 ms over NVLink 2,000 × 320 KiB / link speed. vLLM's own docs say "Disaggregated prefill DOES NOT improve throughput": it buys control over TTFT and tail inter-token latency (disagg_prefill.md). It is worth its complexity at scale with strict TPOT targets and long prompts; on a few GPUs, chunked prefill gets much of the benefit. When it pays, with the published claims and their settings, is that page's section 7.

10. Production: routing, scaling and honest numbers

With several replicas, something in front picks one for each request. A web load balancer's round-robin spreads load evenly but ignores the cache: with N replicas, a returning conversation lands on one without its cache (N − 1) / N of the time and its whole history is prefilled again. Prefix-aware routing (cache-aware, KV-aware) sends a request to the replica most likely to hold its prefix, weighed against how busy each replica is. LLM serving in production, section 2 (Fig. 2), steps eight requests through three real replicas under every routing rule (round-robin computed 13,000 prompt tokens; the rules that follow the prefix computed as few as 5,804) and replays a real multi-turn trace; how Dynamo and llm-d score workers is on Distributed and disaggregated serving, section 2 (Fig. 2), and SGLang's router code on SGLang, section 8.

AutoscalingScale on what users feel and what runs out: queue length, KV cache usage, TTFT. Not on GPU utilisation, which reads near 100% during memory-bound decode whether the server is comfortable or drowning (production, section 3, whose Fig. 3 follows a pool over half an hour).
Cold startsA new replica loads its weights (72.66 GB here: about 36 s at an assumed 2 GB/s from local NVMe 72.66 / 2, minutes from remote storage), profiles memory and captures CUDA graphs; keep warm replicas and scale ahead of known peaks (production, section 4).
SignalsPer replica: running and waiting requests, KV cache usage, preemptions, prefix cache hit rate, TTFT and ITL histograms, at /metrics for Prometheus. Waiting requests growing while cache usage sits near 100% means memory, not compute, is the limit (production, section 7; vLLM's own metrics: vLLM, section 6).
Benchmarks that do not fool youOpen-loop arrivals for a service (a closed loop of N waiting users hides overload), real length distributions, a stated prefix-cache state, percentiles and goodput at a stated SLO across a sweep of load (production, section 8). The Engine bench records every run with its command line and the machine's load.

Gateways above all this (keys, budgets, fallbacks between providers): Gateways and routing; client-side prompt caching with API providers: Context engineering.

11. Three workloads that change the rules

WorkloadWhat changesThe leversOwner
Long contextThe cache grows with every token: 128K tokens of Llama 3.1 70B are 40 GiB 131,072 × 320 KiB, four fifths of what an H200 has left after FP8 weights, for one conversation; every decode step reads all of it (Qwen3-0.6B went from 198 tokens per second with an empty context to 56 at 16,384 tokens measured here), and prefill attention grows with the square of the promptchunked prefill, an FP8 cache, offload, context parallelism, models built for it (sliding windows, latent attention)Long context; Batching, sections 4 and 8; whether models use it: Long-context and multimodal benchmarks
Structured outputTo guarantee valid JSON or any grammar, the engine masks the vocabulary at every step; the mask can also push the model away from what it would have written, so check quality, not only validityprecomputed masks (XGrammar reports up to 100 times faster masks, the authors), grammar back ends per engineSampling and decoding, section 5 (Fig. 3); under load: production, section 6; in SGLang: SGLang, section 6
Many fine-tuned variantsA LoRA adapter is megabytes against gigabytes; one base model can serve many adapters in one batch, each request applying its own through a batched kernel (Punica, S-LoRA)batched LoRA kernels, adapter paging, routing a request to a replica that holds its adapterproduction, section 5 (Fig. 4); vLLM's knobs: vLLM, section 5; LoRA itself: PEFT

12. Child pages

This root gives the map and the comparisons; each mechanism is taught on one child, in this reading order. Times are each page's own header.

Batching, KV cache and scheduling in depthContinuous batching, paging and block tables, prefix caching and eviction, offload tiers, chunked prefill, preemption, scheduling policies, what compressed caches really free, tuning; drawn and measured inline.Child page, about 45 min, plus 19 in closed details
Sampling and DecodingHow next-token probabilities become text: greedy and beam, temperature and truncation, twelve decoders compared on real text, logit processors, constrained decoding with JSON schemas and grammars; a Sampler lab on a real model's logits.Child page, about 23 min, plus 4 in closed details
Speculative decoding: draft models, EAGLE, MTP, n-gram, the batch-size crossoverWhy checking guesses is nearly free, one draft-verify-accept step, the exact acceptance rule, tokens per step, the cost model and batch-size crossover, drafters and trees; a Drafters measured tab.Child page, about 36 min, plus 8 in closed details
vLLM: inside the default engineOne request through vLLM's code, the scheduler loop and KV cache manager recorded on the real engine, the model runners, the knobs and what each trades (including multi-LoRA), metrics, upgrades and a first patch.Child page, about 41 min, plus 15 in closed details
SGLang: radix cache, cache-aware scheduling, large-scale servingThe radix tree against hash blocks, cache-aware queue order, the overlap scheduler, structured output, the router, DeepSeek at large scale, SGLang or vLLM, and SGLang on a Mac.Child page, about 34 min, plus 16 in closed details
Local and on-device inference: llama.cpp, Ollama, MLXBandwidth and fit on one machine, what a model file holds (safetensors, GGUF, ONNX and the rest), quantisation from zero and every GGUF type measured, llama-server, MLX, Ollama, consumer NVIDIA GPUs, very low bits, phones; File explorer and Fit and speed tabs.Child page, about 48 min, plus 53 in closed details
Distributed and disaggregated serving: Dynamo, llm-d, TensorRT-LLM, TritonWhy one GPU stops being enough, replicas and cache-aware routing scores, tensor, pipeline and expert parallelism at serve time, splitting prefill from decode and when it pays, the serving layer, choosing a layout.Child page, about 39 min, plus 21 in closed details
LLM serving in production: routing, autoscaling, cold starts, multi-LoRA, load testingSLOs, goodput, capacity and cost per token; routing across replicas, autoscaling, cold starts, multi-LoRA, structured output under load, metrics and alerts, load testing, measured on real replicas.Child page, about 37 min, plus 13 in closed details

Not children: number formats and quantisation methods belong to Quantization and Precision, KV-cache sizing to Long context; capacity and cost tools stay on this root's Capacity planner, since they span every child.

Depth: mistakes and interview rehearsal

Common mistakes (each points to the section that shows why)
  • "It does 3,000 tokens per second." Per user or for the server, at what latency? The running example does 46 for one user alone and 2,982 for the GPU at 141 users, each of them then at 21. A throughput without its concurrency and TPOT is not a capacity (sections 1 and 5).
  • Sizing by the weights alone. "70B in BF16 fits on two H100s" is true and useless: what is left holds the cache of 2 conversations (section 9). Size by weights plus cache for the concurrency you need.
  • Reading GPU utilisation as load. nvidia-smi's utilisation says a kernel was running, not how much of the chip it used (section 10).
  • Means instead of percentiles. The measured request of section 6 had a mean TPOT of 43.9 ms and an 803 ms stall.
  • Comparing engines at their defaults. llama-server picks 4 slots on its own, mlx_lm.server decodes 32 at once, vLLM's token budget per step depends on the GPU, TensorRT-LLM admits only what is guaranteed to fit. Set the same batch limits, cache size and precision before comparing.
  • "4-bit is faster." Weight-only 4-bit speeds up decode but not prefill (3,240 against 3,618 tokens per second measured here), and costs quality that grows as models shrink (section 8).
Interview: why is decode memory-bound and prefill compute-bound?
Each weight does 2 operations per token. Decode processes one token per sequence per step, so it reads every weight for about 2 operations per byte in FP8; an H200 can do 412 per byte read. Prefill processes thousands of tokens per read, far above 412. Batching moves decode up the same axis.
Interview: how much KV cache do 100 users at 4K context need on Llama 3.1 70B?
320 KiB per token × 4,096 × 100 = 125 GiB in BF16, more than one H200 has left after the weights; FP8 halves it. Then say what you would do: FP8 cache, TP 2, or fewer users per GPU.
Interview: TTFT is fine at low load but its p99 explodes at peak. Why, and what do you do?
Queueing: requests wait for cache room or prefill budget. Check waiting requests, KV usage and preemptions. Fixes: more replicas or a bigger cache (FP8 KV, TP), chunked prefill with a sensible token budget, prefix caching and prefix-aware routing, admission control that rejects early instead of timing out late. If TPOT is spiky instead, steps are carrying someone's prefill: chunked prefill caps it, disaggregation removes it.
Interview: design a chat assistant on a 70B model, 20 requests per second at peak, p99 TTFT 2 s, TPOT 50 ms.
Per request 2,000 tokens in, 300 out. FP8 weights (73 GB) fit one H200, leaving about 54 GB of cache: 141 conversations with a shared system prompt. Single-user decode 21.6 ms per token, prefill 0.42 s. Find the load per GPU that holds both targets (2.11 requests per second in the planner), so 10 GPUs, about $45 an hour; replicas behind a prefix-aware router; chunked prefill; autoscale on queue and TTFT with warm spares; compare against an API at average load.