notes
← back to notes

Attention residuals for better depth utilization

problems with residual connections & pre-norm

Standard residuals

With regular residual blocks, the magnitude of the hidden layers can keep growing with every layer as it gets deeper.

$$h_2 = h_1 + f_1(h_1)$$

$$h_3 = h_1 + f_1(h_1) + f_2(h_2)$$

$$h_4 = h_1 + f_1(h_1) + f_2(h_2) + f_3(h_3)$$

$$h_L = h_l + \sum_{i=l}^{L-1} f_i(h_i)$$

Pre-Norm

Post-LN vs Pre-LN transformer block diagrams

But even with pre-norm the residual connections cause the residual stream to increase in magnitude. Why?

But why do we still use pre-norm instead of post-norm then?

Attention residual

$$h_2 = \alpha_{0 \to 2} \cdot h_1 + \alpha_{1 \to 2} \cdot f_1(h_1)$$

$$h_3 = \alpha_{0 \to 3} \cdot h_1 + \alpha_{1 \to 3} \cdot f_1(h_1) + \alpha_{2 \to 3} \cdot f_2(h_2)$$

How does Attention residual help reduce pre-norm dilution?

Block Attention Residual