Zero Labs
Industry News / AI

mHC: Manifold-Constrained Hyper-Connections. Explained Through Equations, Architecture, Code

Source · Towards AI By JAIGANESAN

From the publisher’s feed, collected in the ZeroLabs newsroom.

mHC: Manifold-Constrained Hyper-Connections. Explained Through Equations, Architecture, Code and Visual WorkflowFrom the plain skip connection, to Hyper-Connections, to the doubly stochastic matrix that made them trainable at 27BAlmost every component inside a transformer has been replaced or updated at least once. Attention became multi-query, then grouped-query, then latent. The feed-forward network became a sparse mixture of experts, then a fine-grained one with shared experts. LayerNorm became RMSNorm and moved to the front of the block. Adam is being challenged by Muon. Positional encoding has been rewritten many times.The residual connection is the one component that didn’t change. It is the x = x + F(x) that closes every block, dates from 2014–2015, and it survived every one of those replacements because a deep network can't do without the operation it performs.In December 2025, DeepSeek published a paper that touches it. Hyper-Connections, a ByteDance design from 2024, had already widened the single residual stream into several and replaced the fixed skip with learned mixing. That improved accuracy, and it also destabilised training at scale. DeepSeek’s paper, Manifold-Constrained Hyper-Connections (mHC), is the version that trains.In 2026, the mHC got shipped. The DeepSeek-V4 technical report and the V4-Pro model card list mHC among the architectural upgrades over V3, next to a hybrid attention by combining Compressed Sparse Attention (CSA) with Heavily Compressed Attention (HCA), and with the Muon optimizer. The attention change is about the cost of a million-token context, and it is a separate piece of work. This article is all about the residual path.The problem mHC solves is a training failure, and the numbers set the scale. Hyper-Connections work on a 27B mixture-of-experts model they lift BBH by five points and GSM8K by six and a half from Base model. But in DeepSeek’s own 27B run, the Hyper-Connections loss surges around step 12,000 and the gradient norm spikes with it. The amplification the learned mixing applies to a signal on its way through the stack peaks near 3,000, against an ideal of exacly 1. With mHC that amplification stays under about 1.6, the gradient norm stays comparable to the plain baseline’s, and the loss ends 0.021 below it.In this article, we follow the chain in order, the residual connection and the problem it was introduced to solve, then Hyper-Connections and the different problem they solve, then the instability they create at depth, and finally the manifold constraint (Hyper-Connections) that removes it. At each step we ask the same question. What does this mechanism fix, and what does it leave behind for the next one? A systems section covers the memory traffic, because that part of the paper is what makes the technique usable at all.A note on the figures, Each one shows a transformation: the tensors going in, the operation, and the tensor coming out, labelled with symbols and with the equation it draws set above it. To keep the shapes concrete, every figure uses one running example: a sequence of 5 tokens, a model width C of 1024, and, once the stream is widened, an expansion rate n of 4. A shape reads tokens × streams × width. So 5 × 1024 is one row of 1024 numbers per token, and 5 × 4 × 1024 is four such rows per token, one per stream. The mHC paper writes the same shapes per token, 1 × C for a single vector and n × C for the widened stream. The figures here do the same, with a row on each card for each of the 5 tokens: a stack of cards is the 4 streams, a single card is one vector per token. Each figure repeats the key for its own shapes in a line at the bottom.1. The Residual ConnectionA residual connection takes the input of a layer, passes a copy through the layer, and adds the result back to the input. With x_l the C-dimensional input to layer l and F whatever the layer computes, the update now isEquation 1, Source: https://arxiv.org/pdf/2512.24880F (Function) is left open on purpose. In a ResNet it's a stack of convolutions. In a transformer it's an attention block or a feed-forward network, each wrapped in its own residual connection, and in parallel-block designs it's both at once. The residual connection doesn't care, which is why it has outlived every particular choice of F.If you’re not sure how a transformer block works, or what attention, the feed-forward network and a mixture of experts do inside it, my earlier articles cover each one in the same style as this piece: Large Language Model (LLM): In and Out for the block as a whole, A Visual Walkthrough of DeepSeek’s Multi-Head Latent Attention for attention, and The Architecture of Mistral’s Sparse Mixture of Experts and Revolutionizing AI with DeepSeekMoE for the feed-forward network and its sparse form. They’re two years old, and the mechanisms haven’t moved. Everything below treats F as a box and never go much deeper into it.To keep every shape concrete and make it understandable, the figures follow one running example from here to the end: a sequence of 5 tokens at a model width C of 1024. At any layer, the plain residual stream for that sequence is a 5 × 1024 matrix, one row per token.Figure 1: The residual connection in the paper’s notation, for the running example. Each card is 5 × 1024: one row per token, 1024 numbers per row.In Figure 1, the x_l (Blue) is what arrives at the layer: for our five tokens, five rows of 1024 numbers (Vector). The amber card is F(x_l, W_l), what the layer computed from it, and it has the same shape. The green card is x_{l+1}, their sum, and it becomes the input to the next layer. The addition is point-wise: the first number of a token's output row is the first number of its x_l row plus the first number of its F row, and the same holds at every one of the 1024 positions and for each of the 5 tokens on its own. Nothing scales either term and nothing crosses between positions or between tokens, so the output keeps the shape of the input and the next block can repeat the same step. It's the simplest operation in the block. The reason it's there only shows up when we look at the backward pass.Figure 2: Gradient flow through a deep stack, with and without a residual connection. Example scenario: each layer attenuates the gradient by a factor of 0.8.On the left of Figure 2 there is no skip. The gradient travelling back from the loss passes through every layer in turn and is multiplied by each layer’s local derivative. At a factor of 0.8 per layer, four layers reduce it to 0.41 of its original size, and forty layers to roughly 0.0001. The layers nearest the input receive almost no learning signal. The 0.8 is an illustration, since a real layer’s derivative is a matrix rather than a scalar, but the compounding is real. Before 2015 it was one reason that adding layers frequently made a network worse.On the right, the addition gives the input a second route forward. If we differentiate Equation 1, the Jacobian of the block is I + dF/dx_l. The identity term scales every coordinate by exactly 1 and mixes nothing. It passes through no weights and no nonlinearity, and it doesn't depend on anything the layer has learned. So whatever the layer's own Jacobian does, the gradient arriving at x_l contains a copy of the gradient at x_{l+1} that nothing has multiplied. Across a whole stack, the gradient at layer l is the gradient at layer L times (I + a sum of layer terms), and that I is the identity path composed through every block in between. The additive identity term is what keeps depth from costing signal.The same property shows in the forward direction. If we unroll Equation 1 from any layer l to any deeper layer L, we getEquation 2, Source: https://arxiv.org/pdf/2512.24880and the coefficient on x_l is exactly 1 at any depth, with no approximation and no averaging across a batch. This is the identity mapping property, and it's the thing to hold on to, because everything that follows is about losing it and getting it back. Identity refers to the route that carries the original signal forward. The layers still do their work, but that route does nothing to the signal, so contributions accumulate additively instead of compounding multiplicatively.A modern transformer block also contains normalisation, and the moment it enters the picture you have to decide where to put it. The two available answers fail in opposite ways.Figure 3: Pre-norm and post-norm.Pre-norm-> on the left of Figure 3, places the normalisation inside the branch. The residual path from x_l to the addition carries nothing and stays the clean identity route described above. This is what almost every production model ships. The cost appears at depth as representation collapse: the deeper layers all make small and mutually similar corrections to a signal already determined beneath them, and they gradually stop differing from one another in any way that matters.Post-norm-> on the right, places the normalisation after the addition. Every layer’s output now has to survive a renormalisation of the whole stream, which keeps the layers distinct. The cost is that the normalisation now sits on the residual path, exactly what pre-norm exists to keep clear, so the undamaged gradient route is gone.Choosing either one buys the other one’s problem. The researchers from ByteDance (Hyper-Connections) named this the seesaw effect. Rather than pick a side, they tried whether the network could be given enough room to avoid choosing.2. Hyper-ConnectionsmHC repairs an existing idea, so the existing idea comes first. That idea is Hyper-Connections, published by ByteDance Seed and presented at ICLR 2025.The seesaw exists because a single residual stream has to serve two incompatible jobs at once. The Hyper-Connections answer gives the network several copies of the residual state and lets it learn the trade-off separately for every layer. Everything below uses the number of copies the expansion rate n = 4 (the mHC paper used in all it’s reports). The residual stream for each token becomes an n × C matrix: n vectors of width C instead of one. In the running example, the 5 × 1024 stream of Figure 1 becomes 5 × 4 × 1024: for every token, four rows of 1024 numbers instead of one. The figures below draw the widened stream as a stack of n cards, one per stream, with the 5 tokens as the rows of each card, and a single card is an ordinary vector per token, which is what the layer itself still works on.Figure 4: A standard residual connection and Hyper-Connections at expansion rate n = 4, drawn for one of the 5 tokens. The four streams are wires, and each is copied at the dot. One copy runs straight through H_res and comes out as the mixed stream h_res. The other is read by one H_pre weight per stream and summed into h_in, the single 1 × C vector the layer sees. The layer’s 1 × C output h_out is weighted by H_post, one weight per stream, and fanned out as h_post. The next stream is h_res + h_post.Once there are four streams instead of one, the layer needs a way to talk to them, and Hyper-Connections supplies three small matrices for the purpose. H_pre, of shape 1 × n per token (a row of four weights for each of the 5 tokens, so 5 × 1 × 4 in the figures), collapses the four streams into the single C-wide vector the layer expects(h_in). The layer returns a single C-wide vector, h_out. H_post, the same size as H_pre, distributes h_out back across the four streams as h_post. H_res, of shape n × n, decides how the streams mix with one another as they pass the layer, and its output is h_res. Both branches start from the same x_l, and neither feeds the other. Put together, the layer update becomesEquation 3, Source: https://arxiv.org/pdf/2512.24880which in the figure’s names is x_{l+1} = h_res + h_post.It’s easy to miss how little changes inside the block. Attention and the feed-forward network still receive exactly one vector of width C per token and still return one, and the parameter count of the layer proper is unchanged. Everything new lives in three matrices totalling n² + 2n numbers per token per layer, which at n = 4 is twenty-four numbers, or 120 for our five tokens.How the four streams start. Nothing in the network produces four different vectors at the entry. The embedding of each token, a single C-wide vector, is copied n times: the expansion is x -> [x, x, x, x] at n = 4, and the Hyper-Connections paper defines the initial hyper hidden matrix exactly that way. For our five tokens, the 5 × 1024 embedding matrix becomes 5 × 4 × 1024 by copying, before layer 0, and all four streams carry the same vector. That makes the streams interchangeable at the entry: relabelling them, together with the matching relabelling of the connection matrices, computes the same function, a permutation symmetry that later work on stream collapse in Hyper-Connections makes explicit.Figure 5: The read-out and the write-back on the running example. The stack of four cards is the 5 × 4 × 1024 residual stream, one card per stream and one row per token. H_pre, a row of four weights per token, collapses it to h_in, a single 5 × 1024 card. The transpose of H_post expands the layer’s output h_out back to one card per stream, h_post.In the upper half of Figure 5, H_pre is four numbers per token, one per stream. The vector handed to the block for that token is the weighted sum down the four streams with those four weights, taken coordinate by coordinate. The result is a single vector of width C per token, 5 × 1024 for the sequence, exactly what an ordinary transformer block (Attn or FFN or Attn+FFN, MoE, etc) expects.In the lower half, H_post performs the reverse operation with its own four numbers. The block returns one vector, and H_post decides how much of it each of the four streams receives. Because the weights differ, the layer can push its result hard into one stream while leaving another almost untouched.The third matrix is the interesting one, and it’s also the one responsible for everything that goes wrong in the next section.Figure 6: Equation 3 drawn in blocks. H_res, one 4 × 4 matrix per token, mixes the stacked streams on the left of the plus sign, and the layer’s single-card output h_out is written back across the streams on the right.H_res is a 4 × 4 matrix per token, and each of its rows describes one output stream as a blend of all four input streams. For example, a row that reads 0.72, 0.11, 0.09 and 0.08 says that the new first stream is mostly the old first stream, with small contributions from the other three. Each row does the same with its own weights. Each of the 1024 coordinates is treated independently, so the mixing happens strictly across streams and never across the model dimension, and never across tokens either.What this buys is control over distance. A layer can write its result into the first stream through H_post while the fourth stream carries an older copy of the signal straight past it, and the H_res three layers further up can mix that fourth stream back in. The network chooses, per layer and per token, how far forward each piece of information travels before it is recombined.The Hyper-Connections paper describes this as the model learning to rearrange its own layers, and the description is literal. A stream that skips two layers and rejoins afterwards is a reordering of the network for that token. That is also what dissolves the seesaw. Instead of one setting for the whole network, one stream can stay a clean identity route for gradient flow while another mixes aggressively so layers stay differentiated, both at once, in the same block.The three matrices can be plain learned parameters (static Hyper-Connections). They can also be produced from the hidden state itself, which makes them dynamic. In the original formulation, with x_norm the RMS-normalised stream,Equation 4with the same construction for H_post and H_res. The b terms are the static part and the tanh term is the input-dependent part. The α terms are learned scalar gates initialised close to zero, so training begins from the static behaviour and the network learns for itself how much input-dependent routing it wants. mHC keeps this split between a static bias and a dynamic score but generates the score a little differently. The manifold section we are gonna see explore that version in full.One detail confirms that this is a generalisation rather than a replacement. If we set n = 1, every one of the three matrices collapses to a single scalar. With those scalars fixed at 1, Equation 3 is Equation 1 again. The Hyper-Connections paper shows pre-norm and post-norm as exactly such non-trainable special cases, which is a large part of why the trainable version worked: on both language and vision pre-training it beat the plain residual consistently.Where Hyper-Connections BreakEquation 3 describes one layer, and models are not one layer. Unrolling it across L layers, exactly as Equation 2 unrolled the plain residual, turns the residual path into a product,Equation 5Setting the two coefficients side by side is the whole argument of the paper. For the plain residual the coefficient on x_l is 1. For Hyper-Connections it isEquation 6which is a product of L freely learned matrices. Nothing in Hyper-Connections constrains that product. Each H_res is optimised independently to reduce the loss at its own layer, and no term in the objective ties the composite across layers to anything in particular.The consequence is geometric. A product of matrices that are each slightly larger than the identity grows exponentially in the number of factors, and a product of matrices each slightly smaller than the identity shrinks exponentially. Very little per-layer drift is needed before thirty or sixty layers of it becomes unmanageable.Figure 7: The composite of per-layer residual matrices. Example scenario: each layer’s matrix is the identity plus a random perturbation of σ = 0.3, at n = 4.Figure 7 is Equation 6 in blocks. The table beside it takes the same example to realistic depths. Each layer’s matrix is the identity plus a small random perturbation (Small variation), and the table reports the amplification the composite applies to whatever was sitting in the stream at layer l. It is Equation 6 evaluated on random example matrices, which I think is, enough to show the shape of the problem.Figure 8: Largest singular value of the product of per-layer residual matrices, against depth. Median of 24 runs, shaded band is the 10th to 90th percentile, σ = 0.3, n = 4. Note: Experiment results with example matrices.(From example experiment result using example matrices) The unconstrained product sits near 4.5 times by layer ten, 64 times by layer thirty and roughly 513 times by layer sixty in the median run. The spread across runs is wide enough that the unlucky ones are considerably worse. This is a deliberately simple simulation with fixed random perturbations, and if anything it understates the problem. In a real network those matrices are being optimised, and the drift they accumulate is not zero-mean.The mHC paper measures the same quantity inside its 27B model. It calls the largest absolute row sum of the composite matrix the forward gain and the largest absolute column sum the backward gain. It counts each transformer block as two layers, because attention and the feed-forward network each carry their own connection, so the 30-block model is 60 layers deep on this axis. For Hyper-Connections the composite gain peaks at about 3,000.From paper what we can understand is, Over the full 60 layers the composite has entries in the hundreds, its row sums run from about −500 to +510, and its column sums sit between about −220 and −260. The ideal for every one of them is 1. The consequence in training appears where that measurement predicts it: the Hyper-Connections run hits a loss surge around step 12,000, closely correlated with a spike in the gradient norm, while the baseline and the mHC run do not.Figure 8(a): Loss gap against the baseline (left) and gradient norm (right) over 50,000 steps of the 27B run. Source: the mHC paper.On the left, both widened models start about 0.06 below the baseline and the two curves sit on top of each other until step 12,000. There the Hyper-Connections curve climbs faster, and its lead shrinks to about 0.016 by the end against mHC’s 0.021. The surge doesn’t blow the run up. It quietly costs about 0.005 of loss that is never earned back. On the right, the gradient norm of the baseline and of mHC decays smoothly, while Hyper-Connections jump from about 0.10 to 0.15 at the same step 12,000 and stay noisy there for thirty thousand steps. That plateau is what a composite gain in the thousands does to the backward pass, and the fact that both panels break at the same step is the correlation the mHC paper explained and solved (I think).From what we have seen so far, there are three fixes we might try before we get to the paper’s, and each fails in a way that narrows down the real requirement.The first is to normalise the streams after mixing. That is post-norm reintroduced one level up: it bounds the magnitude, but it puts a normalisation back onto the residual path, trading the explosion for the gradient problem Hyper-Connections were built to escape.The second is to penalise H_res towards the identity with weight decay. A penalty is a soft constraint. It reduces expected drift without bounding the product, and it applies uniform pressure across layers while the drift that matters is whatever survives the multiplication.The third is to divide H_res by its own largest singular value at every step. That gives a per-layer bound, and the product then cannot amplify, but nothing stops it attenuating. Sixty matrices with largest singular value 0.95 multiply out to 0.046, which swaps an exploding signal for a vanishing one.All together, those failures produce the specification. The matrix must not amplify, so its largest singular value should be at most 1. It must not systematically attenuate either, or the signal dies instead of exploding. And whatever property delivers those two must be closed under multiplication, because otherwise it holds for a single layer and says nothing about the product in Equation 6. The third condition is the one that does the work, and it’s the one all three remedies ignore.3. The Manifold Constraint (Hyper Connections)There is a well-studied set of matrices that satisfies all three conditions at once: the doubly stochastic matrices, in which every entry is non-negative, every row sums to 1 and every column sums to 1. Geometrically they form a convex polytope known as the Birkhoff polytope.Figure 9: A doubly stochastic matrix with example values, with row sums on the right and column sums underneath.All three conditions follow from the definition. Because the rows are non-negative and sum to 1, multiplying by H_res forms a convex combination of the four streams. A weighted average cannot exceed the largest thing being averaged, so the matrix cannot amplify. Because the columns also sum to 1, the total across streams is conserved exactly, so nothing drains away.And the product of two doubly stochastic matrices is itself doubly stochastic, so the sixty-layer product in Equation 6 is still on the manifold, still has largest singular value at most 1, and still conserves the stream total.That last property is the whole design. Closure under multiplication turns a per-layer constraint into a guarantee about the quantity that causes the instability. The flat line in Figure 8 is that guarantee drawn: 1.000 at layer ten, at layer thirty, at layer sixty, and as far beyond as anyone cares to go.The guarantee has a cost that the paper lists as a feature. A doubly stochastic matrix conserves the total across streams and cannot amplify, but it doesn’t preserve any individual stream, and the paper’s own 60-layer composite has every entry between 0.21 and 0.29, close to the uniform 0.25. Mixing increases monotonically with depth, which the paper calls a feature-fusion mechanism. There is an obvious objection. The network still has to learn H_res, and handing it a fixed doubly stochastic matrix would remove the mechanism entirely. The construction that resolves this has two halves. First, generate unconstrained scores from the stream. Then project those scores onto the manifold with a differentiable operation, so that gradients keep flowing back into the scores.The score generation is where mHC departs slightly from Equation 4. Instead of reading each stream separately, it flattens the whole n × C stream of a token into one vector of length nC and normalises it. A plain linear map then projects that vector, so every score sees the entire stream,Equation 7with the same form for H_pre_raw and H_post_raw using φ_pre and φ_post. Here φ_res is an nC × n² matrix, mat reshapes its n² outputs into an n × n grid, b_res is the static bias, and α_res is the small learned gate.Figure 10: Equation 7 in blocks, on the running example. The top row flattens and normalises the stream to 5 × 4096, and the lower rows produce the raw scores for H_res and H_pre, one set per token, from projections and biases that every token shares.For each of our five tokens, the flattened, normalised stream is a single row of 4096 values, so 5 × 4096 across the sequence. Multiplying it by the 4096 × 16 projection, which is shared by every token, gives sixteen numbers per token. They are reshaped into a 4 × 4 grid, scaled by α_res, and added to the static bias, which is also shared, so the result is five 4 × 4 score matrices, one per token. These are still scores, so they can be negative, their rows sum to nothing in particular, and they are not yet a valid residual matrix.The projection that turns those scores into a doubly stochastic matrix is Sinkhorn-Knopp: exponentiate the scores so every entry is positive, then alternately normalise the columns and the rows until both sum to 1.Equation 8Equation 9Figure 11: The projection as a loop, on one token’s 4 × 4 score matrix. T_c divides each column by its sum, T_r divides each row by its sum, and the pair repeats twenty times. The five tokens’ matrices go through it independently.Figure 12: The same projection on one example 4 × 4 matrix, with row sums on the right and column sums in the last row of each panel.Figure 12 follows a single matrix left to right through the procedure. The raw scores (Example scores) in the first panel are whatever the network produced, and their row and column sums are nothing in particular. Exponentiating makes every entry positive. Dividing each column by its own sum makes the column sums 1 and leaves the row sums wrong.Dividing each row by its own sum then makes the row sums 1 and pushes the column sums off again, though by less than before. The row sums after the second step are 1.19, 1.00, 0.90 and 0.91, and the column sums after the third are 0.93, 1.02, 0.99 and 1.06.Described that way it sounds as if it should never terminate. It converges, and on a matrix this small it converges quickly, which is why the paper runs it for a fixed twenty iterations and stops. The paper attributes the small residual error to that fixed count, and the order of the iteration says which side the error lands on. The loop ends on a row normalisation, so after twenty rounds the row sums are exactly 1 and the column sums are approximately 1.But this asymmetry the paper’s own measurements show. The forward gain, a row sum, sits at 1, while the backward gain, a column sum, drifts, and across the whole 60-layer composite the drift reaches about 1.6 at its worst. Against the 3,000 of the unconstrained version that is three orders of magnitude. It is also the number to quote, and it’s why the constraint holds to within the tolerance of twenty iterations rather than exactly.H_pre and H_post get a lighter treatment, and the reason explains why the paper is really about one matrix rather than three. Both are applied once on the way into the block and once on the way out. They never appear inside the product in Equation 6, so they cannot produce the compounding failure and don't need the manifold constraint.The only thing they must avoid is cancelling signal by taking negative values, so Equation 8 squashes them through a sigmoid. The factor of two on H_post lets the write-back exceed 1, up to a gain of 2 (Not sure why the paper choosen this ceiling). But what we can understand from the arithmetic is a plain residual writes back with gain 1, and 2σ puts that value at a logit of 0, the middle of the sigmoid, rather than at its ceiling. H_pre gets no factor because the layer normalises its input anyway, so only the ratio between streams survives.Now let’s move to code. The projection itself is four lines of PyTorch. We run it in log space, so the exponential of a large score is never materialised. That is the right default rather than an optimisation, because the naive version overflows in exactly the situation the constraint exists to handle, a score matrix that has drifted.import torchdef sinkhorn_knopp(logits: torch.Tensor, t_max: int = 20) -> torch.Tensor: """Project an n x n score matrix onto the doubly stochastic manifold.""" log_p = logits for _ in range(t_max): log_p = log_p - torch.logsumexp(log_p, dim=-2, keepdim=True) # columns -> 1 log_p = log_p - torch.logsumexp(log_p, dim=-1, keepdim=True) # rows -> 1 return log_p.exp()Two logsumexp subtractions per iteration, twenty iterations, and the gradient passes through all of them. That is the entire constraint.Because the scores are exponentiated first, b_res is a logit, not the mapping itself. An identity b_res does not give an identity H_res: e⁰ turns the zeros into ones, e¹ puts 2.7 on the diagonal, and Sinkhorn-Knopp then leaves about 0.48 on the diagonal and 0.17 elsewhere. Four times the identity lands H_res at 0.95 on the diagonal after the projection. The module below uses that value, reads mostly from one stream through H_pre, and writes 1.0 into every stream through H_post. With the α gate at the mHC paper’s 0.01, the block starts close to an ordinary pre-norm residual connection, the same starting point the Hyper-Connections paper uses for the unconstrained version. Training moves it away from there.Wrapping a transformer layer with it is not much longer. The module below produces the three sets of scores from the flattened and normalised stream, projects H_res onto the manifold, squashes H_pre and H_post through sigmoids, then performs the three contractions: collapse the streams, run the layer, write the result back. We pass the layer in from outside and call it without modification, which is what makes this droppable into an existing model.The code carries batch and sequence as leading axes, so its residual stream is (B, T, n, C), which for the running example with a batch of one is (1, 5, 4, 1024). One naming difference to keep in mind: in the code, h_res, h_pre and h_post are the three mappings after their constraints, H_res, H_pre and H_post and merged for h_in and out for h_out. If you are gonna adapt it, keep the static values, zero score projections and small alpha gates make the block begin training with its static behaviour, and the static biases are set so that the mappings after projection start near a plain residual connection.import torch.nn as nnclass ManifoldHyperConnection(nn.Module): """x_l+1 = H_res @ x_l + H_post^T * F(H_pre @ x_l)""" def __init__(self, dim, layer, n=4, t_max=20, alpha_init=0.01): super().__init__() self.n, self.t_max, self.layer = n, t_max, layer self.norm = nn.RMSNorm(n * dim) # dynamic part: scores generated from the flattened residual stream self.phi_res = nn.Linear(n * dim, n * n, bias=False) self.phi_pre = nn.Linear(n * dim, n, bias=False) self.phi_post = nn.Linear(n * dim, n, bias=False) for p in (self.phi_res, self.phi_pre, self.phi_post): nn.init.zeros_(p.weight) # learned gates, initialised small: start static, learn to be dynamic self.alpha_res = nn.Parameter(torch.full((1,), alpha_init)) self.alpha_pre = nn.Parameter(torch.full((1,), alpha_init)) self.alpha_post = nn.Parameter(torch.full((1,), alpha_init)) # static part, chosen so the constrained mappings start as a pre-norm # residual: H_res ~ I after the projection, H_pre reads stream 0, # H_post writes 1.0 into every stream self.b_res = nn.Parameter(4.0 * torch.eye(n)) self.b_pre = nn.Parameter(torch.full((n,), -4.).index_fill_(0, torch.tensor([0]), 4.)) self.b_post = nn.Parameter(torch.zeros(n)) def forward(self, x): # x: (B, T, n, C) B, T = x.shape[:2] x_flat = self.norm(x.reshape(B, T, -1)) h_res = self.alpha_res * self.phi_res(x_flat).view(B, T, self.n, self.n) + self.b_res h_res = sinkhorn_knopp(h_res, self.t_max) # the constraint h_pre = torch.sigmoid(self.alpha_pre * self.phi_pre(x_flat) + self.b_pre) h_post = 2 * torch.sigmoid(self.alpha_post * self.phi_post(x_flat) + self.b_post) merged = torch.einsum('btn,btnc->btc', h_pre, x) # n x C -> C out = self.layer(merged) # untouched layer return (torch.einsum('btmn,btnc->btmc', h_res, x) # stream mixing + torch.einsum('btn,btc->btnc', h_post, out)) # write-backSome things are worth checking when you run this, First, the projection never produces an exact zero. Sinkhorn-Knopp drives entries towards zero without reaching it, so the matrix stays strictly inside the polytope and never on its boundary, and no gradient is lost to a hard zero. Second, on a deliberately peaked score matrix, one that wants to be a permutation with a tie in it, the rows come out exactly 1 and the columns land about two per cent off, because the loop ends on a row normalisation. The mHC matrices from paper for layers 30 and 60 of its trained model are close to permutations, so the trained model lives in that regime rather than the random one, and that is where the measured 1.6 comes from.Composing sixty such matrices, with the median of twenty-four random draws, gives the two curves of Figure 8: about 4.5, 64 and 513 times at ten, thirty and sixty layers for the unconstrained version, and 1.000 at every depth for the constrained one. The constrained row holds by construction rather than by tuning, which is a different from a measured improvement.Figure 13: One manifold-constrained hyper-connection block. The top row generates and constrains the three mappings, and the dashed lines show where each is applied.Figure 13 is the whole block in one picture, on our running example. One copy of the 5 × 4 × 1024 stream is flattened, normalised and turned into the three mappings, one set per token. A second is read out by H_pre, passed through the layer (F) and written back by H_post, and a third is mixed by H_res. The last two meet at the addition, and the result is the next layer's stream.Making It AffordableThis is probably the easiest part of the paper to skip, but it’s also where the mathematics above either makes it into a real training run or stays on paper. Equation 3 adds almost no arithmetic. For a model 2,560 wide at n = 4, the score projections come to roughly a quarter of a million parameters per connection. Attention and the feed-forward network each get their own, so a 30-block model carries about 15 million, which is nothing against a feed-forward network measured in hundreds of millions per layer.The cost is not in the parameters but in the memory traffic. A plain residual connection reads the hidden state, reads the layer output and writes the sum, which is 2C in and C out. Hyper-Connections at expansion rate n must read and write a stream that is n times wider, and must also materialise the intermediate products along the way. From the paper, the number is (5n + 1)C read and (3n + 1)C written per token per layer, plus a few dozen elements for the coefficients themselves.Figure 14: Memory traffic for the connection itself, per layer, in units of the C-dimensional hidden state, from the accounting in the mHC paper.At n = 4 the connection moves 34C of data per layer against the plain residual’s 3C, more than eleven times the memory movement in exchange for a quarter of a million extra parameters. On current accelerators an operation with that ratio of bytes moved to arithmetic performed runs at the speed of the memory system rather than the compute units, so it is slow however few operations it performs. This is the memory wall, the same wall that shaped FlashAttention.The mHC paper closes most of that gap with three solutions, the method itself does not change. First, the three operations that touch the widened stream are combined into a single step, so the data is loaded from memory once and written back once instead of three times. Most of the extra traffic disappears there. Second, the connection’s intermediate values are not saved during the forward pass. They are cheap to compute, so they are simply recomputed when the backward pass needs them, and only the stream entering each group of layers is kept in memory. Third, a stream n times wider also has to be sent between GPUs n times more often, and the researchers schedules that transfer so it happens while the GPU is busy with attention, rather than making the GPU wait for it.The reported cost is 6.7 per cent additional training time at n = 4, and the V4 report gives the same 6.7 per cent for the production implementation, measured against the overlapped pipeline stage. At that overhead the constraint is cheap enough to carry into a production run, which is what V4 did.ResultsThe paper trains mixture-of-experts models at three scales, plus a fourth configuration extending the smallest over a much longer token horizon.Table 1: Model configurationsThe headline comparison is the 27B model at 262 billion tokens.Figure 15: 27B mixture-of-experts model trained on 262B tokens. Scores reported in the mHC paper.From Figure 15 what w can understand is, widening the residual stream works, Hyper-Connections move BBH from 43.8 to 48.9, MMLU from 59.0 to 63.0 and GSM8K from 46.7 to 53.2, none of which are marginal gains. And, the manifold constraint adds comparatively little on top. It takes BBH from 48.9 to 51.0, DROP from 51.6 to 53.9 and PIQA from 79.9 to 80.5, while on MATH it is slightly behind at 26.0 against 26.4. The final reduction in training loss against the baseline is 0.021.The constraint is offered as the thing that makes the Hyper-Connections numbers safe to rely on, rather than as an accuracy improvement over them. The run that produced those numbers contained a loss surge at step 12,000, a quarter of the way through its 262 billion tokens, and a run that surges there is not one we would commit thirty trillion tokens to.The component ablation makes the division of labour explicit.Table 2: Hyper-Connections component ablation, Source: https://arxiv.org/pdf/2512.24880H_res on its own delivers 0.022 of the total 0.027, and H_pre and H_post contribute the remaining 0.005 between them. Set against the manifold section, the architecture becomes coherent. The component contributing almost all of the accuracy is the same one that was destabilising training. That is why the manifold constraint is applied to that matrix and the other two receive only a sigmoid.The fourth configuration in Table 1 answers a real objection. A 3B model trained on 1.05 trillion tokens is roughly twenty-seven times the token budget of the other 3B run. The mHC paper frames it as a token-scaling experiment, and that is also what makes it the right check on a stability claim. Short runs are where instabilities hide, and extending a small model over a long horizon is the inexpensive way to see whether the gap narrows as the baseline catches up.Two questions hide in that experiment, and they get different answers. Did mHC solve the problem it set out to solve? Understanding from paper, yes, the 27B run shows no surge, the gradient norm tracks the baseline, and the composite gain stays under 1.6 where Hyper-Connections reached 3,000.Figure 16: Token Scaling curve, Scaling Experiments. Source: mHC PaperDoes the benefit hold as training goes on? From figure 16, the loss gap for the 3B run narrows from about 0.023 to about 0.015 across the trillion tokens, still clearly in mHC’s favour but a third smaller by the end. The compute-scaling curve across 3B, 9B and 27B shows, only a marginal attenuation. So that I guess, the stability claim from paper holds, and the advantage is real but decays gently with both tokens and scale instead of holding flat.Where It Ended UpDeepSeek-V4-Pro is a 1.6 trillion parameter mixture-of-experts model with 49 billion active parameters, 61 transformer blocks at a hidden width of 7,168, pretrained on 33 trillion tokens with a one-million-token context window. mHC among the architectural changes over V3, with the expansion rate at 4 and the Sinkhorn iteration count at 20, the same values as the mHC paper.The other headline change in V4 is the attention design, and it is a useful reminder of what mHC is not. V4 alternates two attention variants. Compressed Sparse Attention compresses the key-value cache of every four tokens into one entry and then lets each query attend sparsely to 1,024 of those entries. Heavily Compressed Attention compresses every 128 tokens into one entry and attends densely.That design is about the cost of a million-token context. mHC is about the stability of the path that carries a token’s state through 61 blocks, and the two sit in different parts of the block without interacting.ConclusionAny change to a residual path deserves that test, because a change that looks harmless at a single layer can still be ruinous at sixty when the governing quantity is a product rather than a sum.From my observation, mHC gives stability than a large jump in benchmark scores. Hyper-Connections buy the accuracy and the manifold constraint buys the right to keep it. The limitation to carry forward is the drift towards uniform averaging with depth. If the technique has a weak point, we expect it to be there. The hybrid CSA and HCA attention that shipped beside mHC in V4 is the other half of that model’s story, and it deserves a walkthrough of its own, we will explore that in next part.A personal note to close. This is my first article after a gap of two years, and it won’t be the last. It also arrives while I’m exploring new roles, in India or remote, on the training and applied side of the AI. If the piece was useful and you know a team that would fit, a referral or a message would mean a lot.🔗 LinkedIn: jaiganesan-n👏 If you got something out of this, a few claps help more people find it.ReferencesZhenda Xie, Yixuan Wei, Huanqi Cao, Chenggang Zhao, Chengqi Deng, Jiashi Li, Damai Dai, Huazuo Gao, Jiang Chang, Kuai Yu, Liang Zhao, Shangyan Zhou, Zhean Xu, Zhengyan Zhang, Wangding Zeng, Shengding Hu, Yuqing Wang, Jingyang Yuan, Lean Wang, Wenfeng Liang, mHC: Manifold-Constrained Hyper-Connections (2025), Research paper (arXiv:2512.24880)DeepSeek-AI, DeepSeek-V4: Towards Highly Efficient Million-Token Context Intelligence (2026), Research paper (arXiv:2606.19348)DeepSeek-AI, DeepSeek-V4-Pro, Hugging Face model card (huggingface.co/deepseek-ai/DeepSeek-V4-Pro)Defa Zhu, Hongzhi Huang, Zihao Huang, Yutao Zeng, Yunyao Mao, Banggu Wu, Qiyang Min, Xun Zhou, Hyper-Connections (2024), Research paper (arXiv:2409.19606), ICLR 2025Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun, Deep Residual Learning for Image Recognition (2015), Research paper (arXiv:1512.03385)Richard Sinkhorn, Paul Knopp, Concerning nonnegative matrices and doubly stochastic matrices (1967), Pacific Journal of Mathematics 21(2)mHC: Manifold-Constrained Hyper-Connections. Explained Through Equations, Architecture, Code was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.