4.1.9 · D1Transformer Architecture

Foundations — Residual connections and layer norm placement

2,251 words10 min readBack to topic

This page assumes you have seen none of the notation used in the parent note. We build every symbol from the ground up, in an order where each piece leans only on pieces already built.


1. What is a "vector of activations"? The symbol

Everything in a Transformer travels as a list of numbers. When we write , we mean one such list attached to one word (one token).

Figure — Residual connections and layer norm placement

Why the topic needs it. Residual connections add two of these lists together, and layer norm rescales one of these lists. Until you picture as a bar-chart of dials, none of the later operations mean anything.

  • The subscript ::: picks out the value on dial number inside one vector
  • ::: how many features (dials) the vector has — the "width" of the model

2. A "sublayer" and the symbol or

Inside each floor of the tower sits a machine that takes in and produces a new list of the same length. In the parent note this machine is written or .

Notation warning. The parent uses three names for the same idea:

symbol meaning
generic sublayer in the math derivations
the same thing spelled out in words
, the two concrete choices for
  • Why can we write at all ::: because returns a vector of the same length as

3. The plus sign that changes everything: the residual

Figure — Residual connections and layer norm placement

Why the topic needs it — the ONE reason. Recall from the opening callout that a learning arrow (the gradient) has to travel backward through the tower. The around road hands that arrow back untouched. Look at the figure: the arrow can always take the skip road home even if the road is broken. This is the "gradient highway" the whole topic is about (deepened in 5.1.03-Gradient-flow-in-deep-networks).

  • The word "skip" refers to ::: the copy of that goes around instead of through it

4. Mean, variance, and the symbols , ,

Before we can define layer norm we need three plain-arithmetic ideas about a single vector .

First, one piece of shorthand we are about to use. The symbol just means "add up, letting run from to ." It is nothing more than written compactly. Keep that in mind for the next two definitions.

Figure — Residual connections and layer norm placement
  • Why we subtract inside the variance ::: to measure spread relative to the center, not relative to zero
  • What tells you in one phrase ::: the typical size of a feature's deviation from the mean

5. Putting it together: LayerNorm and , , ,

Let us earn every new symbol here:

symbol plain words picture
slide all bars down until they balance at zero bars re-centered on the axis
the spread (with a tiny safety number) the width we divide by
now bars have unit spread a "standardized" bar-chart
tiny constant, e.g. guards against dividing by when
learnable scale, one per feature how tall each bar is allowed to grow
learnable shift, one per feature where each bar's baseline sits
multiply element-by-element dial times , no mixing
  • What and let the model do after standardizing ::: re-stretch () and re-shift () each feature, so normalization does not force mean 0 / std 1 if the model prefers otherwise
  • What breaks if and all features are equal ::: division by zero, because

6. The two placements — the whole point of the parent note

Now that and both mean something, the only remaining choice is the order. The parent note calls these Post-LN and Pre-LN.

Here we finally meet the floor subscript . As warned in §1, this is not a feature number — it is the number of the floor in the tower. So is the whole vector arriving at floor , and is the whole vector leaving for the next floor up. (Inside any one of these vectors the individual dials are still , but we won't need that detail.)

  • In Pre-LN, is the residual stream ever normalized ::: no — LayerNorm sits only inside the branch, so the highway is untouched
  • The subscript in means ::: which layer/floor of the tower we are on (a whole vector) — not a single feature

How these foundations feed the topic

Read this as a bottom-up build order. Each item uses only the ones above it, and the last line is the parent topic itself:

  1. Activation vector (§1) — the list of dials everything is made of.
  2. Sublayer (§2) — leans on §1: it eats a vector, returns a same-length vector.
  3. Residual (§3) — leans on §1 and §2: only possible because lengths match; it builds the gradient highway.
  4. Mean and variance (§4) — lean on §1: pure arithmetic on the dials.
  5. LayerNorm (§5) — leans on §4: uses to standardize, then to rescale; keeps numbers sane.
  6. Placement: Post-LN vs Pre-LN (§6) — leans on §3 and §5: it is nothing but the choice of where to slot LayerNorm relative to the residual — which is exactly the parent topic.

The gradient consequences of that choice connect onward to 5.1.03-Gradient-flow-in-deep-networks, 6.2.05-Layer-scaling-and-initialization and 4.2.02-Training-stability-and-convergence.


Equipment checklist

  • I can read as a bar-chart of dials ::: yes — each is one dial's height
  • I can say in one line what the "learning signal / gradient" is ::: a little arrow per dial saying turn-up-or-down and by how much, passed backward down the tower
  • I know why is even allowed ::: because returns a same-length vector, so addition makes sense
  • I can compute and of a small vector by hand ::: mean = average of features; variance = average squared distance from the mean
  • I can state what , , , each do in LayerNorm ::: scale, shift, divide-by-zero guard, element-wise multiply
  • I can tell Post-LN from Pre-LN by looking at where sits ::: Post-LN wraps the whole sum; Pre-LN wraps only the input to , leaving the skip road clean
  • I know the difference between (a feature) and (a whole layer's vector) ::: is one dial inside a vector; is the entire vector at floor
  • I know the failure case that forces ::: a flat vector where every feature is equal, giving