Unit 12 of 12 · about 5 hours · implement, measure
Engine dispatch and fallback, kernel-to-endpoint translation and negative results
Attention baselines, shape matrices, end-to-end translation and losing regimes gave the translation formula for generic blocks. Here the runner chooses backends per phase and batch, so translation must survive dispatch, padding and fallback.
You'll be able to
- Wire one kernel path into a serving runner with explicit backend selection and a tested eager fallback.
- Translate a measured kernel win into endpoint TTFT, TPOT and goodput with Amdahl shares, or reject the win honestly.
- Preserve the negative result: keep outputs identical, keep the losing regime in the report, and keep the fallback as the shipped behavior where it loses.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Backend registry and graph fallback boundaryMini-SGLang - Kernel, Model Runner and Overlap Boundaries
GraphRunner.pad_batch,can_use_cuda_graph,replayand theprepare_for_capture/prepare_for_replaybackend hooks. Forcreate_attention_backendand its hybrid backend string, also open https://github.com/sgl-project/mini-sglang/blob/9a91cfafe754aa85daee49998176275667eb58f2/python/minisgl/attention/__init__.py - Backend selection and capture limitsFlashInfer Documentation
FlashInfer documentation: the
backendparameter (auto,fa2,fa3,trtllm-gen,cute-dsl,prims-ts) with automatic selection,use_cuda_graphrules, and the constraint thatplanruns outside capture (page read 2026-10-14, release 0.7.1)For custom masks also open https://docs.flashinfer.ai/tutorials/kv_layout.html and read Mask Layout (2D Ragged Tensor). Keep
backend="auto"on stable backends: experimental ones join automatic selection only withFLASHINFER_ALLOW_EXPERIMENTAL_AUTO_BACKENDS=1(Experimental APIs and Backends page), and naming one explicitly opts in too. - Decode-kernel dispatch and the eager endpoint baselineAI Systems Performance Engineering companion code - Chapter 18
BaselineVLLMV1Integration(enforce_eager=Truebaseline,SamplingParams,llm.generate,mean_latency_msandthroughput_tokens_per_sec); compare withbuild_decode_kernelindecode_kernels.py(prefer_vllmselects the vLLM path,prefer_vllm=Falsekeeps the explicit torch path)The dispatch file reads
paged_attention_v1fromvllm._custom_ops, which vLLM 0.31.0 does not provide; treat it as a dispatch sketch and verify the op name against your engine version. Withprefer_vllm=Truea missing op raises instead of falling back, unlike the tested fallback this unit asks for.
Focus on
- Dispatch is per phase and batch, not per model. A hybrid
prefill,decodestring can win prefill and lose decode; log the backend per phase before translating. - Translate with shares, not kernels. For speedup on a serial critical-path share , the unchanged-rest model predicts : a 2x win on a 10% share gives about 1.05x. This is not a queueing or endpoint-tail model; overlap, dispatch, scheduler changes and load can invalidate its assumptions.
- A fallback that never fires in testing is untested. Force an unsupported shape, dtype or backend and check outputs plus the miss count.
- Custom masks ride the same dispatch. A mask the backend cannot express must fall back with identical outputs, not silently run unmasked.
Common mistakes · 3
- Averaging per-kernel speedups into an endpoint claim. Weight by measured shares under the serving shape distribution.
- Testing dispatch only on supported shapes. The fallback path ships too; an untested fallback is a latent outage.
- Dropping the negative result from the report. A documented loss with its regime is section evidence; an unreported one will be rediscovered in production.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.A kernel runs 3x faster on half the runtime. What is the endpoint win?Answer
About 1.5x under a serial critical-path model with all other work unchanged: . Endpoint measurements still need to include dispatch, padding, overlap and queueing.
2.The fallback never triggers in your tests. Done?Answer
No. Force unsupported inputs and verify identical outputs plus miss accounting; otherwise the fallback is untested code.
3.Backend A wins decode but loses prefill. Which ships?Answer
The workload's phase mix decides. Log per-phase backends, translate each phase, and keep the hybrid or per-phase choice the numbers support.
4.The endpoint shows no win with outputs preserved. Report or retry?Answer
Report. A preserved negative result with its regime and shifted bottleneck is the required evidence.
You're done when
One kernel path ships behind dispatch with a tested fallback, the endpoint comparison under replayable load shows a win or a preserved rejection, and every number traces to a logged share.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 11 more in the section
- AI Systems Performance Engineering companion code - Chapter 18Chris Fregly · required
Start with paged_attn_common.py, the dense versus paged layout pair, CUDA graph bucketing and the vLLM integration pair. Run correctness tests first, then a hardware-compatible benchmark with newly captured artifacts.
- 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.
- Mini-SGLang - Kernel, Model Runner and Overlap BoundariesSGLang Project · support
Trace how FlashAttention or FlashInfer, KV layouts, tensor parallel communication and overlap scheduling meet the model runner. Identify the fallback and state-reset boundary before attempting a change.
Also in this section
- FlashInfer: Efficient and Customizable Attention Engine for LLM Inference ServingFlashInfer Project · primary
Read the storage heterogeneity, plan and run separation, load-balanced scheduling, customization, CUDA Graph compatibility and end-to-end evaluation. Use it to connect serving-shaped attention kernels to dynamic workloads and dispatch constraints.
- AI Systems Performance Engineering - Chapters 18 and 19, decode kernels and engine optimizationsChris Fregly (O'Reilly) · required
Read "Optimized Decode Kernels" in Chapter 18 (FlashMLA, ThunderMLA, FlexDecoding), then the Chapter 19 sections on kernel autotuning, occupancy-aware kernel selection, hot-swappable kernels and CUDA-graph prewarming. Choose one bounded critical path to verify.
- FlashAttention-2: Faster Attention with Better Parallelism and Work PartitioningTri Dao · required
Derive online-softmax state, memory traffic and work partitioning. Implement only a small oracle-backed version or use the CS336 assignment; production kernel tuning belongs to the GPU track.
- CS336 Assignment 2 - FlashAttention and Triton SectionsStanford University · required
Complete the relevant derivation, PyTorch reference and Triton sections using your own code. Follow assignment integrity: use external help for concepts, invariants, tests and profiling, not copied solutions or edited answer code.
- 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.
- LLM Inference: From scratch, one token at a time - Module 07Tushar Amrit · support
Work the Attention Kernels module for the decode-attention memory traffic and the paged-attention gather before the matching units.
- AI Performance Engineering - Kernel Optimization, Profiling and AttentionWafer · reference
A curated index. Use Sections 2 and 3 only to find a kernel or profiler source the other entries lack.
- 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.
- vLLM structured outputs (v0.31.0)vLLM Project · required
Read Offline Inference and the API-field migration warning; trace grammar bitmask application before sampling in the versioned model-runner API.
- PyTorch compiler troubleshooting guide (2.14)PyTorch · reference
Read Graph break, Guards, Recompilation and Dynamic Shapes; run
TORCH_LOGSset tograph_breaksandrecompileson a small serving-shaped function.