| Residual stream | |
|---|---|
| the residual stream after block , ; is the embedded input | |
| the branch of block , the part added to the stream: convolutions with batch norm in a ResNet, an attention or MLP sublayer with its input norm in a transformer | |
| a later block, or the number of blocks | |
| a generic loss, differentiated through the unrolled residual sum | |
| the mean next-token loss of the course's runs | |
| constant multiplying every shortcut (ResNet v2), which turns the identity term into | |
| learned sigmoid gate on the shortcut, which becomes | |
| a branch's output variance divided by the stream's, at initialization; independent branches give | |
| normalization layer (RMSNorm or LayerNorm) | |
| Mean-field theory | |
| preactivations of layer , , a vector of width | |
| activation function of the wide fully connected network | |
| weight matrix of layer , with entries | |
| bias vector of layer , with entries | |
| width of each layer | |
| variance of each weight entry at initialization | |
| variance of each bias entry at initialization | |
| variance of one preactivation coordinate of layer for a single input, over the random weights | |
| fixed point of the preactivation variance , where the variance settles quickly with depth | |
| correlation between the preactivations and of two inputs and | |
| , the slope of the correlation map at ; is the ordered phase and the edge of chaos | |
| depth scale over which correlations approach 1, ; in the ordered phase | |
| Skipless transformers | |
| matrix of token representations after layer , one row per token of a sequence | |
| width of the token representations | |
| attention matrix of layer , in the simplified model | |
| token Gram matrix | |
| Cholesky factor of the target Gram matrix of layer , | |
| Hyper-connections | |
| number of parallel residual streams (the paper writes n; 4 in the 27B mHC run) | |
| model width; with hyper-connections the stream is | |
| matrix mixing the parallel streams at layer , started at | |
| row that reads the input of layer from the streams, | |
| row that writes the output of layer back to the streams through ; started at all ones | |
| Constants | |
| empirical factor in the trainable-depth fit | |
| best starting gate bias for ResNet v2's gated shortcuts | |
Context. For decades, networks more than a few layers deep were hard to train end to end. On ImageNet, a 34-layer plain network had higher training error than an 18-layer one even with careful initialization, ReLU activations, and batch normalization. Higher training error ruled out overfitting and pointed straight to optimization. Residual connectionsshortcuts that add a block's input to its output, , so that each block learns a correction to what it receives (He et al., 2016) broke that barrier: ResNet-34 reaches 25.0% top-1 error on ImageNet against ResNet-18's 27.9%. Lecture 7 of Stanford's CS 312, Deep Learning Alchemy (Hashimoto and Kotha, Fall 2026), examines why residual depth trains cleanly and how far initialization-time theory explains shortcuts and normalization. It also asks where newer residual designs leave that theory behind. Assignment 4 and Quiz 4 test these ideas on the course's model organismthe course's small reference model, an 8-block transformer pre-trained on about 614M tokens, on which every assignment experiment is run. Reading note: Prediction as understanding: the d8 model organism.
A deep network trains when forward signals and backward gradients cross every layer with their scale and geometry intact. Norms must not vanish or explode, and distinct inputs must stay distinguishable. A clean identity path delivers this almost automatically. It turns the end-to-end Jacobianthe matrix of derivatives of a late layer's output with respect to an early layer's input, ; it carries the gradient from the late layer back to the early one, and for residual blocks it is the product into the identity plus branch terms, giving every layer a unit-gain route to the loss. Tracking variances and input correlations at initialization predicts which shortcut edits break training, where normalization belongs, and how deep a plain network can train. Initialization theory still has limits. Newer designs depart from the identity, using learned mixing across parallel streams or attention over earlier layers, and can beat plain residuals when their depth-wise products stay bounded.
Setting. Write the residual stream after block : the running sum that every block reads and adds to, with the embedded input for the residual stream after block and block 's branch: a few convolutions with batch norm in a ResNet, an attention or MLP sublayer with its input norm in a transformer for its branch, so each block computes . The course's model-organism runs train width-512 models with vocabulary 4,096, context length 1,024, and batch size 64. Each run takes 9,375 AdamWAdam with decoupled weight decay; each coordinate moves by the learning rate times a running average of its gradient (the momentum), divided by the square root of a running average of its squared gradient, so every coordinate takes a step of similar size; weight decay then shrinks every weight by a small fixed fraction per step, applied to the weights directly instead of through that division (Loshchilov and Hutter, 2019) updates over 614.4M token slots, with 1% warmup and linear decay. The default transformer has 8 pre-norm, with here the sublayer alone: each sublayer's input is normalized and its output is added to a stream that is itself never normalized blocks with RMSNormdivision of a vector by its root mean square, followed by a learned per-coordinate gain, QK-norm, RoPErotary position embedding: queries and keys are rotated by angles proportional to their positions, so attention scores depend on relative position, and SwiGLUa gated MLP: the elementwise product of a SiLU-activated projection and a linear projection, followed by an output projection, where MLPs. The RNN baseline has 4 blocks, each pairing a tanh recurrence and a SwiGLU MLP with depth residuals and pre-norm LayerNormlayer normalization: subtract a vector's mean across its coordinates, divide by their standard deviation, then apply a learned gain and bias.
What it changes in practice. Keep an unscaled identity path from embedding to output, and normalize either each branch's input (pre-norm) or both its input and output (peri-norm, with here the sublayer alone: a normalization both before and after each sublayer, with the stream itself left unnormalized; used in Gemma models (OLMo 2 keeps only the norm after each sublayer)). Start each branch near zero; a learnable branch scalar initialized at zero trains 1,000-block networks without normalization. Leave the shortcut itself untouched by scaling, gating, convolutions, or dropout, and log activation and gradient RMS block by block so propagation failures show up right away. When widening the stream into parallel copies, keep the mixing matrices doubly stochasticwith nonnegative entries and every row and every column summing to 1 so their product across depth stays bounded. Stable training still does not guarantee that late layers do useful work, and skipless networks need several times the step budget to train.
| Shortcut (branch) | Error (%) |
|---|---|
| (), the original | 6.61 |
| () | fail |
| () | 12.35 |
| (), best start | 8.70 |
| (), gate nearly open | 6.91 |
| convolution () | 12.22 |
| Dropout 0.5 on () | fail |
Clearing operations off the shortcut helps both ResNets and transformers. Moving batch norm and ReLU off the stream into the branch (full pre-activationthe ResNet v2 block, which applies batch norm and ReLU before each convolution inside the branch, so that nothing acts on the stream after the addition) lowers CIFAR-10 error to 6.37% at 110 layers, and cuts 1,001-layer error from 7.61% to 4.92%. On d8 at learning rate 0.003, scaling the skip path behaves the same way. Multiplying the shortcut by 0.5 raised final validation loss from 2.9267 to 3.2269, while multiplying it by 2 cost far less (2.9500). Adding unit-variance Gaussian noise on the residual path barely hurt (2.9662); the lecture suggests the stream may already have a high signal-to-noise ratio.
Most of the gradient takes short paths, and late layers can be removed. Expanding residual blocks yields paths of binomially distributed length, one per subset of branches. In a 54-block ResNet, Veit et al. (2016) found that most gradient travels along paths only 5 to 17 blocks long, well below the typical length of 27. Deleting one block from a trained ResNet barely changes its error, whereas deleting one layer of a plain network ruins it. Large language models show the same redundancy. In Llama-2, DeepSeek-7B, and Qwen3, removing most single layers beyond about layer 18 barely moves MMLUa multiple-choice benchmark of questions from 57 academic and professional subjects (Sun et al., 2025). Stable training and active use of every layer are therefore separate questions.
At initialization, one number decides whether depth preserves input differences. Even when activation magnitudes stay finite, a deep plain network can collapse distinct inputs onto the same vector or scramble nearby inputs apart. Schoenholz et al. (2017) analyze a wide fully connected network with weights and biases . In their mean-field theorythe large-width limit in which each layer's preactivations are Gaussian, so a variance and an input correlation describe the whole layer; both obey one-dimensional recursions in whose fixed points and slopes decide whether signals die, saturate or propagate (Schoenholz et al., 2017), the preactivations the preactivations of layer , a vector of width are Gaussian, so two scalars track any input pair : the single-input coordinate variance the variance of one coordinate of for a single input, over the random weights and the correlation the correlation between the preactivations and of two inputs and between and . Variance settles quickly at a fixed point , and is always a fixed point of the correlation map. Its slope at is , which in the ordered phase sets the correlation depth scale (for ):In the ordered phase (), every input pair converges to correlation 1 at rate , erasing input differences. In the chaotic phase (), nearby inputs pull apart toward a fixed point , where the slope at sets . The depth scale diverges on the edge of chaosthe curve in the plane of , where for ; where correlations between inputs converge to 1 with depth (ordered phase), where nearby inputs are pulled apart (chaotic phase) (Schoenholz et al., 2017) . Backward gradient variance multiplies by the same per layer, so gradients vanish in the ordered phase and explode in the chaotic phase.
The correlation depth scale predicts trainable depth, and dropout caps it. Schoenholz et al. tested fully connected networks on MNIST and CIFAR-10 with SGD and RMSProp across a grid of and depth . Training succeeded only where why: an empirical fit, not a derived bound; the authors observe that the trainable region ends near this curve and leave the factor 6 unexplained. Dropout destroys the critical point. Two passes of the same input draw independent masks, so correlation 1 stops being a fixed point. The order-to-chaos transition disappears, stays finite for every , and trainable depth is capped.
Normalizing each branch's input keeps the variance growing linearly with depth. Suppose each branch at initialization adds an output independent of the stream with variance times the stream's. Stream variance then grows exponentially:For an unnormalized branch with , that factor reaches . Normalizing each branch's input (batch norm in ResNets, pre-norm in transformers) holds every branch's output variance at order one instead (De and Smith, 2020). Stream variance then grows linearly like , so block 's relative contribution shrinks like . Deep blocks start as small perturbations near the identity. Scaling each branch by bounds total growth by . The direct version puts a learnable scalar initialized at zero on each branch (SkipInita learnable scalar multiplying each residual branch, initialized at zero, so that every block starts as the identity, closely related to ReZero and Fixup). On CIFAR-10 at depths 16, 100, and 1,000, De and Smith reach 93.5%, 94.7%, and 94.6% accuracy with batch norm, and 93.3%, 94.2%, and 94.3% with SkipInit and no normalization. Unnormalized scale-1 branches train only at depth 16, and dividing branches by fails at depth 1,000.
In transformers, pre-norm keeps the identity clean while post-norm rescales early layers at every block. Xiong et al. (2020) apply the same variance count to transformer normalization. Pre-norm, with normalization layer , leaves the shortcut unscaled so variance grows like . Post-normnormalizing after the residual addition, , as in the original transformer, , renormalizes the stream after every block. For a unit-RMS stream and an independent branch of variance , each norm multiplies the identity path by , shrinking early signals at every later block. Initial gradients therefore concentrate in the last layers, which Xiong et al. link to post-norm's need for learning-rate warmup. The two placements also leave opposite ends idle (Sun et al., 2025), early layers in post-norm and late layers in pre-norm. Because a pre-norm stream sums all earlier branch outputs, later blocks must write larger outputs to move it. Quiz 4's answer slides offer this as one explanation for activation growth across depth in trained models. Peri-norm also normalizes each branch output, bounding stream growth and, in the lecture's view, controlling both the forward and backward passes.
Per-token normalization avoids batch norm's stale running statistics. Outside the lecture, rapid activation shifts early in training give a second reason transformers normalize each token individually (LayerNorm or RMSNorm) instead of across a minibatch. Batch normalization trains on current-batch statistics but evaluates with slow running averages, and training variants that use running averages still rely on them tracking the current weights. When activations shift faster than those averages can follow, the statistics describe an outdated network. Per-token norms compute fresh statistics at every step and never couple one example to the rest of its batch.
Norm placement shows directly in d8's activation and gradient RMS profiles. On the 8-block transformer, three variants edit both sublayers of every block: no pre-norm (), post-norm (), and no residual (). Each run logs the RMS of and at every block, where is the mean next-token loss. Each profile matches the mechanisms above. Post-norm pins stream RMS at 1 by construction, while each norm rescales backward gradients and shrinks them in early blocks. Pre-norm keeps an unscaled path to every block. Without pre-norm, branches grow unchecked and early blocks feed the loss through every later branch plus the identity, so early blocks see the largest gradients. Without residuals, the plain 8-block stack suffers uncontrolled activation growth and vanishing gradients toward the input.
Built-in bounding makes normalization matter less to an RNN. The same depth ablations carry over to the 4-block RNN baseline (tanh recurrence plus SwiGLU MLP, depth residuals, and pre-LayerNorm). Because tanh bounds every recurrent state coordinate inside , the RNN controls its own norm. Normalization therefore alters its stability and final loss far less than in the transformer, though it still reduces tanh saturation.
Plain networks train at extreme depth when the Jacobian starts near an isometry. Criticality () fixes the mean squared singular value of the end-to-end Jacobian at 1, leaving its spread unconstrained. Dynamical isometrythe condition that all singular values of the end-to-end Jacobian are close to 1, so that every direction of the gradient passes back with nearly unchanged size requires every singular value to sit near 1. Even with orthogonal weights, ReLU spreads singular values across depth, whereas tanh in its near-linear region keeps them tightly clustered (Pennington et al., 2017, 2018). Xiao et al. (2018) combine tanh, small initial preactivations, critical , and orthogonal convolution kernels to train plain 10,000-layer convolutional networks on MNIST and CIFAR-10. They see no accuracy gain past about 1,200 layers, however, and the initialization behaves almost like a deep linear network. Zhang et al. (2022) later remove skips and batch norm from a ResNet using tuned leaky ReLUs and a second-order optimizer.
Skipless transformers preserve token geometry via initialization, but train five times slower. Attention adds a second failure mode. Stacking attention matrices averages across tokens at every layer, contracting all token representations toward one another (the collapse of mean-field theory; Dong et al., 2021). Model layer as , where the matrix whose rows are the representations of the tokens of one sequence after layer , of width stacks token rows of width and is the attention matrix. The token Gram matrix then evolves asPick target Gram matrices with Cholesky factors and set . The product telescopes to and hits exactly. He et al. (2023) realize this as valid initial attention (E-SPA) with a distance-decaying target. On WikiText-103, it takes a 36-block skipless transformer from untrainable (training loss near 7.5) down to 2.79, though it needs roughly five times as many steps as a pre-norm transformer. As the lecture summarizes, signal propagation theory prescribes keeping the end-to-end Jacobian near the identity. That constraint spans all layers, yet stays tractable because initialization and local behavior dominate.
Hyper-connections widen the residual stream, but unconstrained mixing explodes with depth. Hyper-connectionsa residual design with several parallel copies of the stream, mixed by small learned matrices at every layer (Zhu et al., 2024) expand the residual stream into the number of parallel residual streams; the paper writes parallel copies, for model width , replacing the residual update withHere the row reads the layer's input from the streams, writes its output back, and the matrix mixes the streams. Each of the three combines a learned constant with an input-dependent term. Setting , to read one stream, and to all ones starts the network as standard pre-norm. In that setup, hyper-connections train an OLMoE mixture-of-expertsa model whose MLP is split into many experts, of which a learned router activates a few per token model faster, with larger gains from more streams. Over many layers, however, the identity shortcut becomes the unconstrained product . In Xie et al.'s (2025) 27B model, that product's largest absolute row or column sum reached about 3,000, accompanied by a loss surge near step 12,000.
Manifold-constrained hyper-connections (mHC) keep composite mixing bounded. mHCmanifold-constrained hyper-connections: hyper-connections whose residual mixing matrices are constrained to be doubly stochastic (Xie et al., 2025) projects each onto the doubly stochastic matrices via 20 iterations of Sinkhorn-Knoppthe algorithm that alternately rescales the rows and the columns of a positive matrix to sum to 1; it converges to a doubly stochastic matrix. Reading note: Matrix scaling and Sinkhorn's theorem applied to . It also constrains and to be nonnegative with sigmoids. Every doubly stochastic matrix is a convex combination of permutations, so it has spectral norm at most 1 and preserves the mean across streams. Because the set is closed under multiplication, products of any depth stay doubly stochastic. With this approximate projection, the composite gain stayed below about 1.6. At 27B parameters (), mHC finished 0.021 lower in loss than the baseline, raising BBHBIG-Bench Hard, a set of 23 hard reasoning tasks from 43.8 to 51.0 and DROPa reading-comprehension benchmark whose questions need discrete reasoning such as counting and arithmetic over a paragraph from 47.0 to 53.9 (against 48.9 and 51.6 for unconstrained hyper-connections). It added 6.7% training time and was adopted in DeepSeek-V4.
Attention residuals leave the identity path altogether and still train well. Attention residuals (Kimi team) replace the running residual sum with a softmax over all earlier layer outputs. Each layer carries one learned query vector, while the earlier outputs serve as keys and values. The update starts uniform over earlier layers, far from an identity shortcut, and can focus on a few layers or skip others. Even so, it performs well in practice. The lecture closes on this tension. Variance tracking and end-to-end Jacobian tools explain why identity shortcuts work, yet they predicted neither mHC nor attention residuals.
Limits. Mean-field theory describes wide random networks at initialization. It predicts trainability rather than final loss, and its boundary was fitted to fully connected networks on MNIST and CIFAR-10. The stream-variance calculation assumes branch outputs are independent of the stream, which holds only at initialization. The course's d8 and RNN results are single runs of small models on one dataset. Hyper-connection and mHC evidence comes from their authors' runs at 1B to 27B parameters, and attention-residual results come from a technical report.
Terms
- identity path
- : the gradient reaches every block with gain one, whatever the branches do
- scaled shortcut
- on every shortcut gives on the identity term: vanishing for , exploding for
- : per-layer factor on correlations near 1 and on gradient variance
- depth scale
- in the ordered phase; networks trained only where depth
- edge of chaos
- : diverges; dropout removes this critical point
- stream variance
- unnormalized; about with normalized branches
- pre-norm / post-norm
- keeps the identity clean; divides early signals at every block
- SkipInit
- learnable branch scalar started at 0; trains 1,000 blocks without normalization
- dynamical isometry
- all singular values of the end-to-end Jacobian near 1; lets 10,000-layer plain networks train
- E-SPA
- attention at initialization chosen as to hit a target token kernel; trains skipless transformers about 5 times slower
- mHC
- hyper-connections with doubly stochastic : products stay bounded (gain about 1.6 against 3,000)
- attention residuals
- softmax over earlier layer outputs with a learned query per layer, started uniform
Sources
Lecture 7, “Architecture 1: Signal propagation in depth” (Oct 22, 2026), of Stanford CS 312 Deep Learning Alchemy, Fall 2026. Taught by Tatsunori Hashimoto and Suhas Kotha; course staff Kaiyue Wen and Tristan Thrush (CAs).
Course site Lecture slides Online quiz Quiz answers Assignment Assignment code
The lessons, experiments, figures and quiz problems in this note are the course's, shown here with the instructors' permission.
- Tatsunori Hashimoto and Suhas Kotha. CS 312 Deep Learning Alchemy, Lecture 7: Architecture 1: Signal propagation in depth. Stanford, Fall 2026.
- Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Identity Mappings in Deep Residual Networks. ECCV, 2016.
- Samuel S. Schoenholz, Justin Gilmer, Surya Ganguli, and Jascha Sohl-Dickstein. Deep Information Propagation. ICLR, 2017.
- Zhenda Xie, Yixuan Wei, Huanqi Cao, et al. mHC: Manifold-Constrained Hyper-Connections. arXiv preprint, 2025.
- Tatsunori Hashimoto and Suhas Kotha. CS 312 Deep Learning Alchemy, Quiz 4 (Stability) and Assignment 4 (Transformers vs RNNs). Stanford, Fall 2026.
- Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep Residual Learning for Image Recognition. IEEE Conference on Computer Vision and Pattern Recognition, 2016.
- Ilya Loshchilov and Frank Hutter. Decoupled Weight Decay Regularization. International Conference on Learning Representations, 2019.
Connected notes
- The information exponentHigh-dimensional SGD · Abrupt transitions at a critical ratio
Online SGD's overlap with a hidden direction grows at the rate signal/noise, which is tiny near a random start, so escaping takes about samples for information exponent (the order of the first nonzero Hermite term) and almost all the samples are used up before the overlap grows.
- Softmax attention as a sum of RNNsEfficient sequence models · Fixed scales for stable training
Dividing the numerator of softmax attention by its L2 norm, which fixes the output's length, follows the softmax loss curve, while dividing by the sequence length behind a gate, with scores clamped at 5 and gradients clipped, still gives loss spikes.
PreNorm's unweighted running sum grows with depth and dilutes every earlier output, so Attention Residuals replace it with softmax-weighted averages over earlier block sums, bounding the mixed input by while keeping direct shortcuts across depth without the matrix-product instability of multi-stream mixing.
- In-context learning as implicit Bayesian inferenceIn-context learning · Abrupt transitions at a critical ratio
At dimension 8, below about pretraining tasks more data per task pulls the transformer toward the Bayes rule for the tasks it saw, and above toward ridge, with the threshold growing roughly linearly in dimension.