Residual Connection

A residual connection adds a module output back to its input. It helps deep networks preserve information and makes optimization easier.

The residual stream is the running representation that every block reads from and writes back to. The branch is an update, not a replacement:

In a pre-norm Transformer block:

Here is multi-head attention, is layer normalization, and is a token-wise feed-forward network.

Why It Matters

  • Gradients can flow through the identity path.
  • Deep models can learn small refinements instead of replacing representations at every layer.
  • Residual paths require matching tensor shapes.

Gradient View

For a block:

the Jacobian is:

The identity term gives gradients a direct route through the network. This does not guarantee stability, but it reduces the need for every layer to preserve information through a nonlinear transformation.

For a deep stack:

so residual networks can be read as iterative refinement of a shared representation.

Shape Contract

Residual addition requires the branch output to match the residual stream:

If a block changes width, resolution, node count, or coordinate type, the skip path needs a projection:

where may be a linear layer, convolution, pooling, or graph-compatible projection.

For coordinate or equivariant features, residual addition is only valid between objects with the same transformation type. A scalar invariant feature and a vector equivariant feature should not be added directly.

Variants

VariantFormUse
plain residualstandard residual block
scaled residualcontrol activation growth in deep networks
gated residualadaptive update strength
projected residualshape or channel changes
stochastic depthrandomly drop during trainingregularization for deep models

In papers, changes to residual scaling or gating can be as important as the named architecture family.

Stability Boundary

Residual branches can still grow too large. Deep models often combine residuals with:

StabilizerRole
normalizationcontrols branch input or output scale
residual scalingreduces update magnitude
careful initializationstarts blocks near identity
dropout or stochastic depthregularizes branch updates
gradient clippinghandles occasional large updates

For scaled residuals:

small keeps early updates close to identity. Some architectures learn or schedule .

Checks

  • Confirm that dimensions match before addition.
  • Check whether residual branches are scaled, gated, or dropped.
  • Distinguish residual addition from concatenation.
  • Watch hidden-state magnitude growth in very deep networks.
  • Check whether the residual stream represents tokens, nodes, pixels, residues, or coordinates.
  • For equivariant models, confirm the residual path adds features of the same representation type.
  • Check whether residual scaling, gating, or stochastic depth changes between train and inference.
  • Check whether projection shortcuts change the claim by mixing or downsampling the input.