Before you start: words you need#
| Word | Plain meaning |
|---|---|
| CUDA graph | A recorded sequence of GPU kernels that can be replayed with one launch (5.f). |
| Capture size | A batch size (in vLLM, a token count) for which a graph was recorded. Graphs only replay at the exact shape they were captured with. |
| Padding | Rounding a batch up to the next capture size, filling the extra slots with dummy rows. |
| Piecewise graph | Graphs that cover the parts of the model between attention calls, with attention itself run normally between them. |
| Full graph | One graph covering the whole forward pass, attention included. Needs an attention kernel that can be captured. |
| Uniform decode batch | A batch where every request contributes the same number of tokens: 1, or 1 + k with speculative decoding. |
| Eager mode | Running kernels one by one as the code reaches them, with no graph. |
5.f covered CUDA graphs mechanically. This lesson covers the serving decisions: which modes and sizes to capture, what they cost in memory and start-up time, and which features break them.
Facts checked on 12 November 2026 (vLLM v0.32.0).
1. Problem → Why → Optimization#
PROBLEM At batch 1–32, 30–50% of a decode step can be CPU launch overhead.
WHY Hundreds to a couple of thousand kernels per step, ~5 µs of CPU each,
while each kernel does only microseconds of GPU work.
OPTIMIZE Capture the decode step as a graph; replay it with one launch.
TRADE-OFFS
✓ 10–45% end to end, largest at small batch and for small models
✗ start-up time spent capturing (seconds to a minute)
✗ GPU memory for graph buffers (= KV cache you do not have)
✗ static shapes → padding to the next captured size
✗ some dynamic features cannot be captured
WHEN TO USE Always for decode in production.
WHEN NOT TO Debugging (graphs hide stack traces), or when an incompatible feature
is worth more than the speedup.2. Why does it matter? The serving-specific problem#
Decode shapes are almost static:
Fixed: model architecture, hidden size, number of layers
the KV cache pool's base address, the block table buffer's address
Variable: batch size (changes every step as requests join and leave)
context length per sequence (grows every step)
sampling parameters per requestTwo of the three variables are handled elegantly:
- Context length is data (in the block table and sequence-length buffers), not a shape. The paged attention kernel loops over it (12.l). No recapture needed.
- Sampling parameters live in fixed-size per-slot buffers.
Only batch size really changes the shapes. That is why engines capture a list of sizes and pad up to the nearest one.
3. Simple analogy#
A bakery with a set of pre-made baking trays.
The baker has trays for 1, 2, 4, 8, 16, 24 … loaves, each with the oven programme already set. An order for 21 loaves goes on the 24-tray with three empty spots. Making a new tray for every possible order size would fill the shop with trays (memory) and take all morning (start-up). Too few trays, and most bakes carry empty spots (padding).
4. Tiny example: one batch, padded#
Captured sizes: … 32, 40, 48, 56 … (vLLM steps by 8 in this range)
Live batch: 41 decode requests
Replayed graph: 48 → 7 dummy rows
What do the 7 dummy rows cost at decode?
weights: read once per step regardless of batch → no extra cost
KV: dummy rows have sequence length 0 → no KV read
GEMMs: 48 rows instead of 41 → extra FLOPs, but decode GEMMs
are memory-bound, so nearly freeAt small and medium batch, padding is close to free. It starts to cost when the step becomes compute-bound — at large batch, or when prefill tokens share the batch — because then every padded row is real arithmetic.
5. Technical explanation#
Graph modes in vLLM#
vLLM chooses how much of the step to capture with cudagraph_mode in --compilation-config:
NONE no graphs (same effect as --enforce-eager)
PIECEWISE graphs between attention calls; attention runs eagerly
FULL whole-step graphs, including attention
FULL_DECODE_ONLY full graphs for uniform decode batches only; prefill and
mixed batches run eagerly (good for decode-only instances, 14.j)
FULL_AND_PIECEWISE full graphs for uniform decode, piecewise for everything else
← the default with vLLM's compiler; usually fastest, most memoryFull graphs need an attention backend that can be captured. vLLM ranks backends by how much they support (always, uniform batches only, single-token decode only, never) and downgrades the mode automatically if the backend cannot do what you asked — another place to check the logs.
The capture list#
vLLM default (when you set nothing):
[1, 2, 4] + every 8 from 8 to 248 + every 16 from 256 up to max_cudagraph_capture_size
max_cudagraph_capture_size defaults to 512 (1,024 on data-centre Blackwell)
→ 51 sizes at the default 512Override it with --compilation-config '{"cudagraph_capture_sizes": [1, 2, 4, 8, 16, 32, 64]}' or
cap it with max_cudagraph_capture_size. Batches larger than the biggest captured size run without
a graph.
Tuning the list#
1. Measure your batch-size distribution over a day of real traffic (19.c metrics).
2. Keep capture points dense where traffic is dense.
3. Drop sizes you never reach — each costs memory and start-up time.
Example: if 80% of steps are batch 20–60 and you never exceed 128, capture
[1, 2, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 56, 64, 96, 128]Few teams tune this. On a latency-critical service it is worth half an hour.
Memory budget#
Each captured graph needs its static input and output buffers and its intermediate activations.
Engines share one memory pool across graphs, so the total is far less than “per-graph size ×
number of graphs” — typically a few hundred MiB to a couple of GiB per GPU, more with
FULL_AND_PIECEWISE. vLLM measures it during start-up and already subtracts it from the KV cache
it reports; your own capacity estimates (23.b) should do the same.
If memory is tight, shorten the capture list or use FULL_DECODE_ONLY before disabling graphs.
6. Under the hood: feature interactions#
This is where production surprises live:
FEATURE GRAPH COMPATIBILITY (vLLM v0.32.0)
Paged attention ✓ context length is data, not shape
Continuous batching ✓ via the capture list and padding
Prefix caching ✓ block tables are data
Chunked prefill / mixed ✓ piecewise graphs; full graphs only for uniform decode
Speculative decoding ✓ verify steps are "uniform decode" with 1 + k tokens per
request; drafters may run their own graphs
Multi-LoRA ✓ supported, but adds graph variants (more memory)
Structured output ✓ the grammar mask is applied outside the graph
Python logits processors ✗ run outside the graph, on the CPU
Tensor parallelism ✓ NCCL and custom all-reduce are capturable
Pipeline parallelism ⚠ supported, check your version's notes
New attention or sparse ⚠ may force PIECEWISE or reject FULL at start-up
backendsOlder versions and other engines differ — LoRA and speculative decoding used to disable graphs in several stacks. The dangerous case is a silent downgrade. Enable a feature, the engine falls back to piecewise or eager for some batches, and you lose 10–25% without an error. Check the logs after enabling any new feature, and re-benchmark.
Verification#
vLLM start-up logs show each capture pass and its cost, for example:
Capturing CUDA graphs (mixed prefill-decode, PIECEWISE): 100% ... 51/51
Capturing CUDA graphs (decode, FULL): 100% ... 35/35
Graph capturing finished in 14 secs, took 0.62 GiB
Warnings that the mode was downgraded, or "enforce_eager" in the config,
mean you have lost some or all of the optimization.Also verify by profiling (22.h): a graph-replayed decode step in Nsight Systems shows one
cudaGraphLaunch followed by back-to-back kernels. Eager shows hundreds of cudaLaunchKernel
calls with gaps between kernels.
7. Performance implications#
Model / batch Typical speedup from graphs
7B, batch 1 1.4–1.6×
7B, batch 32 1.15–1.25×
70B (TP=8), batch 1 1.3–1.4×
70B (TP=8), batch 32 1.15–1.2×
70B (TP=8), batch 128 1.05–1.1×
Prefill-heavy steps ~1.0×These ranges are typical, not guaranteed; measure your own (exercise A). Two patterns hold everywhere: smaller models benefit more (more kernels per unit of useful work), and smaller batches benefit more (less work per kernel). Full graphs add a further gain over piecewise at small batch, because attention’s launches disappear too.
8. Production implications#
- Leave graphs enabled. Default in vLLM, SGLang and TensorRT-LLM.
- Budget the start-up time. Capture adds seconds to a minute to every cold start (20.g). vLLM caches compiled code (13.m) but captures graphs on every start; shorten the list if cold start matters.
- Budget the memory, and prefer
FULL_DECODE_ONLYon decode-only instances. - Tune the capture list to your measured batch distribution.
- Re-benchmark after enabling any new feature, in case graphs were downgraded.
- Use
--enforce-eageronly for debugging, and make sure it is not in your production config. This has happened to many teams.
9. Common mistakes#
--enforce-eagerleft in production. A free 20–40% loss at small batch.- Not noticing a silent downgrade after enabling a feature or switching attention backend.
- A capture list mismatched to traffic, either wasting memory on sizes never used or leaving common sizes uncaptured.
- Forgetting the graph memory in capacity planning.
- Overestimating padding cost at decode. Dummy rows read no KV and the weights are read anyway.
- Expecting graphs to help prefill. Prefill kernels are big enough that launch overhead hardly matters.
10. Hands-on exercise#
A. Measure the win. Run vLLM with and without graphs (--enforce-eager) at batch 1, 8, 32 and
128. Plot speedup against batch. Compare with section 7.
B. Compare modes. Run PIECEWISE, FULL_DECODE_ONLY and FULL_AND_PIECEWISE. Record start-up
time, graph memory (from the log) and decode latency at batch 1 and 32.
C. Tune the list. Collect the batch-size distribution from a realistic load test. Design a capture list that minimizes padding within a fixed memory budget. Compare with the default.
D. Find a downgrade. Enable a feature or attention backend your version cannot fully capture. Find the log line that says so, and measure what you lost.
E. Verify in a profile. Capture Nsight Systems timelines with and without graphs. Count the
cudaLaunchKernel calls and measure the total gap time in each.
11. Interview questions#
- Why do CUDA graphs help LLM decode so much at small batch?
- Why does growing context length not require recapture?
- How do engines handle varying batch size, and what does padding really cost at decode?
- What is the difference between piecewise and full graphs, and why does vLLM use both?
- How would you tune the capture list?
- How does graph memory affect capacity?
- How would you detect that graphs were silently downgraded?
12. Further reading#
Checked on 12 November 2026.
- [REFERENCE] vLLM CUDA graphs design — modes, dispatch, backend support
- [REFERENCE] vLLM compilation config —
cudagraph_mode,cudagraph_capture_sizes,max_cudagraph_capture_size - [REFERENCE] CUDA C++ Programming Guide — CUDA Graphs
- [REFERENCE] vLLM’s capture code and compilation integration — read it in 18.d