Neural Networks
Skip / Residual Connections
An activation receives the signed sum of every outgoing reverse path; an identity contribution does not bound the total gradient away from zero.
2 scalar steps, skip connections off, two-step, linear branch. x=1, shared w=0.9, supplied u=1. Post-add identity. Output=0.810000; input adjoint=0.810000. Inspect a0.
2 scalar steps, skip connections off, two-step, linear branch. x=1, shared w=0.9, supplied u=1. Post-add identity. Output=0.810000; input adjoint=0.810000. Inspect a0.
All current settings remain active at every stage: two-step; shortcuts Off; branch linear; w=0.9; supplied u=1.
Input a0=x=1; no incoming block.
- Activation node
- Branch (straight; dashed if local derivative negative)
- Shortcut (arched)
What exact computation produced this activation?
Each step multiplies the preceding activation by shared w, applies the branch activation, then adds the stated shortcut. The post-addition map is identity.
Branch
The computed f(w·a) contribution, distinct from the shortcut and addition.
Check this stage
Check your understanding
Inspect how scalar branches and shortcuts add signed gradient contributions, including exact cancellation and amplification.
What a shortcut contributes
A skip connection adds another route through the computation. Reverse differentiation sums the signed contributions from all real routes. An identity route contributes its downstream signal unchanged, but that does not guarantee that the total gradient stays large or nonzero.
Start with Forward graph. Select an activation in the graph or use Inspect activation. Read its branch input, product, branch output, shortcut and addition separately. Every step uses the same scalar parameter . There is no bias. The branch activation is linear by default; the final stage also offers tanh. After addition the map is identity, with derivative one.
This is a deterministic derivative experiment. It has no target, loss, optimiser, parameter update or training history. The output adjoint is supplied, initially one. Calling an input-activation adjoint an early-layer parameter update would confuse two different derivatives.
The two graphs are different
The retained Two-step graph has input and branch . With skips on:
The shortcut into step starts at , not at the branch input . Consecutive shortcuts overlap. These are not separate canonical two-layer ResNet blocks.
In Identity blocks, every block has one boundary from to . Its branch and shortcut share the same input:
Skips Off removes the shortcut additions in either topology. The paired plain readout holds input, depth, shared parameter, branch activation and supplied upstream signal fixed. Removing shortcuts changes the represented function and downstream activations. It is not a matched training-success experiment, nor does it hold every nonlinear branch operating point fixed.
Follow the actual reverse accumulation
Open Reverse accumulation. We initialise and all other adjoints to zero. Visit destinations in reverse order. Each branch returns
Each real shortcut also returns to its stated source: in the two-step graph or in identity blocks. Both paths must be counted exactly once. Inspect a selected activation to see its outgoing paths, local Jacobians, downstream signals, signed contributions and accumulated sum. At the output, the signal is supplied rather than accumulated from outgoing paths.
For a hand check, use depth two, , , linear branch and . Plain activations are and adjoints are . The two-step shortcut changes the output to and the input adjoint to : branch contribution plus shortcut contribution .
The local parameter derivative at occurrence is . Because is shared across steps, its total adjoint is
That is distinct from , the input adjoint. The drawer also retains unscaled input tangents , which remain meaningful when supplied . No update is applied to .
Identity is a contribution, not a guarantee
For a genuine identity residual block , the total Jacobian is . For column adjoints, reverse propagation is
In this scalar identity-block experiment the local total is . The identity contribution is one; the total need not be one.
In Cancellation and scale, choose Cancel the identity. Linear gives , so branch derivative cancels identity derivative . Select the activation before the final block to inspect two nonzero returning contributions that sum to zero. A nonzero identity path supplies no unconditional lower bound on the norm of the total gradient.
Next use linear , skips On, identity blocks and depth ten. The total input derivative is with . Large gradients can amplify; they are not automatically healthy. Set : identity blocks pass the input through, whereas the two-step graph alternates and zero. Zero branch output at one input is not, in general, proof of zero branch derivative everywhere.
With tanh, inspect . Saturation can make the branch slope small. Double-precision endpoint rounding may make it exactly zero. Readout rounding is a display choice, not evidence of underflow or permanent inability to learn. Bounded finite controls do not manufacture a numerical-failure threshold. Nonfinite arithmetic is a separate computational condition.
What this says about ResNet
The original residual-learning paper studies residual parameterisation in actual trained architectures. Its original block has a ReLU after addition. In that case the complete Jacobian is , and a negative pre-activation can block the apparent identity route. The identity-mapping paper analyses shortcut and after-addition maps separately and motivates pre-activation units. Moving activations inside the branch does not make the branch linear.
This lab has no post-addition nonlinearity, projection, shortcut scaling or dimension change. A projected shortcut would contribute , so the total before any post-add map would be and reverse mode would transpose that total. Matching dimensions is necessary for addition; projection is one architectural option rather than an identity guarantee.
Residual parameterisation can ease optimisation in studied settings. It does not completely solve vanishing gradients. Depth, representational capacity, optimisation success and generalisation are different questions. In particular, stacking scalar linear branches still produces a scalar linear map; more depth here does not demonstrate richer nonlinear capacity.
Read the display and restore the experiment
Straight lines are branches; arches are shortcuts. Negative branch Jacobians use dashes as well as signed numbers. Nodes and labels paint above connections. Positions illustrate connectivity, not activation magnitude. Widths have a structural minimum and a display cap; compressed layouts omit node labels rather than shrinking their text. Metrics round; Under the hood preserves raw double values, all steps, all edges and all accumulated adjoints. There is no sampled field, geometric projection or clipping of the computation.
Earlier stages retain all active settings even when some controls are introduced later. Inspection changes only the selected activation. Mathematical, stage and mode edits clear predictions; inspection preserves them. Restore experiment restores settings, selection, stage, sandbox and prediction after later edits. Reset retains the guided stage, restores defaults, returns guided and clears guesses and recovery. Shared links recompute all settings, selection and display stage in guided mode; they exclude guesses, recovery and local progress.
Try the retained depth-ten challenge. With , linear branch and skips Off, for . Turning on two-step shortcuts adds real paths and changes both the function and derivative. Neither number establishes training success.
Stage recap
Forward graph
Each step multiplies the preceding activation by shared w, applies the branch activation, then adds the stated shortcut. The post-addition map is identity.
Reverse accumulation
Start with supplied output adjoint u. Multiply by each real local Jacobian and add contributions at reused activations. No loss or update is computed.
Shortcut endpoints
Two-step shortcuts add aᵢ₋₂ to f(w·aᵢ₋₁), overlapping neighbouring steps. Identity blocks instead add aᵢ₋₁ at every step: their local total is 1 + w f′.
Cancellation and scale
Yes. For identity blocks F(x)=−x, the branch derivative −1 cancels +1. Positive factors above one can amplify gradients. Neither magnitude certifies training health.
Reference
- Reverse accumulation
- gᵢ is the sum of outgoing local-Jacobian × downstream-adjoint contributions; gᴰ=u is supplied.
- Identity block
- y=x+F(x); total J=I+J_F. Reverse mode applies Jᵀ to the output adjoint.
- Shared parameter
- Sum every occurrence derivative for w. An input-activation adjoint is not a parameter update.
- ResNet scope
- This scalar model has no convolution, projection, normalisation, loss or optimiser.
Break it on purpose
With identity blocks and a linear branch w = −1, branch and shortcut derivatives cancel. The input adjoint is zero despite the identity contribution.
Explore next
- BackpropagationMultiply local Jacobians along each path; add contributions where a value feeds multiple paths.
- RNN vs LSTM MemoryA direct cell path and a final hidden-output derivative answer different questions: multiply local Jacobians through time and sum the signed contributions at forks.
- Batch Norm & DropoutChange the batch statistics and dropout mask to see how they affect the same network.