Attention Residuals Across Depth: Principle, Implementation, and Cost

    Residual connections are one of the few Transformer components that have remained essentially unchanged while attention, feed-forward networks, positional encodings, and normalization layers have all evolved. This article examines whether fixed-weight addition in residual connections limits the expressiveness of deep models, and explores an alternative: replacing fixed addition with attention over the outputs of all previous layers. It covers the dilution phenomenon in PreNorm residuals, an analogy between attention over time and attention over depth, a concrete formulation with softmax and sigmoid weighting variants, comparisons with DenseNet, ELMo, Highway Networks, and Hyper-Connections, and a cost estimate showing roughly 17% additional compute from key projections and a depth cache about twice the size of the KV cache. Training and initialization recommendations are included, with clear notes on which claims require experimental validation.

    Introduction: The Overlooked Residual Connection

    Over the past few years, nearly every component of large language models has been reworked. Attention has evolved from multi-head attention into variants with shared KV to reduce inference overhead; feed-forward networks have swapped dense MLPs for mixture-of-experts structures to scale up parameters; positional encodings have moved from absolute to rotary; and normalization layers have been traded off between LayerNorm and RMSNorm.

    The residual connection is the exception. Proposed alongside deep residual networks, it has remained essentially unchanged since. Its form is simple:

    1. h_l = h_{l-1} + f_l(h_{l-1})

    This article addresses one question: does this fixed-weight addition limit the expressiveness of deep models? We first describe the concrete form of residuals in modern models, then introduce an approach that replaces fixed addition with attention, and finally estimate its cost. Most benefit claims discussed here require experimental validation, and this article marks them explicitly.

    1. PreNorm Residuals and the Dilution Phenomenon

    1.1 The Current Mainstream Formulation

    Most modern large language models use a PreNorm structure. Each sublayer first normalizes its input, then adds the sublayer output back to the backbone:

    1. h_l = h_{l-1} + f_l(Norm(h_{l-1}))

    Here f_l denotes the attention or feed-forward sublayer at layer l. Because Norm operates on the backbone, the input to f_l depends on the accumulated results of all preceding layers. Unrolling this recurrence gives:

    1. h_L = h_0 + f_1(Norm(h_0)) + f_2(Norm(h_1)) + ... + f_L(Norm(h_{L-1}))

    Each term depends on the previous state, so the terms are not independent. “Equal-weight accumulation” describes the update rule, not that the terms are unrelated to each other. One reason PreNorm became popular is that gradients can flow directly back through the identity path, making deep training more stable.

    1.2 The Dilution Phenomenon

    Under fixed-weight addition, the magnitude of the backbone grows with depth. To estimate a single layer’s contribution, we can make a simplifying assumption: all layer outputs have similar norms and roughly aligned directions. In that case, h_L is approximately the sum of L vectors pointing in the same direction, and the contribution of layer l is roughly 1/L. If the layer outputs are mutually uncorrelated in direction, the backbone norm grows roughly as √L, and the per-layer share declines more slowly.

    Real models do not satisfy these assumptions. Layer magnitudes and directions vary considerably, so these numbers only indicate a trend and should not be treated as measured results. This article calls this phenomenon “dilution”; it is not a standard term.

    Dilution has two main effects. First, later layers struggle to make their output occupy a noticeable position in the backbone. Second, the model can only rely on downstream normalization layers to adjust magnitudes, and each layer’s influence on the final state cannot be modulated by the model itself.

    2. An Analogy Between Time and Depth

    One key reason Transformers displaced RNNs is that attention allows each position to read historical information on demand. An RNN compresses all history into a fixed-size hidden state, whereas attention preserves the full history for every position and dynamically weights it according to the current query.

    Transferring this view to the depth dimension yields the following comparison:

    Dimension Old Mechanism Alternative
    Time RNN compresses history into a fixed hidden state Attention reads historical tokens on demand
    Depth Residual accumulates previous layer outputs with fixed weights Attention reads historical layer outputs on demand (to be validated)

    This analogy is suggestive, but it is not a strict mathematical isomorphism. Attention over time relies on content matching between tokens. Along depth, the outputs of layer 3 and layer 10 do not necessarily correspond to the same kind of semantic position, so whether “reading historical layers” is actually useful must be determined experimentally.

    3. One Formulation of Attention Residuals

    3.1 Basic Idea

    Store the outputs of all previous layers as a set of “key-value pairs.” The current layer computes its own query, performs a weighted sum over these historical outputs, and uses the result as the sublayer’s input. The backbone is then no longer a fixed sum of all history, but a combination determined by attention weights.

    3.2 Formulation

    The following is one implementable formulation. Notation: v_0 is the embedding output, v_i is the output of sublayer i, and r_l is the aggregated input at layer l.

    1. # Historical outputs: v_0 = embedding output, v_i = f_i(Norm(r_{i-1})), i = 1..l-1
    2. k_i = W_K · Norm(v_i) # key, projected from a historical output
    3. q_l = W_Q · Norm(r_{l-1}) # query, projected from the previous aggregated input
    4. alpha_i = w(q_l · k_i / sqrt(d)) # weight for the i-th historical output, i = 0..l-1
    5. r_l = sum_i alpha_i · v_i # values are the historical outputs themselves (V is identity)
    6. v_l = f_l(Norm(r_l)) # output of sublayer l

    Here w is the weighting function. It can be softmax or sigmoid; Section 3.3 compares the two. Since both queries and keys come from their respective normalized representations, the weights depend on both the current state and the content of historical layers.

    Before the final output, the model must aggregate all historical outputs once more, using the same form as above.

    3.3 Trade-offs Between Two Weighting Functions

    The choice of weighting function determines two fundamental properties of the model, which usually cannot be satisfied simultaneously.

    Choice Property Cost
    softmax (weights sum to 1) The aggregate is a convex combination of historical outputs; by the triangle inequality, ‖r_l‖ ≤ max_i ‖v_i‖, so magnitude is bounded Not equivalent to standard PreNorm; it differs from the standard residual from the start
    sigmoid (unnormalized) When all weights are 1, rl exactly equals the standard PreNorm backbone h{l-1}; controllable behavior early in training Magnitude is unbounded and can still grow as weights increase

    The equivalence of the sigmoid version can be verified directly. When all alpha_i equal 1, r_1 = v_0 = h_0, r_2 = v_0 + v_1 = h_1, and so on — r_l always equals the backbone of the standard recurrence. Therefore, initializing the logit to a large positive value (e.g., 4, giving a sigmoid output of about 0.98) lets training start near the standard residual.

    Neither choice is strictly better. The softmax version suits scenarios where magnitude stability matters most; the sigmoid version suits scenarios where you want to preserve standard residual behavior and gradually learn to deviate from it.

    4. Comparison with Existing Methods

    Information aggregation along depth is not a new problem. Existing methods can be roughly classified by connection pattern and weight properties.

    • DenseNet (Huang et al., CVPR 2017) concatenates features from all previous layers. The total number of connections grows quadratically with depth, approximately L(L+1)/2.
    • ELMo (Peters et al., 2018) applies learnable scalar weights to layer representations, normalized by softmax. The weights are input-independent and fixed after training.
    • Highway Networks (Srivastava et al., 2015) uses input-dependent gating to mix adjacent layers. The gating depends on the input but operates only between adjacent layers.
    • Hyper-Connections (Zhu et al., 2024) expands the residual into multiple parallel backbones connected by learnable mixing matrices. The mixing coefficients are fixed for all inputs after training.

    The distinction of attention residuals is that the weights are content-dependent and can select from any historical layer. The cost is that every position must store and read all historical outputs — exactly what the next section estimates.

    5. Compute and Memory Cost

    The following estimates assume a reference configuration: L = 64 layers, d = 4096, each layer with MHA plus a 4x-wide MLP, with parameters and caches in bf16. Estimates count only multiply-accumulate operations and cache bytes per token, excluding implementation-specific overhead.

    5.1 Compute

    A standard layer costs roughly 12d² multiply-accumulates: the attention Q, K, V, and O projections total 4d², and the MLP’s two matrices total 8d². Across 64 layers, that is about 1.29 × 10^10 multiply-accumulates.

    For depth attention, scoring and weighted summation require Σ l ≈ L²/2 = 2048 dot products per token. Each dot product has dimension d, and both scoring and weighted summation need one pass, totaling about 1.68 × 10^7 multiply-accumulates — roughly 0.13% of the base compute.

    The real overhead comes from projections. The query projection W_Q is needed once per layer, and the key projection W_K once per historical output, each costing about 64 × d² ≈ 1.07 × 10^9. Together that is about 2.15 × 10^9, or roughly 17% of the base compute.

    If the key dimension is reduced to 512, the key projection overhead drops to 1/8 of the original, a little over 1% of base compute. Low-rank projection is the most straightforward cost reduction for this kind of method, but it also limits the expressiveness of the keys — which needs to be confirmed experimentally.

    5.2 Cache

    During training, each token must store L vectors of dimension d to support backpropagation and reads during inference. With the configuration above, this cache is 64 × 4096 × 2 bytes = 512 KiB per token.

    For comparison, the standard attention KV cache under the same configuration — 8 KV heads with head dimension 128 — is 2 × 8 × 128 × 2 = 4 KiB per token per layer, or 256 KiB across 64 layers. The depth cache is about 2x the KV cache.

    This differs from common intuition. During inference, depth attention does not change how tokens interact with each other, but it introduces a new cache alongside the KV cache. When planning the memory budget for long-context inference, this cache must be accounted for.

    6. Training and Initialization

    Training stability is the main risk for this class of methods. The following recommendations are based on the analysis above; this article does not present validated results.

    1. Start near the standard residual. Use the sigmoid version and initialize the logit to a large positive value so that all historical outputs start with weights close to 1.
    2. Zero-initialize the query projection. Early in training, attention weights are dominated by the bias terms, with the content-dependent component introduced gradually during training.
    3. Monitor magnitudes. Track the backbone norm at each layer and check whether it grows faster with depth than under the standard residual.
    4. Monitor layer contributions. Compute each layer’s sublayer output share of the final state to verify whether dilution is actually mitigated.

    To judge whether this approach is worth adopting, compare validation loss under the same compute budget while also reporting the magnitude and contribution metrics above. Training curve shapes alone are not sufficient to draw conclusions.

    7. Summary

    The fixed-weight addition in residual connections causes state magnitudes to grow in deep models and weakens the relative contribution of later layers. Attention residuals replace fixed addition with content-dependent weights, letting each layer selectively read historical outputs.

    This direction has a clear benefit hypothesis and a clear cost: key projections add roughly 17% extra compute, and the depth cache is about 2x the KV cache. Whether to adopt it depends on the specific model scale, context length, and training budget. Running small controlled experiments on your own data is the most direct way to determine whether it fits your use case.