Unit 6 of 12 · about 3 hours · derive
Memory layout, strides and alignment, and fusion against intermediate traffic
Build on SwiGLU MLP and epilogue fusion boundaries and the earlier KV layout work. A serving optimization must include conversion and dispatch costs, not just the traffic of a convenient contiguous benchmark.
You'll be able to
- Derive physical addresses from strides, storage offsets and element sizes for serving views.
- Count intermediate traffic removed by a legal fusion while retaining required residual outputs.
- Choose a fusion boundary that preserves reduction ownership, cast points and supported layouts.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Physical KV layoutsFlashInfer Documentation
FlashInfer documentation: Layout: NHD/HND and Page Table Layout (page read 2026-10-14, release 0.7.1)
Skip MLA and cascade layouts. Use
plan/runfrom the current API instead of the tutorial's olderbegin_forwardexample. - Sparse gathers and fusion, arXiv:2501.01005v1FlashInfer: Efficient and Customizable Attention Engine for LLM Inference Serving
Sections 3.2.1 and 3.2.3, data movement and transformation functors; Section 4.3, fused versus unfused RoPE evaluation
Read Section 4.3 for its comparison boundary, not the source's hardware-specific speedup as an expected result.
- Outputs that fusion must retainFlashInfer Documentation
Step 1 and Step 2 of
fused_add_rmsnorm(page read 2026-10-14, release 0.7.1)
Focus on
- With element strides , storage offset and element size , byte address is , where is the storage base. Alignment depends on the resulting address, not just allocation alignment.
- A transpose view changes strides without moving data. Making it contiguous performs a copy; include that read/write traffic and allocation when deployment needs it.
- For a materialized intermediate with elements of bytes, removing one write and one read saves requested bytes. That is not a measurement of DRAM traffic after caches.
- Residual fusion still writes the retained sum and normalized activation. A full-row norm cannot generally be fused into one projection tile without coordinating the row reduction.
Common mistakes · 3
- Assuming a view's last dimension is contiguous because the original tensor was contiguous.
- Counting a retained residual write as removed traffic. It is part of the output contract.
- Treating fewer launches as proof of lower latency. Larger fusion can increase register pressure, spills or padding.
Try it yourself
Closed-book, before checking anything
torch.arange(24, dtype=torch.float32).reshape(4, 6)[:, 1::2]. Derive shape [4, 3], element strides [6, 2] and storage offset 1, then verify every element by independent indexing. Explain why this view loses 16-byte base alignment despite an aligned storage allocation. For a hypothetical one-pass residual-add plus norm with both outputs required, derive vector bytes for separate add and norm versus for fusion: two input reads, two output writes and one eliminated reread. State that weights, statistics, repeated loads and cache effects are excluded.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Does changing an NHD tensor's layout label create HND storage?Answer
No. The consumer needs matching dimensions and strides. A real contiguous conversion moves data; a view may be supported only if the kernel accepts its strides.
2.Why is the fused residual example saving only one vector read?Answer
The sum must remain as a residual output. Fusion removes normalization's reread of that sum, but not its write.
3.Can nominal saved bytes predict speedup by themselves?Answer
No. Cache filtering, transaction utilization, launch costs and resource changes determine actual time. The ledger gives a hypothesis to measure.
You're done when
Your address calculation matches the strided view, and your fusion diagram accounts for every required read, write, conversion and reduction boundary.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 12 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.
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.
- 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.
- 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.