Rúben GalvãoThe Rabbit Hole

The Rabbit Hole / AI and machine learning / Language models / The residual stream

Hyper-connections: more than one residual stream

Hyper-connections and manifold-constrained hyper-connections (mHC) give the residual stream multiple paths. How should those paths mix?

Our rabbit token passes through dozens of layers. Attention adds context, feed-forward adds what it has learned, and both write into the same running vector.

Late layers read almost the same thing

With pre-norm, the stream keeps every update and keeps growing. Each new update is about the same size, so it moves a larger and larger vector by less and less.

With one stream, late layers read almost the same inputSimilarity between consecutive layers' inputs in a toy 32-layer pre-norm stack, where every update is a random vector of the same size. It starts at 0.70 and reaches 0.98 by layer 32.0.60.70.80.91.018162432layersimilarity0.70: the update still matters0.98: almost the same inputToy stack, random updates
Each point compares one layer's input with the next layer's. Late in the stack, a layer's update barely changes what the next one reads. Illustrative: a toy stack where every update is a random vector of the same size.

By the last layers, each one reads almost what the previous one read. Their extra depth adds little. The Hyper-Connections authors saw the same pattern in a real 1-billion-parameter pre-norm model.

Post-norm avoids this by rescaling the stream after every layer, but then the training signal fades on its way back through all those norms. One stream forces a trade between the two.

Just use a bigger embedding size?

We could give each token more numbers: a larger embedding size. That leaves room for updates to stay distinct, but it is simply a bigger model. Every layer’s matrices have a row and a column for each of those numbers.

Three times the embedding size costs nine times the weights; three streams cost almost nothing extraLeft: one stream and a layer's weight matrix. Middle: an embedding size three times larger needs a matrix with three times the rows and columns, nine times the weights. Right: three streams of the usual size share the usual layer, plus a few small weights to read, write and mix them.One streamThe usual layer1× weights3× embedding sizeBigger matrices9× weightsThree streamsSame layer1× + 15 weights
A bigger embedding size makes every layer's matrices bigger. Carrying several streams keeps the layer as it was.

Three times the embedding size means nine times the weights, and nine times the work, in every layer. Can we give the stream more room without paying for a bigger model? Carry three streams between layers, but let each layer still read and write one vector of the usual size.

The usual one-stream stack beside the same stack with three residual streamsOn the left, the token embedding starts one residual stream; attention and feed-forward each read it and add an update. On the right, the embedding is copied into three streams. Each layer reads a weighted combination of the three, runs once, and writes its update back to all three. At the end the three streams are added together before the output.One streamEmbeddingAttentionFeed-forward⋮ more layersOutputThree streamsEmbeddingcopiesreadAttentionwritereadFeed-forwardwrite⋮ more layersOutputstreams added together
Left: the usual stack, with one residual stream. Right: the same layers carrying three. Each layer still reads one vector and writes one update.

We start with copies of the token vector. As layers add different amounts to each copy, the streams can grow apart.

What should the layer read?

Attention or feed-forward still needs one vector per token. Which stream should we give it?

We can let the model learn a weight for each stream, then add the weighted vectors together.

Choose the layer input

Interactive
Stream 1Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.058Coordinate 2: 0.516Coordinate 3: -0.003Coordinate 4: -0.783Coordinate 5: -0.400Coordinate 6: -0.516Coordinate 7: 0.700Coordinate 8: -0.691Coordinate 9: 0.754Coordinate 10: 0.159Coordinate 11: -0.441Coordinate 12: 0.095Coordinate 13: 0.570Coordinate 14: -0.164Coordinate 15: -0.717Coordinate 16: -0.322Coordinate 17: 0.822Coordinate 18: -0.006Current token computation.× 1Stream 2Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.287Coordinate 2: -0.649Coordinate 3: -0.683Coordinate 4: 0.437Coordinate 5: 0.281Coordinate 6: -0.598Coordinate 7: 0.494Coordinate 8: 0.106Coordinate 9: -0.039Coordinate 10: 0.492Coordinate 11: 0.803Coordinate 12: 0.787Coordinate 13: -0.540Coordinate 14: -0.620Coordinate 15: 0.005Coordinate 16: 0.120Coordinate 17: -0.543Coordinate 18: 0.480Current token computation.× 0Stream 3Earlier context is dimmed; outlined columns are current.Coordinate 1: -0.146Coordinate 2: -0.126Coordinate 3: -0.737Coordinate 4: 0.567Coordinate 5: -0.367Coordinate 6: -0.240Coordinate 7: -0.159Coordinate 8: -0.437Coordinate 9: 0.166Coordinate 10: 0.186Coordinate 11: -0.201Coordinate 12: 0.683Coordinate 13: -0.576Coordinate 14: 0.370Coordinate 15: -0.001Coordinate 16: -0.690Coordinate 17: 0.697Coordinate 18: 0.785Current token computation.× 0+Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.058Coordinate 2: 0.516Coordinate 3: -0.003Coordinate 4: -0.783Coordinate 5: -0.400Coordinate 6: -0.516Coordinate 7: 0.700Coordinate 8: -0.691Coordinate 9: 0.754Coordinate 10: 0.159Coordinate 11: -0.441Coordinate 12: 0.095Coordinate 13: 0.570Coordinate 14: -0.164Coordinate 15: -0.717Coordinate 16: -0.322Coordinate 17: 0.822Coordinate 18: -0.006Current token computation.7,168Layer inputTo the layer

Choose one stream, then try combining them. Either way, the result is a single layer input of the usual size.

Where should the layer output go?

The layer calculates one layer output. We can add it to every stream, but give each its own write weight.

Layer outputEarlier context is dimmed; outlined columns are current.Coordinate 1: 0.292Coordinate 2: -0.248Coordinate 3: 0.160Coordinate 4: 0.310Coordinate 5: -0.058Coordinate 6: 0.402Coordinate 7: 0.233Coordinate 8: -0.088Coordinate 9: -0.403Coordinate 10: -0.360Coordinate 11: -0.134Coordinate 12: -0.127Coordinate 13: -0.404Coordinate 14: -0.388Coordinate 15: -0.280Coordinate 16: -0.119Coordinate 17: -0.172Coordinate 18: -0.008Current token computation.7,168× 0.2Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.058Coordinate 2: -0.050Coordinate 3: 0.032Coordinate 4: 0.062Coordinate 5: -0.012Coordinate 6: 0.080Coordinate 7: 0.047Coordinate 8: -0.018Coordinate 9: -0.081Coordinate 10: -0.072Coordinate 11: -0.027Coordinate 12: -0.025Coordinate 13: -0.081Coordinate 14: -0.078Coordinate 15: -0.056Coordinate 16: -0.024Coordinate 17: -0.034Coordinate 18: -0.002Current token computation.Stream 1Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.058Coordinate 2: 0.516Coordinate 3: -0.003Coordinate 4: -0.783Coordinate 5: -0.400Coordinate 6: -0.516Coordinate 7: 0.700Coordinate 8: -0.691Coordinate 9: 0.754Coordinate 10: 0.159Coordinate 11: -0.441Coordinate 12: 0.095Coordinate 13: 0.570Coordinate 14: -0.164Coordinate 15: -0.717Coordinate 16: -0.322Coordinate 17: 0.822Coordinate 18: -0.006Current token computation.+Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.116Coordinate 2: 0.466Coordinate 3: 0.029Coordinate 4: -0.721Coordinate 5: -0.412Coordinate 6: -0.435Coordinate 7: 0.746Coordinate 8: -0.709Coordinate 9: 0.673Coordinate 10: 0.087Coordinate 11: -0.468Coordinate 12: 0.069Coordinate 13: 0.489Coordinate 14: -0.242Coordinate 15: -0.773Coordinate 16: -0.346Coordinate 17: 0.788Coordinate 18: -0.007Current token computation.× 1Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.292Coordinate 2: -0.248Coordinate 3: 0.160Coordinate 4: 0.310Coordinate 5: -0.058Coordinate 6: 0.402Coordinate 7: 0.233Coordinate 8: -0.088Coordinate 9: -0.403Coordinate 10: -0.360Coordinate 11: -0.134Coordinate 12: -0.127Coordinate 13: -0.404Coordinate 14: -0.388Coordinate 15: -0.280Coordinate 16: -0.119Coordinate 17: -0.172Coordinate 18: -0.008Current token computation.Stream 2Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.287Coordinate 2: -0.649Coordinate 3: -0.683Coordinate 4: 0.437Coordinate 5: 0.281Coordinate 6: -0.598Coordinate 7: 0.494Coordinate 8: 0.106Coordinate 9: -0.039Coordinate 10: 0.492Coordinate 11: 0.803Coordinate 12: 0.787Coordinate 13: -0.540Coordinate 14: -0.620Coordinate 15: 0.005Coordinate 16: 0.120Coordinate 17: -0.543Coordinate 18: 0.480Current token computation.+Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.580Coordinate 2: -0.897Coordinate 3: -0.523Coordinate 4: 0.747Coordinate 5: 0.222Coordinate 6: -0.196Coordinate 7: 0.727Coordinate 8: 0.018Coordinate 9: -0.442Coordinate 10: 0.132Coordinate 11: 0.670Coordinate 12: 0.660Coordinate 13: -0.945Coordinate 14: -1.008Coordinate 15: -0.275Coordinate 16: 0.001Coordinate 17: -0.715Coordinate 18: 0.473Current token computation.× 0.5Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.146Coordinate 2: -0.124Coordinate 3: 0.080Coordinate 4: 0.155Coordinate 5: -0.029Coordinate 6: 0.201Coordinate 7: 0.116Coordinate 8: -0.044Coordinate 9: -0.202Coordinate 10: -0.180Coordinate 11: -0.067Coordinate 12: -0.064Coordinate 13: -0.202Coordinate 14: -0.194Coordinate 15: -0.140Coordinate 16: -0.059Coordinate 17: -0.086Coordinate 18: -0.004Current token computation.Stream 3Earlier context is dimmed; outlined columns are current.Coordinate 1: -0.146Coordinate 2: -0.126Coordinate 3: -0.737Coordinate 4: 0.567Coordinate 5: -0.367Coordinate 6: -0.240Coordinate 7: -0.159Coordinate 8: -0.437Coordinate 9: 0.166Coordinate 10: 0.186Coordinate 11: -0.201Coordinate 12: 0.683Coordinate 13: -0.576Coordinate 14: 0.370Coordinate 15: -0.001Coordinate 16: -0.690Coordinate 17: 0.697Coordinate 18: 0.785Current token computation.+Earlier context is dimmed; outlined columns are current.Coordinate 1: -0.000Coordinate 2: -0.250Coordinate 3: -0.657Coordinate 4: 0.722Coordinate 5: -0.396Coordinate 6: -0.039Coordinate 7: -0.042Coordinate 8: -0.481Coordinate 9: -0.036Coordinate 10: 0.005Coordinate 11: -0.268Coordinate 12: 0.619Coordinate 13: -0.778Coordinate 14: 0.176Coordinate 15: -0.141Coordinate 16: -0.749Coordinate 17: 0.611Coordinate 18: 0.781Current token computation.
Each stream gets its own weighted share of the layer output.

One stream receives a small change; another receives more. We run the layer once and use its output in several places.

Let the streams share information

So far, each stream has kept its own path. We could also let them exchange information.

A small learned matrix does that. Each row combines the incoming streams into one outgoing stream.

Let the streams exchange information

Interactive
1Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.058Coordinate 2: 0.516Coordinate 3: -0.003Coordinate 4: -0.783Coordinate 5: -0.400Coordinate 6: -0.516Coordinate 7: 0.700Coordinate 8: -0.691Coordinate 9: 0.754Coordinate 10: 0.159Coordinate 11: -0.441Coordinate 12: 0.095Coordinate 13: 0.570Coordinate 14: -0.164Coordinate 15: -0.717Coordinate 16: -0.322Coordinate 17: 0.822Coordinate 18: -0.006Current token computation.2Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.287Coordinate 2: -0.649Coordinate 3: -0.683Coordinate 4: 0.437Coordinate 5: 0.281Coordinate 6: -0.598Coordinate 7: 0.494Coordinate 8: 0.106Coordinate 9: -0.039Coordinate 10: 0.492Coordinate 11: 0.803Coordinate 12: 0.787Coordinate 13: -0.540Coordinate 14: -0.620Coordinate 15: 0.005Coordinate 16: 0.120Coordinate 17: -0.543Coordinate 18: 0.480Current token computation.3Earlier context is dimmed; outlined columns are current.Coordinate 1: -0.146Coordinate 2: -0.126Coordinate 3: -0.737Coordinate 4: 0.567Coordinate 5: -0.367Coordinate 6: -0.240Coordinate 7: -0.159Coordinate 8: -0.437Coordinate 9: 0.166Coordinate 10: 0.186Coordinate 11: -0.201Coordinate 12: 0.683Coordinate 13: -0.576Coordinate 14: 0.370Coordinate 15: -0.001Coordinate 16: -0.690Coordinate 17: 0.697Coordinate 18: 0.785Current token computation.Incoming streamsFrom stream123110020103001rows: to stream1Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.058Coordinate 2: 0.516Coordinate 3: -0.003Coordinate 4: -0.783Coordinate 5: -0.400Coordinate 6: -0.516Coordinate 7: 0.700Coordinate 8: -0.691Coordinate 9: 0.754Coordinate 10: 0.159Coordinate 11: -0.441Coordinate 12: 0.095Coordinate 13: 0.570Coordinate 14: -0.164Coordinate 15: -0.717Coordinate 16: -0.322Coordinate 17: 0.822Coordinate 18: -0.006Current token computation.2Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.287Coordinate 2: -0.649Coordinate 3: -0.683Coordinate 4: 0.437Coordinate 5: 0.281Coordinate 6: -0.598Coordinate 7: 0.494Coordinate 8: 0.106Coordinate 9: -0.039Coordinate 10: 0.492Coordinate 11: 0.803Coordinate 12: 0.787Coordinate 13: -0.540Coordinate 14: -0.620Coordinate 15: 0.005Coordinate 16: 0.120Coordinate 17: -0.543Coordinate 18: 0.480Current token computation.3Earlier context is dimmed; outlined columns are current.Coordinate 1: -0.146Coordinate 2: -0.126Coordinate 3: -0.737Coordinate 4: 0.567Coordinate 5: -0.367Coordinate 6: -0.240Coordinate 7: -0.159Coordinate 8: -0.437Coordinate 9: 0.166Coordinate 10: 0.186Coordinate 11: -0.201Coordinate 12: 0.683Coordinate 13: -0.576Coordinate 14: 0.370Coordinate 15: -0.001Coordinate 16: -0.690Coordinate 17: 0.697Coordinate 18: 0.785Current token computation.Mixed streamsbefore the layer output

These learned reads, writes and connections between streams are called hyper-connections. Their weights can also change with the token being processed.

Here is how the pieces fit together:

Token streamsEarlier context is dimmed; outlined columns are current.Coordinate 1: 0.058Coordinate 2: 0.516Coordinate 3: -0.003Coordinate 4: -0.783Coordinate 5: -0.400Coordinate 6: -0.516Coordinate 7: 0.700Coordinate 8: -0.691Coordinate 9: 0.754Coordinate 10: 0.159Coordinate 11: -0.441Coordinate 12: 0.095Coordinate 13: 0.570Coordinate 14: -0.164Coordinate 15: -0.717Coordinate 16: -0.322Coordinate 17: 0.822Coordinate 18: -0.006Current token computation.Earlier context is dimmed; outlined columns are current.Coordinate 1: 0.287Coordinate 2: -0.649Coordinate 3: -0.683Coordinate 4: 0.437Coordinate 5: 0.281Coordinate 6: -0.598Coordinate 7: 0.494Coordinate 8: 0.106Coordinate 9: -0.039Coordinate 10: 0.492Coordinate 11: 0.803Coordinate 12: 0.787Coordinate 13: -0.540Coordinate 14: -0.620Coordinate 15: 0.005Coordinate 16: 0.120Coordinate 17: -0.543Coordinate 18: 0.480Current token computation.Earlier context is dimmed; outlined columns are current.Coordinate 1: -0.146Coordinate 2: -0.126Coordinate 3: -0.737Coordinate 4: 0.567Coordinate 5: -0.367Coordinate 6: -0.240Coordinate 7: -0.159Coordinate 8: -0.437Coordinate 9: 0.166Coordinate 10: 0.186Coordinate 11: -0.201Coordinate 12: 0.683Coordinate 13: -0.576Coordinate 14: 0.370Coordinate 15: -0.001Coordinate 16: -0.690Coordinate 17: 0.697Coordinate 18: 0.785Current token computation.7,168Read weightsEarlier context is dimmed; outlined columns are current.Coordinate 1: 0.106Coordinate 2: 0.102Coordinate 3: -0.280Coordinate 4: -0.282Coordinate 5: -0.193Coordinate 6: -0.513Coordinate 7: 0.552Coordinate 8: -0.427Coordinate 9: 0.457Coordinate 10: 0.262Coordinate 11: -0.044Coordinate 12: 0.361Coordinate 13: 0.122Coordinate 14: -0.248Coordinate 15: -0.429Coordinate 16: -0.227Coordinate 17: 0.400Coordinate 18: 0.219Current token computation.Layer inputNormAttention or FFNEarlier context is dimmed; outlined columns are current.Coordinate 1: 0.292Coordinate 2: -0.248Coordinate 3: 0.160Coordinate 4: 0.310Coordinate 5: -0.058Coordinate 6: 0.402Coordinate 7: 0.233Coordinate 8: -0.088Coordinate 9: -0.403Coordinate 10: -0.360Coordinate 11: -0.134Coordinate 12: -0.127Coordinate 13: -0.404Coordinate 14: -0.388Coordinate 15: -0.280Coordinate 16: -0.119Coordinate 17: -0.172Coordinate 18: -0.008Current token computation.Layer outputWrite weightsStream mixing+++
Read from the streams, process one vector, then add the weighted layer output to the mixed streams.

The layer still processes one input and produces one output. We carry more streams between layers, so storing and mixing them adds some work.

Back to the late layers

At the start, every late layer read almost the same vector, because one growing stream absorbed every update.

Now a layer can read its own combination of the streams, and write its output mostly into one of them. The next layer no longer has to read what this one just read. The Hyper-Connections authors measured this in the same 1-billion-parameter model: with hyper-connections, the inputs of neighbouring layers were much less alike.

The streams still carry every update forward, as the residual stream did, so the learning signal keeps its path back. Or does it?

Haven’t we seen this before?

The residual stream made deep networks trainable because it changed nothing. It passed the stream on with a factor of 1, so the learning signal could reach the first layer however deep the stack.

Mixing puts a learned matrix back on that path. Now the stream is multiplied at every layer, as in a plain stack, and the effect compounds. Rows that add up to just 1.15 add 15% at each layer.

Unconstrained mixing compounds layer after layer; balanced mixing does notThe size of the three streams after repeated mixing alone, relative to their start. A non-negative matrix whose rows add up to 1.15 reaches about 163 times after 40 layers. The balanced matrix from the mixing example stays at or below 1.050100150010203040layers of mixingsize ÷ startrows add up to 1.15rows and columns add up to 1
Rows that add up to 1.15 grow the streams about 163 times in 40 layers. With every row and column adding up to 1, they never grow.

The learning signal travels back along the same path and meets the same matrices. Slightly too large, and it explodes; slightly too small, and it fades away. In giving the stream more freedom, we have brought back the problem the residual stream was there to solve.

Put the identity back

In the mixing example, the Keep separate option passes every stream through unchanged, just like the original residual stream. That is safe, but the streams share nothing. Can we share information and stay safe?

Manifold-constrained hyper-connections (mHC) allow only matrices whose weights are non-negative and whose rows and columns each add up to one. Such a matrix only moves values between streams: their total passes through unchanged, as on the original residual stream.

Balanced mixing moves values between streams without changing their totalBefore mixing: 0.90, 0.20, 0.50, total 1.60. Rows add up to 1.15: 0.76, 0.43, 0.65, total 1.84. mHC: rows and columns add up to 1: 0.65, 0.36, 0.59, total 1.60.Before mixing0.9010.2020.503Total 1.60Rows add up to 1.150.7610.4320.653Total 1.84 (+15%)mHC0.6510.3620.593Total 1.60
One number from each stream. Rows that add up to 1.15 grow the total by 15%; with mHC the values move between streams, but their total stays the same.

Multiply two of these matrices and the result follows the same rule, so it holds through any number of layers, forwards and backwards. That is the flat green line in the growth figure above.

The Mix streams example follows this rule, and the layer output can still add something new.

DeepSeek-V4 uses mHC to carry four streams through every layer.

With the identity restored, can we also scale the one skip path we already have? Next, residual scaling (coming soon).

Sources and assumptions
  • Hyper-Connections, Sections 2–3 and Appendix J: stream expansion, weighted reading, residual mixing, weighted writing and input-dependent coefficients. Streams start as copies; the final streams are summed before the output projection.
  • Hyper-Connections, Figure 3: cosine similarity between each layer’s input and earlier layers’ inputs in OLMo-1B. The pre-norm model shows high similarity between adjacent layers, which the authors call representation collapse; with hyper-connections it is much lower. The paper gives the result as a plot without numbers, so the first figure here uses a toy instead.
  • mHC, Section 4: doubly stochastic residual mixing, constrained read/write coefficients and efficient implementation. The constraint on the mixing matrix concerns the skip paths, not the full block including its layer output. Its abstract gives the motivation used here: unconstrained hyper-connections compromise “the identity mapping property intrinsic to the residual connection”, causing training instability. A product of such doubly stochastic matrices is doubly stochastic, and so is its transpose, which carries the learning signal back.

The first figure compares, in a toy 32-layer pre-norm stack with 64 numbers per token, each layer’s input with the next layer’s; every update is a random vector the size of the starting token. The weight comparison assumes a layer’s matrices have a row and a column for each number in the token vector. The growth figure repeats mixing alone, without layer outputs, on the article’s three streams. The total figure mixes one hand-picked number from each stream. The other diagrams use the same three streams. Read and mixing controls calculate each displayed coordinate. The writing diagram scales one fixed layer output. Norm and layer calculations are represented by their boxes. The size label shows the selected model’s token width.

← Browse all subjectsBack to the beginning ↑