A Transformer produces a new vector at every attention or MLP sublayer, then adds it to the residual stream. The next sublayer receives the sum. It can read the features in that sum, but it cannot ask for the output of layer 3 by itself.

Working on Hyper-Connections brought me back to that addition. We spend most of the computation producing new features; the connection between layers decides which results remain separately available. Keeping two contributions apart lets a later layer choose between them. Adding them together makes that choice earlier.

A residual stream carries a running sum

Follow one token position through a Pre-LN Transformer. Count each attention or MLP sublayer as one step:

ol=Fl(Norm⁡(hl)),hl+1=hl+ol.(1)o_l=F_l(\operatorname{Norm}(h_l)), \qquad h_{l+1}=h_l+o_l. \tag{1}

Both hlh_l and olo_l have dd coordinates. An attention sublayer still reads other token positions; we are following what happens to its output at this position as depth increases.

Unrolling the additions gives

hL=h0+∑i=0L−1oi.(2)h_L=h_0+\sum_{i=0}^{L-1}o_i. \tag{2}

Every earlier output enters this expression with coefficient one. The next sublayer receives this accumulated state, followed by normalization.

Suppose two earlier computations produced pp and qq. Once only p+qp+q remains, a later layer cannot generally choose to read pp alone. The pairs (p,q)(p,q) and (p+r,q−r)(p+r,q-r) produce the same sum for any rr. A network can learn to encode contributions in distinguishable feature directions, but the connection itself supplies one vector, with no separate address for each contribution.

The point where we add vectors determines which choices remain available later. Hyper-Connections changes that point by carrying several states between sublayers.

HC separates reading, mixing, and writing

Hyper-Connections maintains NN residual streams for each token. Stack them as rows:

Hl=[hl,1⊤⋮hl,N⊤]∈RN×d.(3)H_l= \begin{bmatrix} h_{l,1}^\top\\ \vdots\\ h_{l,N}^\top \end{bmatrix} \in\mathbb R^{N\times d}. \tag{3}

Each row is a full dd-dimensional state at the same token position. Three sets of coefficients connect it to the next sublayer:

CoefficientShapeWhat it controls
ala_lNNWhich combination of streams the sublayer reads
AlA_lN×NN\times NHow the existing streams mix with each other
blb_lNNHow much of the new output each stream receives

The read and computation are

ul=Hl⊤al=∑s=1Nal,shl,s,ol=Fl(Norm⁡(ul)).(4)u_l=H_l^\top a_l=\sum_{s=1}^{N}a_{l,s}h_{l,s}, \qquad o_l=F_l(\operatorname{Norm}(u_l)). \tag{4}

The state update is

Hl+1=AlHl+blol⊤.(5)H_{l+1}=A_lH_l+b_lo_l^\top. \tag{5}

The attention or MLP still processes one dd-dimensional input. The extra streams expand the state carried between sublayers. Static HC learns fixed coefficients for each sublayer; dynamic HC generates coefficients from the current state, allowing different tokens to use different mixtures.

For a concrete two-stream example, take

H=[p⊤q⊤],a=(10),A=I,b=(01).(6)H=\begin{bmatrix}p^\top\\q^\top\end{bmatrix}, \qquad a=\begin{pmatrix}1\\0\end{pmatrix}, \qquad A=I, \qquad b=\begin{pmatrix}0\\1\end{pmatrix}. \tag{6}

The sublayer reads pp, computes o=F(Norm⁡(p))o=F(\operatorname{Norm}(p)), and leaves

H+=[p⊤(q+o)⊤].(7)H^+=\begin{bmatrix}p^\top\\(q+o)^\top\end{bmatrix}. \tag{7}

The next read can select pp, select q+oq+o, or combine them. Reading one stream did not force the output back into that same stream. This is a possible routing pattern, rather than an assigned meaning for either stream.

An old output reaches deeper layers through learned coefficients

Two steps of the HC recurrence give

H1=A0H0+b0o0⊤,H2=A1A0H0+A1b0o0⊤+b1o1⊤.(8)\begin{aligned} H_1&=A_0H_0+b_0o_0^\top,\\ H_2&=A_1A_0H_0+A_1b_0o_0^\top+b_1o_1^\top. \end{aligned} \tag{8}

The first output o0o_0 is still present, but its coefficients across streams have changed from b0b_0 to A1b0A_1b_0. Reading H2H_2 with a2a_2 assigns that output the scalar coefficient a2⊤A1b0a_2^\top A_1b_0.

More generally, define

PL,i=AL−1⋯Ai,PL,L=I.P_{L,i}=A_{L-1}\cdots A_i, \qquad P_{L,L}=I.

Then

HL=PL,0H0+∑i=0L−1PL,i+1bioi⊤.(9)H_L=P_{L,0}H_0+ \sum_{i=0}^{L-1}P_{L,i+1}b_i o_i^\top. \tag{9}

The coefficient of oio_i in the next read is aL⊤PL,i+1bia_L^\top P_{L,i+1}b_i. The write determines where a result starts; subsequent mixing determines where it travels; the read determines how much reaches the next computation.

This expansion also holds along a dynamic HC forward pass, using the coefficients produced on that pass. Those coefficients depend on the states, so the expansion does not turn the model into a linear function of its input.

One output gives every stream the same write direction

In HC, the newly added state is

ΔH=bo⊤=[b1o⊤⋮bNo⊤],rank⁡(ΔH)≤1.(10)\Delta H=b o^\top =\begin{bmatrix}b_1o^\top\\\vdots\\b_No^\top\end{bmatrix}, \qquad\operatorname{rank}(\Delta H)\leq1. \tag{10}

Every stream receives a multiple of the same output vector. Increasing NN adds destinations, but this write still supplies only one feature direction. Outputs from different sublayers can accumulate into a higher-rank state; the restriction is on the new contribution from one sublayer.

This suggested a simple change for our experiments: keep the contributions inside a sublayer separate until they reach the streams. Split the MLP’s hidden activations into qq groups and partition the down-projection’s columns to match:

h=[h1;…;hq],Wdown=[W1 ⋯ Wq],o=∑g=1qWghg⏟og.(11)h=[h_1;\ldots;h_q],\qquad W_{\mathrm{down}}=[W_1\ \cdots\ W_q],\qquad o=\sum_{g=1}^{q}\underbrace{W_gh_g}_{o_g}. \tag{11}

Each og∈Rdo_g\in\mathbb R^d is a contribution to the full output. In ordinary HC, stream ss receives bs∑gogb_s\sum_g o_g: the same scalar bsb_s multiplies every group. Our change gives each stream a separate coefficient for each group. Collect these coefficients in B∈RN×qB\in\mathbb R^{N\times q}, where BsgB_{sg} weights group gg for stream ss. With the contributions stacked as rows of O∈Rq×dO\in\mathbb R^{q\times d}, the write becomes

Original:H+=AH+b(∑g=1qog)⊤,Our write:H+=AH+BO.(12)\begin{aligned} \text{Original:}\quad H^+&=AH+b\left(\sum_{g=1}^{q}o_g\right)^\top,\\ \text{Our write:}\quad H^+&=AH+BO. \end{aligned} \tag{12}

For two groups, the contribution added to stream ss is

Original:bso1+bso2,Our write:Bs1o1+Bs2o2.(13)\begin{aligned} \text{Original:}\quad &b_s o_1+b_s o_2,\\ \text{Our write:}\quad &B_{s1}o_1+B_{s2}o_2. \end{aligned} \tag{13}

Originally, changing bsb_s scales both groups together. With separate coefficients, the stream can emphasize one group without scaling the other. We change which coefficients must be shared; training determines their values. As with HC, they can be learned directly or generated from the current state by a learned mapping. Setting Bsg=bsB_{sg}=b_s for every group recovers the original write.

Attention allows the same change: each head contributes WO,rzrW_{O,r}z_r through its slice of the output projection. We write these projected contributions separately, while keeping Q/K/V and attention over tokens unchanged.