Why Hyper-Connections Are Unstable: Improving Them with Doubly Stochastic Matrices

    Hyper-Connections extend residual streams into multiple parallel paths, offering greater flexibility than standard residual connections—but this flexibility introduces training instability. This article explains why the learnable residual mixing matrix causes signals to grow or decay exponentially across layers, and how constraining it to doubly stochastic matrices restores stability while preserving adaptability. Includes schematic code, a log-domain Sinkhorn projection implementation, and a practical checklist for deployment.

    Residual Connections: The Information Highway of Deep Networks

    Each Transformer layer contains two types of sublayers: attention and a feed-forward network (FFN). A standard residual connection takes the form x_{l+1} = x_l + F(x_l), where F denotes the sublayer’s computation. The sublayer produces an increment that is added to the existing representation rather than replacing it.

    Residual connections offer two direct benefits. First, the original information is preserved—each layer only needs to learn “what to add.” Second, during backpropagation, gradients can flow directly through the identity path, mitigating gradient vanishing in deep networks.

    Consider the sentence “Xiao Zhou worked overtime until early morning last night; he kept yawning during the meeting the next day.” The representation of the second “he” must simultaneously carry information such as “worked overtime,” “is tired,” and “refers to Xiao Zhou.” The attention layer first gathers relevant content from earlier context, and the FFN then applies nonlinear processing to it. Both results are added back to the residual stream as increments. This is only a semantic illustration and does not involve actual model activations. A single layer’s increment is small, but layer-by-layer accumulation builds a complete semantic representation.

    In the standard architecture, the residual stream’s width d remains constant throughout the network.

    Hyper-Connections: Extending One Residual Path to Many

    A single residual stream has only one channel, so information written by each layer can only be summed directly, with no selectivity. The idea behind hyper-connections is to replicate the residual stream into n parallel copies, where n is usually a small integer such as 2 to 4. Each layer reads from the multiple paths, computes through sublayers, and writes back to them. Three groups of learnable matrices control this process:

    • Read matrix H_pre: aggregates the n paths into one, serving as the sublayer’s input.
    • Write matrix H_post: distributes the sublayer’s output across the paths.
    • Residual mixing matrix H_res: exchanges information between paths.

    All three matrices require constraints. The weights of H_pre should be non-negative and sum to 1, so that the sublayer input is a weighted average of the paths. The weights of H_post should be non-negative to prevent sign flips or repeated amplification when writing back. H_res is the key to stability and is the main focus of this article. Constraining only one group cannot guarantee overall stability.

    The cost of this extension is clear: the memory footprint and memory-access volume of the residual stream grow linearly with n, and computation and communication overhead rise accordingly. How the “extra capacity” is allocated is decided by these learnable matrices rather than by manually fixed rules.

    Here is a schematic code snippet illustrating the data flow—this is not a real API of any framework:

    1. # Schematic: one update of an n-path residual stream
    2. # streams: shape (n, d); H_pre: (1, n); H_post: (n, 1); H_res: (n, n)
    3. def hyper_connection_block(streams, layer_fn, H_pre, H_post, H_res):
    4. x = H_pre @ streams # Aggregate into a single input, shape (1, d)
    5. y = layer_fn(x) # Output of attention or FFN, shape (1, d)
    6. streams = H_res @ streams + H_post @ y # Mix paths, then write back the sublayer output
    7. return streams

    Initialization also affects early training. H_pre and H_post can be initialized with uniform weights—each path gets 1/n. H_res can be initialized close to the identity matrix. If the initial weight allocation is uneven, some paths will be noticeably stronger or weaker during early training.

    Where Does the Instability Come From?

    A standard residual connection can be viewed as the special case where H_res equals the identity matrix. In that case, mixing between paths introduces no additional amplification or attenuation. The sublayer output F(x_l) still changes signal magnitude, but that part is controlled by the sublayer’s own training. In hyper-connections, however, H_res is a learnable general matrix with weak constraints, and problems emerge.

    After passing through L layers, a signal is effectively multiplied by HL, H{L-1}, down to H_1. If the gain along some direction exceeds 1, it grows exponentially over layers; if it is below 1, it decays toward zero. Both cases break training. Assuming constant per-layer gain—only to illustrate the exponential effect: a per-layer gain of 1.1 yields roughly 1.1^100 ≈ 13780 after 100 layers, while a gain of 0.9 yields 0.9^100 ≈ 0.0000266. Real models have varying per-layer gains, but the deeper the network, the more easily small per-layer deviations accumulate and amplify.

    During training, these problems typically manifest as three symptoms: sudden loss spikes, exploding gradient norms, and activation overflow in some layers.

    Manifold Constraints: Restricting the Mixing Matrix’s Value Range

    The improvement is to stop letting H_res take arbitrary values and instead restrict it to a mathematically well-behaved set. A directly practical choice is the doubly stochastic matrix, which satisfies two conditions: all elements are non-negative, and the sum of every row and every column equals 1. Such matrices have three properties favorable to training.

    1. Closure: the product of two doubly stochastic matrices is still doubly stochastic, so the constraint holds after multiplying across many layers.
    2. Boundedness: the spectral norm of a doubly stochastic matrix does not exceed 1. When H_res is doubly stochastic, the mixing step alone does not amplify the signal’s 2-norm. Whether the full layer update is stable also depends on the normalization of H_pre and H_post.
    3. Identity inclusion: the identity matrix is itself doubly stochastic, so standard residual connections are a special case under this constraint.

    The third point shows that this improvement is a smooth generalization of standard residuals, not a completely new architecture.

    During training, the model actually learns unconstrained parameters and obtains an approximate doubly stochastic matrix via projection. The common approach is the Sinkhorn-Knopp iteration: alternately normalize rows and columns of the matrix. Direct exponentiation can overflow when logits are large, so a more robust approach performs the normalization in log space:

    1. import torch
    2. def sinkhorn_projection(logits, iters=20):
    3. # logits has shape (n, n); normalize rows and columns in log space to avoid exponent overflow
    4. log_m = logits
    5. for _ in range(iters):
    6. log_m = log_m - torch.logsumexp(log_m, dim=1, keepdim=True) # Row normalization
    7. log_m = log_m - torch.logsumexp(log_m, dim=0, keepdim=True) # Column normalization
    8. return torch.exp(log_m) # Approximate doubly stochastic matrix

    The number of iterations determines projection accuracy. More iterations bring the result closer to doubly stochastic, but projection costs accumulate. Since n is usually small, a single projection costs far less than one matrix multiplication over the hidden dimension. However, the projection runs on every training step, so the iteration count must balance accuracy against overhead on a validation set.

    Why This Design Is Intuitively Sound

    Row sums equal to 1 mean each path’s output is a weighted average of all input paths—signals cannot be amplified out of thin air. Column sums equal to 1 mean each path’s input information is fully distributed across outputs without being double-counted. Together, these two properties keep the total amount of information controllable as it flows between layers.

    Compared with simple addition, mixing is no longer a mechanical superposition but a learned redistribution of information. Meanwhile, signal magnitude remains controlled. This is exactly what hyper-connections aim for: retain the flexibility of information exchange while restoring stability.

    Engineering Checklist for Deployment

    When deploying, verify the following items one by one.

    1. Shapes and constraints: confirm the shapes of H_pre, H_post, and H_res, and check that H_pre sums to 1, H_post is non-negative, and H_res is doubly stochastic after projection.
    2. Projection accuracy: monitor the maximum deviation of the projected matrix’s row and column sums from 1. Large deviations usually indicate insufficient iterations or constraints not actually taking effect.
    3. Overhead assessment: measure the memory footprint and memory-access growth caused by the n-path residual stream, and confirm communication overhead is acceptable.
    4. Training monitoring: continuously log loss, gradient norms, and the maximum absolute activation values per layer. When spikes or overflow occur, check H_res’s projection first.
    5. Ablation comparison: under the same data, random seeds, and training steps, compare standard residuals, unconstrained hyper-connections, and the doubly stochastic constrained version. Only if the comparison shows improvements in both stability and performance can the improvement be considered effective.

    Summary

    The instability of hyper-connections mainly stems from the unconstrained learnable H_res, which causes signals to grow or decay exponentially across layers. Constraining H_res with doubly stochastic matrices—closed under multiplication, bounded in spectral norm, and containing the identity—makes standard residuals a special case, controlling signal magnitude while retaining flexibility. In deployment, H_pre and H_post must also be constrained, projection error and training metrics monitored, and gains validated through ablation experiments.