How models are made training pipeline · stage 7
Serving deep dive: KV cache, batching, and inference enginespractitioner-perspective methodology · key facts carry official sources
Why serving throughput is bottlenecked by KV-cache memory; what PagedAttention, continuous batching and RadixAttention each solve; where vLLM and SGLang sit. Practitioner view; the one-page explainers live on the Learn site, cross-linked, not duplicated.
What this guide covers
Once a model is running, the throughput bottleneck is usually not compute but the KV cache in memory.
This guide covers the three things inference engines do around that memory: how to store, how to batch, how to reuse.
This site runs no benchmarks. Every multiplier is a paper's self-reported figure, sourced at the end;
engine capabilities always follow the official docs.
The KV cache: the first bill of inference
Autoregressive generation revisits the preceding text for every token it produces.
To avoid recomputation, the earlier key/value tensors are cached — that is the KV cache.
Its memory grows linearly with “context length × concurrent requests” and scales dynamically.
The PagedAttention paper points out that under inefficient management, fragmentation and redundant copies waste this memory badly,
which in turn caps batch size — throughput stalls not because compute ran out but because requests won't fit.
Rule of thumb: on the same card, throughput collapses when long context and high concurrency arrive together —
most likely the KV-cache memory hit its ceiling first.
PagedAttention and continuous batching
PagedAttention borrows the paging idea from operating-system virtual memory:
the KV cache is allocated in fixed-size blocks that need not be contiguous. The paper self-reports near-zero waste.
vLLM builds on it; the paper self-reports 2–4× throughput at equal latency — note this is the paper's experimental setting.
Continuous batching solves a different problem: requests arrive unevenly.
A static batch waits for the slowest request before swapping in the next batch; continuous batching lets finished requests leave at any time and new ones slot in.
vLLM's official docs describe both side by side as throughput sources.
Chunked prefill is the companion third move: a long prompt's prefill phase hogs the GPU,
so it is cut into chunks interleaved with decode steps, flattening the latency curve.
Where vLLM and SGLang sit
vLLM: the general-purpose LLM serving engine, the official landing of PagedAttention,
with docs covering quantisation, parallelism and multi-node deployment. The default name in open-weight deployment discussions.
SGLang: a serving framework aimed at “multi-call programs” — agent loops, reasoning chains, structured-output workloads.
The paper self-reports two mechanisms: RadixAttention reuses KV cache across shared prefixes between calls;
compressed finite-state machines speed up structured-output decoding. The paper self-reports up to 6.4× throughput on such tasks.
The two are not a ranking — their workload profiles differ:
for single-turn Q&A and batch offline generation, the vLLM route is mature;
for multi-turn agents, shared long prefixes and strict-format output, SGLang's reuse mechanisms fit.
This site adjudicates neither; the paper figures are all at the end.
Running GGUF locally on one machine is a separate line: llama.cpp-style implementations do not chase concurrent throughput,
they chase fitting the model into limited memory. Ask “how many concurrent requests” first, then ask about the engine.
Speculative decoding: trading compute for latency
Decoding produces one token per step, leaving most GPU compute idle.
Speculative decoding has a small model guess several tokens first while the big model verifies them in one parallel pass; correct guesses are free profit.
It changes single-request latency, not the throughput ledger; workloads with high miss rates see the gains shrink.
Both vLLM and SGLang official docs offer the option; the payoff depends on how well the draft model matches the task.
How this differs from the Learn site
The Learn site's KV cache,
PagedAttention,
continuous batching and
speculative decoding pages are user-perspective explainers;
this guide is about how practitioners keep the inference ledger and pick an engine by workload profile.
Same concept, different depth on each side, cross-linked without duplication.
For hardware facts and cost math see the next guide, “GPU facts and cost math”.
Sources
- vLLM official docs home page (fetched directly, HTTP 200, 2026-10-21):https://docs.vllm.ai/en/latest/
- vLLM architecture overview (official docs design section; fetched directly, HTTP 200, 2026-10-21):https://docs.vllm.ai/en/latest/design/arch_overview.html
- vLLM PagedAttention design document (official docs design section; fetched directly, HTTP 200, 2026-10-21):https://docs.vllm.ai/en/latest/design/paged_attention.html
- PagedAttention paper (arXiv 2309.06180, self-reported 2–4× throughput; abstract page fetched directly 2026-10-21):https://arxiv.org/abs/2309.06180
- SGLang official docs home page (fetched directly, HTTP 200, 2026-10-21):https://docs.sglang.ai/
- SGLang official repository (self-described: a high-performance serving framework for LLMs and multimodal models; fetched directly, HTTP 200, 2026-10-21):https://github.com/sgl-project/sglang
- SGLang paper (arXiv 2312.07104, RadixAttention and structured output, self-reported up to 6.4× throughput; abstract page fetched directly 2026-10-21):https://arxiv.org/abs/2312.07104
- llama.cpp official repository (the representative local-inference implementation; fetched directly, HTTP 200, 2026-10-21):https://github.com/ggml-org/llama.cpp
Base source snapshot: 2026-10-21; item-specific additions and check scope appear in the text and source labels. Check original specifications, methods and conditions.