Unit 1 of 12 · about 3 hours · explain, implement
Stable and online softmax, normalization and fused residual paths
Build on Online softmax state, query and key-value tiling and Stable RMSNorm and LayerNorm, and RoPE fusion. The serving task is preserving residual state and reduction semantics across repeated decode steps, not writing another generic reduction kernel.
You'll be able to
- Integrate residual-add plus RMSNorm with explicit mutation, accumulation and contracts.
- Use online-softmax state to combine disjoint decode partitions without averaging their outputs.
- Test both returned activations and retained residuals against an independent reference.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Attention composition, arXiv:2501.01005v1FlashInfer: Efficient and Customizable Attention Engine for LLM Inference Serving
Section 2.2, Attention Composition, attention-state definition and binary merge
Use disjoint key subsets and maximum subtraction when merging. Associativity holds in real arithmetic, not bitwise floating-point arithmetic.
- Fused residual mutation contractFlashInfer Documentation
FlashInfer documentation: Step 1, Step 2 and Parameters of
fused_add_rmsnorm(page read 2026-10-14, release 0.7.1) - Residual ownership in the model pathMini-SGLang - Kernel, Model Runner and Overlap Boundaries
RMSNormFused.forward, including the absent-residual branch
Focus on
- For residual sum , RMSNorm returns . LayerNorm instead centers the row and uses population variance. Preserve the model's choice.
- The fused API overwrites the residual with the sum and the input with normalized activations. Returning only normalized values loses state needed by the next block.
- For partial attention states, merge unnormalized weights or log-normalizers. Keep the logarithm base consistent and rescale by the larger maximum before exponentiating.
- Specify whether the residual sum is rounded to storage dtype before normalization. Promotion before the sum and promotion only for the reduction are different numerical contracts.
Common mistakes · 3
- Validating activations but forgetting that the residual was overwritten incorrectly.
- Reading aliased input and residual buffers as though they were independent. Reject unsupported overlap before dispatch.
- Initializing an all-masked partition with ordinary subtraction of two negative infinities. Give empty states an explicit identity path.
Try it yourself
Closed-book, before checking anything
eps=1e-6. For input [1., 2., 3., 4.], residual [4., 3., 2., 1.] and unit weights, the retained residual is [5., 5., 5., 5.]; RMSNorm is approximately one while centered LayerNorm is zero. Check both buffers through two successive calls. Then merge disjoint online-softmax states from your earlier GPU-track implementation and compare with one dense reduction under its declared tolerance.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Why is averaging two partition outputs wrong?Answer
Their softmax denominators generally differ. Weight each output by its partition's normalizer before dividing by the combined normalizer.
2.Does finite-logit maximum subtraction make every softmax input safe?Answer
No. NaNs, positive infinities and all-masked rows still need a declared policy. A finite nonempty row avoids exponential overflow after subtraction.
3.What must a residual-fusion oracle return?Answer
The updated residual and normalized activation, with the intended cast points, , weight and mutation semantics.
You're done when
Both residual and activation pass independent repeated-call checks, and split-softmax merges match the dense oracle under a stated finite and all-masked policy.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 11 more in the 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.
- 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
- 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.
- 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.
- 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.