Unit 10 of 10 · about 6 hours · measure

Attention baselines, shape matrices, end-to-end translation and losing regimes

Beating materialized attention does not establish a useful optimization. A change must survive strong fused baselines and retain correctness at the full workload boundary.

You'll be able to

  • Benchmark prefill and decode separately against eager, compiled and supported production attention baselines.
  • Explain residuals across a shape/dtype/mask/layout matrix and preserve losing or unsupported regimes.
  • Translate a local change into full-block and request-level latency, memory and goodput evidence without confusing those boundaries.

Covers

Compiler, framework and production attention-library baselinesSequence, head, batch, mask, dtype and alignment matrixKernel gain translated to TTFT, TPOT, memory and goodputSmall, decode-heavy, irregular and unsupported losing regimes
1

Read

In this order, only the parts listed

0 of 4 done

  1. CS336 compiled and custom attention benchmarksCS336 Assignment 2 - Section 4 FlashAttention-2 in Triton

    Problems pytorch_attention (p. 16), torch_compile (pp. 16 to 17), and flash_benchmarking (p. 28)

    Replace the B200 sweep with a sweep that fits your GPU's memory. On a 6 GB GPU, use batch size 1, widths 32 and 64, and sequence lengths 128, 256, 512 and 1024. On a 24 GB GPU, grow the sequence range only after budgeting reference intermediates and backward workspace. Keep allocation failures in the report rather than forcing them.

  2. PyTorch SDPA dispatch and full-module comparisonPyTorch SDPA contracts and integration tutorial

    Documentation read 2026-10-13: Explicit Dispatcher Control, Hardware dependence, Causal Self Attention and Using SDPA with torch.compile

    Shrink the tutorial's large tensors before running. Correct CausalSelfAttention.forward: evaluation disables dropout, not causality. Preserve self.is_causal in evaluation for full-sequence causal attention. Use PyTorch 2.14's API contract rather than treating the tutorial's backend list as exhaustive. Skip NestedTensor.

  3. Request latency boundaries and load patternsvLLM serving latency and goodput definitions

    vLLM v0.31.0: Understanding the Latency Metrics and Load Pattern Configuration

    Read the metric and workload definitions only. Do not run the large-model serving examples in this unit.

  4. Goodput service-level objectivesvLLM serving latency and goodput definitions

    vLLM v0.31.0: Arguments, the descriptions of goodput service-level objectives, request rate and maximum concurrency

    Use the definitions, not a required CLI run. Full production-engine integration belongs to the next section.

2

Focus on

  • Compare the dense correctness oracle, eager SDPA, compiled full block and a supported pinned FlashInfer path separately. Record the actual selected backend, its workspace and any fallback. Failure to support a case is not a zero-latency result.
  • Start with prefill and one-row decode, then vary batch, sequence, head width, GQA ratio, causal/padding/custom masks, dtype, strides and tile alignment. Include tiny, odd-length and irregular cases; hold some shapes out from tuning.
  • Warm up compilation and allocator state outside steady-state trials. Interleave variants, retain raw samples and report medians with uncertainty. Profile separate runs; use timelines and compiled resource reports to explain losses rather than infer a bottleneck from achieved bandwidth alone.
  • Translate local latency using the changed critical-path share. Request TTFT includes more than prefill attention; TPOT excludes the first token and averages remaining request time. Define goodput as successful requests meeting predeclared latency objectives per unit observation time, with the same tokenizer, outputs and arrival workload.
Common mistakes · 3
  • Benchmarking against only an unfused dense reference. It is an oracle and explanatory baseline, not the strongest performance competitor.
  • Calling a block's event duration TTFT or goodput. Request metrics need request boundaries, output validation, a workload and service-level objectives.
  • Improving tokens per second by changing output length, prefix-cache state or quality. Keep those controls fixed, report cache state, and count only validated requests as successful.
3

Try it yourself

Closed-book, before checking anything

Derive the serial fixed-workload bound , where is the baseline time share of the replaced operation and its local speedup, with all other work unchanged. A hypothetical 20% share and twofold local speedup give , approximately 1.111, not twofold. Then substitute measured full-block shares and compare the prediction with your bounded prefill/decode runner. Label runner TTFT/TPOT separately from HTTP endpoint metrics.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Can reducing peak attention workspace increase serving capacity without reducing one request's latency?Answer

    Yes. It can allow a larger batch or more cached requests. That is a separate capacity experiment; it does not establish lower latency at the original fixed workload.

  2. 2.Why can mean inter-token latency differ from mean request TPOT?Answer

    They weight observations differently, and one streamed output can bundle several tokens. TPOT amortizes each request's post-first-token duration over its remaining tokens; inter-output gaps are separate observations.

  3. 3.A custom kernel loses on tiny decode. Is that evidence the implementation is wrong?Answer

    Not by itself. Launch, merge or dispatch overhead may exceed useful work. First validate correctness, then keep the losing case and choose a measured fallback.

  4. 4.What should you do if a strong baseline wins every tested regime?Answer

    Report the negative result and keep that baseline as dispatch. Do not claim the section's end-to-end gain gate passed; identify a narrower measured bottleneck or leave that gate outstanding.

5

Practice

  • CS336 Assignment 2: flash_benchmarking

    Problem flash_benchmarking (p. 28), using the reduced sweep above

    Gate each variant on the public attention tests and your own edge tests before timing. Use only forward timings if you skipped the optional backward unit, and say so. Add eager SDPA and the compiled full-block baseline rather than only the handout's materialized PyTorch baseline. The section mini-project covers the expanded shape matrix, supported FlashInfer comparison or documented compatibility blocker, full-runner integration, request-metric translation and a retained losing regime.

You're done when

Your report links correctness tests, raw trials, selected backends and profiles to one full-runner comparison and one losing regime, with TTFT/TPOT and goodput boundaries stated. If no end-to-end gain survives strong baselines, mark that section gate outstanding instead of inventing a gain.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 10 more in the section
  • CS336 Assignment 2 - Section 4 FlashAttention-2 in TritonStanford University · required

    Do the weighted-sum warm-up, then flash_forward (a PyTorch tiled version and the Triton kernel) and flash_backward against tests/test_attention.py. Run flash_benchmarking on sizes that fit your GPU instead of the handout's B200 sweep.

  • PyTorch SDPA contracts and integration tutorialPyTorch · reference

    The PyTorch 2.14 SDPA API page gives mask polarity, rectangular causal alignment, GQA and backend limitations. The SDPA tutorial (https://docs.pytorch.org/tutorials/intermediate/scaled_dot_product_attention_tutorial.html, read 2026-10-13) gives Explicit Dispatcher Control, Causal Self Attention, Using SDPA with torch.compile and Using SDPA with attn_bias subclasses. Correct the tutorial's evaluation-time causal flag before integration.

  • vLLM serving latency and goodput definitionsvLLM Project · reference

    vLLM v0.31.0: Benchmark CLI, Understanding the Latency Metrics and Load Pattern Configuration; serving benchmark CLI, goodput service-level objectives. Use definitions to translate kernel evidence into request metrics, not as a required serving-engine installation.

Also in this section

  • FlashAttentionTri Dao and collaborators · primary

    Read the IO-awareness argument, exact attention algorithm and complexity analysis. Derive the online state and block dataflow, then implement a reduced forward kernel or trace a trusted implementation across at least causal and noncausal cases.

  • FlashAttention-2Tri Dao · required

    Study reduced non-matmul work, sequence parallelism and warp work partitioning. Compare the schedule with the first paper and predict which shapes benefit before checking measurements.

  • Online Normalizer Calculation for SoftmaxOnline Softmax Authors · required

    Re-derive the recurrence inside tiled attention and prove rescaling correctness. Add extreme-logit, all-masked, odd-head and partial-tile tests before any performance comparison.

  • TensorTonic Language Modeling from Scratch - Blockwise Online SoftmaxTensorTonic · support

    Solve it before the tiled attention kernel as a check on the rescaling recurrence.

  • LeetGPU - Attention and Transformer ChallengesAlphaGPU · required

    Solve 6 Softmax Attention and 12 Multi-Head Attention or 53 Causal Attention. Then choose two of 50 RMS Normalization, 54 SwiGLU, 61 RoPE, 80 Grouped Query Attention, 83 Fused Residual Add RMS Norm and 84 SwiGLU MLP Block. Keep correctness tests beyond the hosted score.

  • FlashInferFlashInfer Project · support

    Inspect the attention, sampling and serving-kernel interfaces. Reconstruct one dispatch path and compare its layout and workspace contracts with your reduced kernel instead of copying the optimized implementation.

  • GPU MODE - Attention and Fused KernelsGPU MODE · support

    Use Lectures 12, 13, 18, 36 and 40 for FlashAttention, Ring Attention, fusion, FlashAttention-3 and FlashInfer. Reproduce one schedule or fusion idea under the stage shape matrix and a strong baseline.

  • FlashAttention-3FlashAttention Authors · depth

    Study Hopper-specific asynchronous execution and low-precision design after the portable kernel. Implement only with the required architecture, and separate algorithmic from hardware-specific gains.

  • Modern GPU Programming for MLSys - Flash Attention 4MLC · depth

    Read the complete Blackwell attention chapter, including two MMAs, online softmax, causal masking and GQA. Run it only on compatible sm_100a hardware with the pinned TIRx stack; otherwise use the code for architecture reconstruction.

  • Triton 3.8.0 Layer NormalizationTriton Project · required

    Motivations and _layer_norm_fwd_fused in tutorial 05, pinned to v3.8.0. Study centered variance, float32 reductions, valid-column masks and the forward wrapper's supported-width guard. Defer backward and the benchmark sweep.