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

Stable and online softmaxNormalization and fused residual paths
1

Read

In this order, only the parts listed

0 of 3 done

  1. 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.

  2. 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)

  3. Residual ownership in the model pathMini-SGLang - Kernel, Model Runner and Overlap Boundaries

    RMSNormFused.forward, including the absent-residual branch

2

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.
3

Try it yourself

Closed-book, before checking anything

Closed-book, implement a CPU double-precision residual/RMSNorm reference with 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.
4

Quiz yourself

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

0 got · 0 missed

  1. 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. 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. 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