Unit 8 of 12 · about 5 hours · explain, measure

CUDA graph capture and replay, static shapes, buckets, padding and fallback

CUDA graphs and validated dispatch with fallback and Launch overhead, bucketing and graph misses covered generic capture and bucketing. Serving adds mixed batch shapes and attention backends that veto full capture, so one static graph never fits the whole workload.

You'll be able to

  • Explain full, piecewise and eager dispatch for uniform-decode versus prefill/mixed batches, including the automatic backend-compatibility downgrade.
  • Capture and replay a static-shape decode step with bucketed sizes, padded inputs and a counted eager fallback for misses.
  • Measure replay against eager with warmup and interleaved medians, and attribute the gap to launch supply rather than faster execution.

Covers

CUDA graph capture and replayStatic-address and shape constraintsGraph buckets, padding and eager fallback
1

Read

In this order, only the parts listed

0 of 4 done

  1. CUDA Graphs modes and the v1 dispatchervLLM CUDA Graphs design (v0.31.0)

    CUDAGraphMode (NONE, PIECEWISE, FULL, FULL_DECODE_ONLY, FULL_AND_PIECEWISE), CudagraphDispatcher with BatchDescriptor, and CUDA Graphs Compatibility of Attention Backends (the AttentionCGSupport table and downgrade)

    Read the dispatch design, not the linked pull-request comments as results. Confirm cudagraph_capture_sizes defaults in CompilationConfig in your installed v0.31.0 source.

  2. Full versus piecewise graphsUCSD CSE 291A (Spring 2026) - Guest lecture: Engineering vLLM

    May 7, 2026 scribe notes: Sections 4.1 (CPU overhead share) and 4.5 (full versus piecewise graphs, the attention-boundary split, Table 1)

    Treat the lecture's H100 percentages as its hardware result, not your target. Map its full/piecewise vocabulary onto v0.31.0 runtime modes; capture moved under CudagraphDispatcher.

  3. Decode-wrapper capture contractFlashInfer Documentation

    FlashInfer documentation: BatchDecodeWithPagedKVCacheWrapper constructor (use_cuda_graph, backend), plan/run Parameters and Notes (page read 2026-10-14, release 0.7.1)

    plan cannot run inside a graph or torch.compile; replay needs stable addresses and a planned shape. Read decode only.

  4. Padding policy and overlapTensorRT-LLM Architecture Overview

    Architecture Overview: Runtime Optimizations, CUDA Graph (padding to the nearest larger captured size) and Overlap Scheduler (page read 2026-10-14)

    Read the padding-versus-eager tradeoff and the overlap pipeline. The 22% figure is the page's result on its models and hardware, not your target. Note the page date before treating a path as available.

2

Focus on

  • A captured graph replays addresses, not values or shapes. New contents in the same static buffers replay correctly; a new batch size needs its bucket's capture or the eager path.
  • The vLLM v1 dispatcher searches keys in the order FULL, then PIECEWISE, then NONE. A missing key runs eager. Cascade attention never takes a full graph.
  • Most backends support full graphs only for uniform batches, so mixed batches downgrade automatically. Read the resolved runtime mode from logs, not the requested cudagraph_mode.
  • Padding to a larger captured size executes wasted tokens to avoid a miss. Count padded rows as executed work and keep them out of goodput.
Common mistakes · 3
  • Reusing a capture after the batch shape changed and reporting the outputs. A stale graph replays stale addresses; recapture or take the eager path.
  • Reading the configured cudagraph_mode as the executed mode. Downgrade by backend support is silent unless you check the dispatched runtime mode.
  • Counting padded tokens as served work. They cost execution time but complete no request.
3

Try it yourself

Closed-book, before checking anything

On your GPU, capture a two-op static-shape step (addmm plus in-place clamp) in torch.cuda.CUDAGraph after three warmup runs. Replay matches eager under torch.testing.assert_close, and new values written into the same buffers replay to the new expected outputs. Then list your engine's capture sizes, name which batch sizes hit, which pad and which miss to eager, and record interleaved eager/replay medians with the timed boundary stated.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Why do new values in the same buffers replay correctly while a new batch size cannot?Answer

    Replay replays recorded addresses. Same-shape contents sit at the same addresses; a new shape needs different addresses and launches.

  2. 2.A batch misses every captured key. What runs?Answer

    The eager path (the NONE runtime mode). Count the miss; silent fallback hides a bucketing defect.

  3. 3.The backend table allows FlashInfer full graphs only for single-token uniform decode. What happens to a requested FULL mode on mixed batches?Answer

    It downgrades. Mixed batches cannot use full graphs with that backend, so they take piecewise or eager under the fallback policy.

  4. 4.Does graph replay make the matmul itself faster?Answer

    No. It removes repeated launch supply. The recorded kernels run unchanged; the measured gap is reduced host overhead.

You're done when

Your capture replays identical results at captured shapes, misses fall back with no wrong outputs, and you can name the dispatched runtime mode for a uniform-decode and a mixed batch from the capture-size list.

Only when you can do this without notes.

Leads to

Notes

Resources · 4 for this unit, 10 more in the section
  • FlashInfer DocumentationFlashInfer Project · required

    Use the current attention, PageAttention, sampling, JIT and CUDA Graph interfaces while implementing. Pin the version and supported GPU architecture, and validate dispatch and fallback over the real workload shape distribution.

  • UCSD CSE 291A (Spring 2026) - Guest lecture: Engineering vLLMUC San Diego · support

    Read the scribe notes, Sections 4 and 5: CPU overhead, the API server and renderer, synchronous and asynchronous engine-core scheduling, GPU-side input preparation, piecewise CUDA graphs and the hybrid kernel strategy.

  • vLLM CUDA Graphs design (v0.31.0)vLLM Project · support

    Use the capture modes, batch-size buckets and piecewise splitting around attention to explain what a graph replay can and cannot include.

  • TensorRT-LLM Architecture OverviewNVIDIA · support

    Use the runtime-optimization section to compare graph replay, overlap scheduling and backend dispatch with your selected engine. Record current version and hardware support before treating a path as available.

Also in this section