Skip connections: add every gradient path
跳跃连接与梯度流
Compare additive and concatenated skips, audit exact path contributions and test cancellation, growth and decay in a real graph.
skip-connectionsA short route can still cancel another route
Adding a shortcut gives a signal another route through a computation graph. It does not decide how contributions from different routes combine. Two derivatives can reinforce each other, one can be blocked, or they can cancel exactly.
The 2016 Identity Mappings paper, Section 2 analyzes direct propagation in residual units when both the skip map and the post-addition map are identities. That analysis concerns a particular merge. A different use of skips appears in U-Net’s 2015 architecture, Section 2: features from the contracting path are cropped and concatenated with upsampled features. Concatenating representations is not the same operation as adding them.
This chapter studies graph routes and reverse accumulation. Residual connections separately studies learning a correction to a baseline mapping.
Addition and concatenation have different derivatives
For a vector x and a compatible branch F, compare the merges and their Jacobians:
Addition requires compatible shapes and mixes the values immediately. Concatenation stores them in different coordinates, increasing feature width. A later map chooses how to use those coordinates. With scalar F(x)=2x and a linear readout −2x+F(x), the final derivative is zero even though the concatenated representation explicitly contains x.
For a scalar directed acyclic graph, the chain rule expands the derivative into a sum over directed paths from input to output:
Each product is a path contribution, and all contributions are evaluated at the same forward state. For linear weighted edges, dₑ is simply the edge weight. Nonlinear networks require the local derivatives at that state. For vector edges, multiplication becomes ordered Jacobian multiplication; reordering factors can change the result.
Reverse-mode differentiation computes this sum efficiently without enumerating paths. At each node it adds contributions to every parent. Overwriting a parent’s existing gradient would lose paths that were already processed.
Two residual blocks already have four paths
Let the two scalar branches have slopes a and b, with identity skips and no post-addition activation. Then:
For a=2 and b=3, the four contributions are 1,2,3,6 and the derivative is 12. For a=−1 and b=3, they are 1,−1,3,−3 and sum to zero. The all-identity path still contributes one; it is the total derivative that cancels. This is an explicit counterexample to the blanket claim that identity skips make vanishing gradients impossible.
With twenty identical branches, the derivative is (1+a)²⁰. Setting a=0 preserves it at one; a=1/2 gives about 3325.256730; a=−1/2 gives 1/1048576. These are controlled linear examples, not measurements of how frequently a trained deep model behaves this way.
Compare reverse accumulation with path enumeration
The complete Python 3.12 program represents each computed node as weighted incoming edges from earlier nodes. Node zero is the input and the final node is the output. Two edges may have the same parent: in a scalar residual block, one represents the identity route and the other the branch. The graph is linear, and the input derivative uses output adjoint one; a loss gradient would also include the derivative of the loss with respect to the output.
from fractions import Fraction as F
def graph(rows):
if not 1<=len(rows)<=24:raise ValueError('1 through 24 computed nodes required')
checked=[]
for node,row in enumerate(rows,1):
if not 1<=len(row)<=4:raise ValueError('1 through 4 incoming edges required')
edges=[]
for parent,weight in row:
if type(parent) is not int or not 0<=parent<node:raise ValueError('parents must precede the node')
if type(weight) not in (int,F) or abs(weight)>16:raise ValueError('bounded rational edge weight required')
edges.append((parent,F(weight)))
checked.append(edges)
return checked
def evaluate(rows,x=1):
rows=graph(rows)
if type(x) not in (int,F) or abs(x)>16:raise ValueError('bounded rational input required')
values=[F(x)]
for edges in rows:values.append(sum((values[p]*w for p,w in edges),F(0)))
adjoints=[F(0)]*len(values);adjoints[-1]=F(1)
for node in range(len(rows),0,-1):
for parent,weight in rows[node-1]:adjoints[parent]+=adjoints[node]*weight
edge_grads=[[adjoints[node]*values[p] for p,_ in edges] for node,edges in enumerate(rows,1)]
return dict(values=values,input_derivative=adjoints[0],edge_derivatives=edge_grads)
def paths(rows):
weights=[[F(1)]]
for edges in graph(rows):
count=sum(len(weights[parent]) for parent,_ in edges)
if count>4096:raise ValueError('path audit exceeds 4096 paths')
weights.append([previous*w for parent,w in edges for previous in weights[parent]])
return weights[-1]
def chain(coefficients):
return [[(i,1),(i,a)] for i,a in enumerate(coefficients)]
if __name__=='__main__':
for coefficients in [(2,3),(-1,3)]:
rows=chain(coefficients);r=evaluate(rows,2)
print('branch slopes:',coefficients,'path contributions:',[str(v) for v in paths(rows)])
print('output:',r['values'][-1],'input derivative:',r['input_derivative'])
for slope in (F(0),F(1,2),F(-1,2)):
d=evaluate(chain([slope]*20))['input_derivative']
print('twenty blocks, branch slope:',slope,'derivative:',f'{float(d):.9f}')
readout=evaluate([[(0,2)],[(0,-2),(1,1)]],2)
print('concatenation-style readout derivative:',readout['input_derivative'])
Actual output:
branch slopes: (2, 3) path contributions: ['1', '2', '3', '6']
output: 24 input derivative: 12
branch slopes: (-1, 3) path contributions: ['1', '-1', '3', '-3']
output: 0 input derivative: 0
twenty blocks, branch slope: 0 derivative: 1.000000000
twenty blocks, branch slope: 1/2 derivative: 3325.256730080
twenty blocks, branch slope: -1/2 derivative: 0.000000954
concatenation-style readout derivative: 0
The program returns node values, the input derivative and derivatives with respect to each edge weight. Tests compare reverse accumulation with literal path sums, check input and edge derivatives by finite differences, verify the twenty-block formulas and reject forward references, cycles, nonfinite weights and oversized path audits.
Forward and reverse passes require O(V+E) work and storage for V nodes and E edges. The separate path audit can grow exponentially; twenty two-route blocks have over a million paths, so the program intentionally uses reverse accumulation for that case and caps explicit enumeration at 4096 paths. The cap limits inspection, not the graph’s computed derivative.
A diagram does not specify every derivative
The identity argument changes if the shortcut is a projection or gate. A ReLU after addition can also block a path: with a zero residual branch and negative scalar input, ReLU(x) has derivative zero. A normalization after the merge introduces its own Jacobian. These operations must be included in the local derivatives before summing routes.
A nonzero output-to-input derivative does not guarantee useful gradients for every branch parameter. A parameter may lie behind a saturated unit, have a zero input or affect a direction ignored by the loss. Our edge derivatives make a different quantity from the overall input derivative explicit.
Concatenation can retain high-resolution features, but it costs feature storage and often widens later layers. Spatial dimensions must align; U-Net’s original cropped skip features because its unpadded convolutions changed sizes. This chapter does not implement an image encoder-decoder or claim every modern U-Net uses the same cropping policy.
The identity-mapping paper argues that complete cancellation is unlikely in its intended training setting. Our linear construction is not evidence about that empirical frequency; it shows why a useful architectural intuition must not be turned into an unconditional mathematical guarantee.
Count contributions before naming the effect
- What derivative comes from two identity-skip blocks with branch slopes 2 and 3?
Answer 1: Twelve, from 1+2+3+6.
- Can the derivative vanish while an all-identity path remains present?
Answer 2: Yes. Slopes −1 and 3 give 1−1+3−3=0.
- Why does reverse accumulation use addition at a shared parent?
Answer 3: Different outgoing routes contribute to the same derivative; overwriting would discard some routes.
- Does concatenating x with 2x ensure a later scalar readout has nonzero derivative?
Answer 4: No. The readout −2x+2x cancels it.
Separate route existence from the final gradient
The residual analysis supplies explicit assumptions about the skip and post-addition maps. U-Net supplies an example of a different merge used to combine feature scales. Our scalar graph, exact path cancellations, reverse accumulation and finite-difference tests are original; no source code, image model or benchmark was reproduced.
Continue with computational graphs for reverse-mode bookkeeping, vanishing gradients for long products, and residual connections for the correction parameterization.
Make a prediction, then check
With identity skips and branch slopes-1 and3, what is the total input derivative?
Learning objectives
- Differentiate addition and concatenation merges.
- Sum graph paths without claiming a nonvanishing guarantee.
Prerequisites & connections
Explore related knowledge →References
- Identity Mappings in Deep Residual Networks — arXiv1603.05027v3
Kaiming He; Xiangyu Zhang; Shaoqing Ren; Jian Sun · 2016 - U-Net: Convolutional Networks for Biomedical Image Segmentation — arXiv1505.04597v1
Olaf Ronneberger; Philipp Fischer; Thomas Brox · 2015
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-06 · Codex single-agent authored technical review: cited primary-source scope, explicit assumptions, original calculations and counterexamples, runnable tests and bilingual review; not independent human or second-agent review.
- Single-agent authored technical review: bounded primary-source locations, assumptions, original derivations, exact/literal references and matching bilingual equations/examples/exercises. Not independent human or second-agent review.
- Four focused CPython3.12.4 tests passed per chapter. Normalization axes and groups, matched residual fits and reverse graph paths are checked against literal references, analytic identities and finite differences. Two examples use NumPy1.26.4; two use the standard library.
- Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
- Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.
Source locations checked:
- Identity Mappings in Deep Residual Networks — arXiv1603.05027v3 · Fixedv3 Section2 physicalpages3–4 Eqs1–5: identity skip/post-addition assumptions, additive direct term and authors cancellation discussion; counterexample does not measure its empirical frequency.
- U-Net: Convolutional Networks for Biomedical Image Segmentation — arXiv1505.04597v1 · Fixedv1 Section2 physicalpage4: contracting/expanding paths, cropped concatenation, unpadded convolution alignment; no architecture or training experiment reproduced.
Related topics