xl+1=xl+…\mathbf{x}_{l+1} = \mathbf{x}_l + \dots

Residual connection

The next vector is the current vector plus what the sub-layer computed. Each sub-layer adds a change instead of replacing its input. The subscript l counts sub-layers.

Because each block adds to the stream instead of overwriting it, both information and gradients have a direct path from the first layer to the last.

Where the normalization sits is the Pre-LN versus Post-LN question. Normalizing inside the branch, before the sub-layer, leaves the direct path untouched. Normalizing after the addition puts a normalization on that path at every layer, and deep models built that way usually need a learning-rate warmup to train.

In the Post-LN form, xl+1=LayerNorm⁡(xl+Sublayer⁡(xl))\mathbf{x}_{l+1} = \operatorname{LayerNorm}(\mathbf{x}_l + \operatorname{Sublayer}(\mathbf{x}_l)), the residual addition is still there; it is just normalized afterwards.

Example

xl+1=[1,2]+[0.1,−0.3]=[1.1,1.7]\mathbf{x}_{l+1} = [1, 2] + [0.1, -0.3] = [1.1, 1.7]

The sub-layer's output is a small edit to the vector, not a replacement.

Where the course uses it

Related terms