research26 min studyLesson 751 in Engineering

Merge normalized attention without averaging tile outputs

Derive stable running summaries, their rescaling law, and an explicit empty-row contract.

On this page

What you’ll understand

  • Derive a merge of maximum, exponential mass, and weighted-value sum.
  • Explain why separate normalized outputs cannot simply be averaged.
  • Handle empty blocks and entirely masked rows without undefined arithmetic.

A softmax row couples every allowed key through one normalization denominator. Splitting that row into tiles does not remove the coupling, but it can replace a stored probability row with a small mergeable summary. For each tile, retain a score maximum, an exponential mass measured relative to that maximum, and a similarly scaled weighted-value sum. Merging requires converting both summaries to a common scale. This algebra is the foundation of exact tiled attention and split-key reductions; the challenge is preserving normalization, not approximating distant keys or declaring one tile more important because it was processed later.

A summary carries its scale

Let scores be finite dimensionless numbers on the allowed positions of one row, with one value vector per score. Subtracting the row maximum before exponentiation keeps every exponential at most one, avoiding overflow from large positive scores. The numerator is a vector, while the denominator is a scalar. Dividing them gives a weighted average in the same units as the values. Storing only that average discards how much exponential mass supported it.

Two tiles can each produce a normalized output of ordinary magnitude while their total masses differ by orders of magnitude. An unweighted average of those outputs therefore assigns the wrong influence to their keys. Even a mass-weighted average needs masses expressed relative to the same maximum. This is why the maximum belongs in the summary: it is the reference level that makes the other two fields interpretable, rather than an optional diagnostic statistic.

mA=max⁡j∈Asj,ℓA=∑j∈Aesj−mA,zA=∑j∈Aesj−mAvjm_A=\max_{j\in A}s_j,\qquad \ell_A=\sum_{j\in A}e^{s_j-m_A},\qquad z_A=\sum_{j\in A}e^{s_j-m_A}v_j
A is a nonempty set of allowed key indices, sj∈R is dimensionless, and vj∈R^dv is finite. mA and ellA are scalars; zA has dv components and value units. ellA>0, so the normalized row output is zA/ellA.↔ Scroll wide equations horizontally.

Merge by moving to the larger reference level

For disjoint nonempty tiles, choose the larger maximum and multiply each mass and weighted numerator by the exponential of its old maximum minus the new maximum. Both rescaling factors lie between zero and one. Add the rescaled masses and numerators, then normalize once. Expanding the definitions shows this is the same sum that would have been formed over all allowed keys at once. In exact arithmetic, grouping or ordering these merges does not change the answer.

Floating-point execution changes the reduction order, so exact attention here means the same mathematical operator rather than bitwise identity. A tree reduction, sequential tile loop, and materialized softmax can round differently. Keep sufficiently accurate accumulation and compare errors against a higher-precision reference. Large score differences can underflow tiny contributions; the stable maximum subtraction addresses overflow but cannot promise that every real-number contribution survives a finite numerical format.

m=max⁡(mA,mB),α=emA−m,β=emB−m,ℓ=αℓA+βℓB,z=αzA+βzB,o=z/ℓm=\max(m_A,m_B),\quad \alpha=e^{m_A-m},\quad\beta=e^{m_B-m},\qquad \ell=\alpha\ell_A+\beta\ell_B,\quad z=\alpha z_A+\beta z_B,\quad o=z/\ell
A and B are disjoint nonempty tiles of the same row. All scores are finite; ell>0. The formula merges scalar masses and vector numerators in one common dimensionless exponential scale. It does not average separately normalized tile outputs.↔ Scroll wide equations horizontally.

Empty is a control-flow case

A fully masked tile contributes no keys. Represent it as an explicit empty summary with zero mass and zero numerator, and let merging an empty summary return the other summary unchanged. A sentinel maximum of negative infinity can be useful, but evaluating negative infinity minus negative infinity creates NaN. Branch around the both-empty case instead of assuming a later multiplication by zero will repair undefined intermediates. Masked logits are exclusions, not large finite negative guesses.

If the entire row is masked, the usual normalized softmax expression has zero denominator and no probability distribution. Specify an extension such as zero output, or reject the input, and make forward and backward implementations agree. FlashAttention 2.8.3 documents zero output for its all-masked causal rows; another API must be checked independently. This explicit policy also matters when a sparse pattern, ragged batch, or unequal query/key alignment creates empty rows unexpectedly.

Two scaled tiles form one weighted average

Use scores (0, ln3, ln2, ln6) with scalar values (2,4,−1,3). Tile A contains the first two entries and tile B the last two. Form stable summaries and merge them without materializing the four probabilities.

  1. Tile A has maximum ln3, mass 1/3+1=4/3, and numerator 2/3+4=14/3. Tile B has maximum ln6, mass 1/3+1=4/3, and numerator −1/3+3=8/3. Each mass is measured on its own maximum scale.

  2. The combined maximum is ln6. Rescale A by exp(ln3−ln6)=1/2 and B by 1. The merged mass is (1/2)(4/3)+4/3=2, and merged numerator is (1/2)(14/3)+8/3=5.

  3. Normalize once to get 5/2=2.5. A direct check uses original exponential weights (1,3,2,6): weighted sum 2+12−2+18=30 and denominator 12, also giving 2.5.

The result

The merge preserves the global denominator. A’s normalized output is 3.5 and B’s is 2, whose unweighted average 2.75 would be wrong.

Explore the model

Interactive lab

Interactive lab · network

Two-score softmax is a sigmoid of their difference

Reset, set Input x to 0.5 and Weight w to 1. Predict logit wx−0.5=0 and output 0.5 before Step. Reset, set x to 1.5 and w to 1, predict logit 1 and output approximately 0.731059 before Step. These are probabilities for the second entry of two logits (0,0) and (0,1). The instrument is one fixed-bias sigmoid, not a tiled attention implementation.

Two-score softmax is a sigmoid of their differenceOne inspectable sigmoid unit, σ(wx − 0.5). Playback traces the computation graph. There is no training, attention mechanism or hidden deep network. Current readings: Product · wx: 1.2; Logit · wx − 0.5: 0.7; Sigmoid output: 0.6682. All parameters are adjustable with the labeled controls below.One input. One weight. One sigmoid.x1.20× w1.20+ b0.70σ0.668output0.668w = 1.00b = −0.50σ(z) = 1 / (1 + exp(−z))
Computation graphSignal trace
Product · wx
1.2
Logit · wx − 0.5
0.7
Sigmoid output
0.6682
t = 0 s

One inspectable sigmoid unit, σ(wx − 0.5). Playback traces the computation graph. There is no training, attention mechanism or hidden deep network. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forNormalization depends on score differences; the toy checks only the two-score special case.

Check your understanding

What is required when merging two nonempty stable attention summaries?

Try it yourself

One valid tile has maximum 0, mass 2, and numerator 6. Merge it with an empty tile, then state the output if both tiles are empty under a declared zero-output extension.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Use the empty-summary identity rather than exponentiating a difference of sentinel infinities.

Compare with the solution

The empty tile contributes no keys, so the valid summary stays (0,2,6) and its output is 6/2=3. If both tiles are empty, the zero-output extension returns 0 through an explicit empty-row branch. It does not evaluate 0/0 or exp(−∞−(−∞)); the branch is part of the specified operator extension.

Take it with you

  • Maximum, mass, and weighted numerator form the mergeable state.
  • Rescale before combining independently normalized tiles.
  • Define empty-tile identity and all-masked output explicitly.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.