Attention & Transformers

Residual Connections & Skip Connections

Why deep networks can keep useful features alive: each layer learns a correction to the identity instead of rewriting the whole representation from scratch.

status: reviewimportance: importantdifficulty 3/5math: undergraduateread: 14mdemo planned

Concept Structure

Residual Connections & Skip Connections

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

1prerequisites
2next concepts
3related links

Learning map

Residual Connections & Skip Connections
BeforeScaled Dot-Product Attention & Transformer LayersNow3/4 sections readyTryUse the demo notes to predict the mechanism before moving on.NextLayer Normalization & RMSNorm

Object flow

3/4 sections readyAsk about thisResearch room
ConceptResidual Connections & Skip ConnectionsAttention & Transformers
Local snapshot ready
concept:attention-transformers/residual-connections

Conceptual Bridge

What should feel connected as you move through this page.

Carry inScaled Dot-Product Attention & Transformer Layers

Bring the mental model from Scaled Dot-Product Attention & Transformer Layers; this page will reuse it instead of restarting from zero.

Work hereResidual Connections & Skip Connections

Why deep networks can keep useful features alive: each layer learns a correction to the identity instead of rewriting the whole representation from scratch.

Carry outLayer Normalization & RMSNorm

The next edge should feel earned: use the demo prediction here before following Layer Normalization & RMSNorm.

Test the linkUse the demo notes to predict the mechanism before moving on.Then continue to Layer Normalization & RMSNorm
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

Without a skip connection, a deep layer has to reinvent the whole representation it receives.

That is a hard optimization problem. If the best thing a layer could do is "mostly keep what already works, and add a small correction," a plain stack has no easy way to express that.

Residual connections make that easy. Instead of asking a layer to learn a full map xyx \mapsto y, we ask it to learn a delta:

y=x+F(x).y = x + F(x).

Now the safe default is clear:

  • if the layer has nothing useful to add, it can make F(x)0F(x) \approx 0,
  • if it has a useful feature, it writes that feature on top of the existing state,
  • the block provides an additive identity path for the current representation, even though later normalization, nonlinearities, finite precision, and downstream updates can still change or overwrite information.

In transformers, this becomes the residual stream mental model: attention and MLP blocks both read the current state, write an update, and pass the shared stream onward.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Let xRdx \in \mathbb{R}^d be the input to a block and let F:RdRdF: \mathbb{R}^d \to \mathbb{R}^d be the learned update. A residual block outputs

y=x+F(x).y = x + F(x).

The Jacobian of this mapping is

yx=I+JF(x),\frac{\partial y}{\partial x} = I + J_F(x),

where II is the identity matrix and JF(x)J_F(x) is the Jacobian of FF.

That identity term matters for optimization. Across many layers,

h(+1)=h()+F()(h()),h^{(\ell+1)} = h^{(\ell)} + F^{(\ell)}(h^{(\ell)}),

so backpropagation multiplies matrices of the form I+JF()I + J_{F^{(\ell)}}. Even if the learned part is small or noisy, there is still a direct gradient path through the identity.

For a pre-norm transformer layer, a common pattern is

h=h+Attn(LN(h)),h' = h + \operatorname{Attn}(\operatorname{LN}(h)), hnext=h+MLP(LN(h)).h_{next} = h' + \operatorname{MLP}(\operatorname{LN}(h')).

This says each sublayer writes an update into a shared stream rather than replacing the stream entirely.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
import numpy as np

rs = np.random.RandomState(0)
d = 128
x0 = rs.randn(d)

def run(depth=40, residual=True, alpha=0.2):
    h = x0.copy()
    norms = []
    for _ in range(depth):
        W = rs.randn(d, d) / np.sqrt(d)
        update = np.tanh(W @ h)
        h = h + alpha * update if residual else update
        norms.append(np.linalg.norm(h))
    return norms

plain = run(residual=False)
resid = run(residual=True)

print("plain layer-1/layer-40:", round(plain[0], 3), round(plain[-1], 3))
print("resid layer-1/layer-40:", round(resid[0], 3), round(resid[-1], 3))

Residual connections do not magically solve every instability, but they give optimization a much safer default: keep the current representation unless there is a good reason to change it.

04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

No interactive demo yet for this concept. A strong next step would be a residual-stream sandbox that toggles skip connections on and off, then shows signal norms and gradient flow across depth.

No live visualization is registered for this concept yet.

The page still supports explanatory demo notes above; when a viz.tsx exists, it will render here without changing the route.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

Why deep networks can keep useful features alive: each layer learns a correction to the identity instead of rewriting the whole representation from scratch.

Demo notes open01 / Intuition
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Residual Connections & Skip Connections should make visible.

Visual Inquiry

Make the image answer a mathematical question

Why deep networks can keep useful features alive: each layer learns a correction to the identity instead of rewriting the whole representation from scratch.

3/4 stages readyDemo notes connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Residual Connections & Skip Connections easier to reason about before the page gives the answer.

Claim Review

Why deep networks can keep useful features alive: each layer learns a correction to the identity instead of rewriting the whole representation from scratch.

StatusSubstantive claim review pending

Source IDs and witness objects are attached for review; they are not proof by themselves.

SourcesNo references

Add source metadata before claiming support.

Witnesses3 local objects

Use equation, code, and demo objects to check whether the source support is operational.

Practice Loop

Try the idea before it explains itself

Why deep networks can keep useful features alive: each layer learns a correction to the identity instead of rewriting the whole representation from scratch.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Residual Connections & Skip Connections.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Object research drawerClose
ConceptResidual Connections & Skip ConnectionsAttention & Transformers

Research Room

Attach the question to an exact object

Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptAttention & Transformers

Residual Connections & Skip Connections

Anchored question

What is the smallest example that makes Residual Connections & Skip Connections click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays locally in this browser for concept:attention-transformers/residual-connections.

No local draft saved.
Evidence to inspect
  • Definition, prerequisite, and contrast concept links
  • The equation or code witness that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Residual Connections & Skip Connections Object key: concept:attention-transformers/residual-connections Context: Attention & Transformers Anchor id: concept/concept-notebook/attention-transformers/residual-connections Open question: What is the smallest example that makes Residual Connections & Skip Connections click without losing the math? Evidence to inspect: - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

Open source object
concept/concept-notebook/attention-transformers/residual-connections concept:attention-transformers/residual-connections