Explain what CUDA graphs do during decode and why the speedup is most visible at small batch. Then identify two conditions under which CUDA graphs help less, or break entirely.
CUDA graphs record the kernel-launch sequence of one decode step and replay the whole graph as a single submission, collapsing dozens of per-step CPU dispatches into one.
Picture a busy chef shouting instructions to a fast cook for each tiny task: chop, stir, pour, taste. The cook is so fast that most of the wall-clock time is the chef finishing one sentence and starting the next. CUDA graphs let the chef write the whole recipe down once and just say 'do that recipe' on every batch, so all the talking happens once. This makes a big difference when the cook is much faster than the chef can talk, which is exactly what happens during decode at small batch. But if the recipe changes every batch (different ingredients, different steps), writing it down does not help, and that is when CUDA graphs stop working.
Detailed answer & concept explanation~8 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
3 min: explain the ~10-30 us per-launch CPU overhead, count kernels per decode step, identify the small-batch regime where overhead dominates, describe what a CUDA graph captures and replays, then name the large-batch erosion and the shape-variability break with shape bucketing as the standard mitigation.
| Regime | Per-step time without graphs | Per-step time with graphs | Win |
|---|---|---|---|
| Small batch (1-4) on 7B-13B model | ~3-8 ms (mostly dispatch) | ~1.5-4 ms | 1.5-2x |
| Small batch on 70B model | ~25-30 ms (dispatch is ~10-20% of step) | ~22-26 ms | 1.1-1.3x |
| Large batch (32-64) on 70B | ~50-60 ms (dispatch <5%) | ~48-58 ms | <1.05x |
| Variable-shape continuous batching | Per-step recapture cost | Per-bucket graphs + padding | Depends on bucket coverage |
Real products, models, and research that use this idea.
- vLLM captures CUDA graphs per (batch_size, max_seq_len) bucket and routes each scheduling step to the nearest bucket via padding.
- TensorRT-LLM's runtime ships explicit CUDA-graph capture for decode with shape buckets defined at engine build time.
- SGLang uses CUDA graphs for the decode loop and falls back to eager execution for prefill, where shapes are highly variable.
- NVIDIA's H100 and B200 driver releases include latency improvements specifically targeting per-launch overhead, but CUDA graphs remain the standard way to eliminate it for repeated decode steps.
- PyTorch 2.x exposes cudagraph trees as a higher-level abstraction that handles capture and replay automatically for static graphs.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does CUDA graph replay differ from compiler-level kernel fusion?
QWhy does the captured graph need fixed tensor shapes?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Thinking CUDA graphs make the GPU work faster. The kernels themselves run at the same speed; CUDA graphs only remove the CPU-side dispatch overhead between them. The win comes from eliminating idle gaps, not from accelerating compute.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.