skip to content
← Scientific Spaces English

A Memoir on Attention Residuals

This article introduces one of our latest works, Attention Residuals(AttnRes); as the name suggests, this uses ideas from Attention to improve Residuals.

Many readers have likely heard of the Pre-Norm vs. Post-Norm debate, but at the end of the day, this is merely infighting within Residuals itself, as are many subsequent normalization variants. A more intriguing change was HC, which set out on the route of expanding the residual stream; perhaps due to instability in its empirical performance, however, it did not create much of a stir. Many may know the rest of the story: late last year, DeepSeek's mHC improved upon HC and validated its effectiveness in larger-scale experiments.

Rather than expanding the residual stream even further, we chose another radical route: directly applying Attention across layers to replace Residuals altogether. Of course, getting the full pipeline to work still required dealing with numerous details and efforts, so here I will simply recount the journey and thoughts behind it.

Schematic of AttnRes

Schematic of AttnRes

Inter-Layer Attention #

As usual, let us begin with Residuals, with which everyone should be thoroughly familiar. Its form is

Here we switch to an alternative notation, which allows us to see deeper insights. Let , then , and setting , it easily follows that , so it can be equivalently written as

That is, from the perspective of , Residuals takes and sums them with equal weights as the input to to obtain , so a natural generalization is to replace this with a weighted sum:

This is the seed of AttnRes. The equation above also imposes two additional constraints on ; let us first discuss why they are necessary:

1. The constraint ensures that the contribution of the same to different layers is always in the same direction, avoiding the inconsistency where one layer wants to increase while another layer wants to decrease , which intuitively is more friendly to model learning;

2. The we use incorporates In-Norm, applying to the input first. Since holds identically for , weighted averages and weighted sums are completely equivalent, so the constraint does not diminish expressiveness.

Hyper-Connections #

Before getting into AttnRes, let us briefly review HC (Hyper-Connections) and show that it can also be understood as inter-layer attention, thereby demonstrating that inter-layer attention is indeed a more fundamental route. HC changes residuals to

where , and the classic choice is . Simply put, the state variable is expanded to times; before being fed into , an matrix is used to change it back to times; after being output, is used to change it back to times, and finally added to -adjusted . If we do not restrict the form of , then architectures like Post-Norm and Highway are all special cases of HC.

Similarly, denoting , then , and adopting the convention that , it can also be expanded as , where is defined as . Further adopting the convention that , we can write

Note that each is a matrix, which is equivalent to a scalar, so it is also in the inter-layer attention form of Eq. . Readers familiar with linear attention should quickly understand this result: HC is actually equivalent to a "90-degree rotated" DeltaNet. In practice, the three matrices are computed by simple linear layers activated by , which causes the cumulative product to risk exploding or collapsing, and cannot guarantee that is non-negative.

Later, mHC made improvements: it first changed all three to Sigmoid activations, ensuring that is non-negative, and then alternately normalized so that it satisfies double stochasticity; the closure of doubly stochastic matrices under multiplication guarantees the stability of , and ultimately experiments also confirmed the effectiveness of these modifications. However, some recent experiments, such as "Your DeepSeek mHC May Not Need the "m"", show that setting directly to the identity matrix is already good enough.

Many Hands Make Light Work #

Let us return to AttnRes. Having realized the feasibility of AttnRes, the next question was: as for , what form should it take? A very natural thought was to follow the standard Scaled Dot-Product Attention, but at the time, I wanted to quickly try something out first, so I chose a simpler form:

where is a trainable vector parameter; that is, directly using a data-independent static vector as Q, while both K and V are to perform Softmax Attention. This was the first version of AttnRes. To our pleasant surprise, with just such a simple design, its improvement over Residuals was already very significant!

When I shared the preliminary experimental results of AttnRes within the group, @Yu Zhang and @Guangyu showed great interest and joined in to run validations on larger-scale models, finding that the results were all very delightful. During this period, we also tried some more complex designs and found that most of them were inferior to this simple version; only adding an extra operation to K yielded relatively consistent gains, which constituted the final form of AttnRes:

However, AttnRes is, after all, a dense inter-layer connection scheme. Would training and inference be feasible on K2 or even larger scales? Excitingly, @Brother V, through exquisite analysis, first confirmed its feasibility in inference. The crowning touch was precisely the static Q design that we initially chose just for convenience! This allows us, after computing , to compute in advance for the attention , giving Infra ample room to maneuver.

Unfortunately, however, training colleagues such as @Brother Wang, after careful analysis, judged that in our current training environment, AttnRes was still not viable enough (put bluntly, we were just poor), and that we needed a scheme to further reduce communication and memory. Thus came the Block version below; correspondingly, we refer to the previous version as the Full version.

Block Version #

Moving from Full AttnRes to Block AttnRes is akin to the previous process of linearizing quadratic attention: various existing ideas from efficient attention can be plugged in and tested. For instance, the first one we tried was SWA (Sliding Window Attention), but we found the actual results were terrible, even worse than Residuals.

Upon reflection, I think it can be understood this way: Residuals itself is already a very strong baseline, corresponding to an equal-weight sum of all state vectors. If any new design hopes to surpass it, it must at least be able to cover it in form. Full AttnRes clearly satisfies this condition, but with SWA added, it no longer does—it discards a portion of the states and cannot cover the special case of 'equal-weight sum of all state vectors'.

From this, we realized that for AttnRes, 'compression' might be more effective than 'sparsity', and the compression does not need to be overly elaborate—a simple weighted sum may well suffice. After some brainstorming and polishing, @Yu Zhang and @Guangyu proposed the Block AttnRes design presented in the paper. It combines the ideas of block-by-block processing and sum compression, achieving performance close to that of the Full version.

The idea behind Block AttnRes is roughly as follows: First, the embedding layer forms a block on its own. This is because observing the attention matrix of the full version (which is also the advantage of the attention concept—attention patterns can be visualized at any time) revealed that the model tends to allocate a substantial amount of attention to the embedding layer, so it is necessary to separate the embedding layer out; each group of remaining layers forms a block, within which compression is performed via summation, and inter-block attention is computed taking the summation result as the unit.

Experiments show that simply fixing the partition to around 8 blocks is enough to obtain most of the gains of AttnRes. After evaluation, the colleagues working on training and inference unanimously agreed that the overhead of Block AttnRes is very small and well worth it compared to its performance gains (for detailed analyses, see @Brother Wang's and @Brother V's posts; to put numbers on it, roughly an overhead within 5% in exchange for a 25% gain). Everyone then went all out to push it into the mainline, which was another fulfilling and pleasant experience that I will not elaborate on here.

Matrix Perspective #

It is worth mentioning that we can also unify Residuals, HC/mHC, Full AttnRes, and Block AttnRes through the attention matrix, which offers quite an interesting perspective. An example is shown below, where , the Block AttnRes version corresponds to , and , a notation that we also used in Making Model Training More Scientific, Part 4: A New Identity, a New Learning Rate.

Residuals #

HC/mHC #

Full AttnRes #

Block AttnRes #

Related Work #

Ever since we planned to work on AttnRes, my teammates and I had been immersed in the process of refining, verifying, and accelerating it. Some readers may know that my research style is to first do my best to derive and solve problems on my own, and only look for related literature when encountering difficulties or after completely solving them. As it happened, I met a group of like-minded teammates, and as it happened, this exploration of AttnRes went quite smoothly overall, so it was not until all tests had basically passed and we began preparing the technical report that we started surveying the related literature.

However, precisely because of this, as the saying goes, "you never know until you look, and once you look you are stunned"—it turned out that there was already a tremendous amount of related work on dense connections and depth attention. In addition to the classic DenseNet, other works we found during our survey include DenseFormer, ANCRe, MUDDFormer, MRLA, Dreamer, and others; even before BERT, ELMo had partially adopted similar designs. We have included all of these in our references.

After the technical report was released, we received comments from readers one after another, pointing out several related works that had not yet been included, such as SKNets, LIMe, and DCA, among others. For this, we express both our apologies and our gratitude, and we promise to do our best to add them in subsequent revisions. However, whether you are a reader or an author yourself, please remain rational about this: literature reviews are not an easy task, and some omissions are inevitable. We pay our highest respects to all related work.

At the same time, we also call on everyone to pay more attention to the amount of work in AttnRes beyond the concept of "Depth Attention". We completely agree that today in 2026, "Depth Attention" or "Layer Attention" is by no means a novel idea. However, how to apply it to sufficiently large models as a strong enough replacement for Residuals, while simultaneously satisfying efficiency requirements in both training and inference, is by no means an easy task. To the best of our knowledge, AttnRes is the first work to achieve this.

Summary #

This post introduced our latest result in model architecture, Attention Residuals (AttnRes). It replaces vanilla residuals with inter-layer attention and, through meticulous design, satisfies the efficiency requirements of both training and inference, ultimately succeeding in scaling it to sufficiently large models.