DeepCrossAttention: Supercharging Transformer Residual Connections — Analysis and Practical Adoption Paths
Source: Mike Heddes, Adel Javanmard, Kyriakos Axiotis, Gang Fu, MohammadHossein Bateni, Vahab Mirrokni — DeepCrossAttention: Supercharging Transformer Residual Connections, Proceedings of ICML 2025 (PMLR 267), arXiv:2502.06785v2. Authors are affiliated with Google Research and USC/UC Irvine.
1. Executive summary
Standard transformers add residual connections as a plain sum: every previous layer output is treated as equally important. That sum is full-rank on paper, but in practice it dilutes the few layers that actually carry the information a token needs. Heddes et al. show that even a residual network that is full-rank in principle cannot recover a simple identity transform through low-rank layers — the sum smears signal across depth.
DeepCrossAttention (DCA) fixes this with two ideas:
- Learnable, input-dependent residual weights (Generalized Residual Networks, GRN). Instead of
x + f(x), each layer forms a weighted combination of all previous layer outputs, where the weights can depend on the input token and on the feature dimension. - Depth-wise cross-attention. In a transformer block, three independent GRN instances produce the queries, keys, and values of self-attention, so attention inputs are composed from arbitrary depths rather than only the previous block.
Cost: a negligible parameter increase (a 6-layer, ~50M-parameter model goes from 49.65M to 49.73M parameters) and a modest throughput hit that is largely recovered by keeping only the first and last-k layer outputs in the residual stack. Payoff: lower perplexity for the same parameter budget, reaching a target perplexity roughly 3× faster, and markedly fewer training loss spikes.
The paper's own framing is that DCA turns a purely sequential stack of residual blocks into a dynamically rearranged mix of sequential and parallel paths, chosen per token, without changing the attention kernel itself.
2. The problem: information dilution in residual sums
A residual block is x_{t+1} = f_t(x_t) + x_t. Unrolled, layer t receives the sum of every earlier output:
g_T(x) = x + f_1(x) + ... + f_{T-1}(x_{T-1})
That sum has two failure modes the paper targets:
- Equal weighting. No layer is allowed to say "I need layer 3, not layer 7." Everything is averaged into one vector.
- Bottleneck persistence. If individual
f_tare low-rank, the sum is full-rank in algebra but the information in each summand is still trapped in a low-dimensional subspace. The identity experiment in Figure 1 of the paper demonstrates this: a 10-layer network of rank-3 layers with standard residuals cannot reconstruct a 100-dim input even after 10^5 examples, while the same network with learnable residual weights reaches near-zero loss with 100× fewer examples.
The hypothesis: residual connections mitigate bottlenecks but do not resolve them, because the sum cannot selectively route around them. Learnable residual weights can.
3. Method
3.1 Generalized Residual Networks (GRN)
Let G_t ∈ R^{d×t} be the stack of previous layer outputs. Standard ResNet uses g_t = G_t 1 (all-ones combination). GRN generalizes this in three steps:
- GRN-v1 (DenseFormer-style).
g_t = G_t b_t, with a single vectorb_t ∈ R^tshared across alldfeatures. Learnable linear combination of previous outputs. - GRN-v2.
g_t = (G_t ⊙ b_t) 1, withb_t ∈ R^{d×t}. Different weights per feature dimension, still static. - GRN-v3.
g_t = (G_t ⊙ (b_t + \bar w_t)) 1, whereb_tis static per-feature and\bar w_t = 1 σ(w_t^T G_t)is a scalar (same for allddimensions) computed from the input. This gives both dimension-dependent and input-dependent weighting at a small parameter cost. The paper uses ReLU forσ.
The ablation in the paper (Table 7) shows where the gains come from on a 6-layer LM1B model:
| Variant | Params | Perplexity |
|---|---|---|
| Transformer (baseline) | 49.65M | 18.98 |
| GRN-v1 | 49.65M | 18.80 |
| GRN-v2 | 49.66M | 18.43 |
| GRN-v3 | 49.68M | 18.41 |
| DCA (3× GRN-v3 per block) | 49.73M | 18.06 |
GRN-v1 alone delivers most of the improvement; GRN-v2/v3 add the rest; DCA's three independent instances add the final step by letting attention's Q, K, and V each compose depth differently.
Memory reduction. Because G_t grows with depth, the paper proposes keeping only the input, the sum of intermediate outputs, and the last-k layer outputs explicitly (e.g. k = 2 keeps at most four vectors). Intermediate layers fall back to ordinary residual addition. This is what makes DCA practical for deep models.
3.2 DeepCrossAttention
In each transformer decoder block, DCA inserts three GRN-v3 instances that share the same residual stack but independently produce Q, K, and V for the attention module. The attention computation itself is unchanged; only its inputs are dynamically composed. Skip connections still ensure the block input is available to both attention and the feed-forward module.
graph TD
S["Residual stack G_t (input + last-k layers)"]
S --> GQ["GRN-v3 (queries)"]
S --> GK["GRN-v3 (keys)"]
S --> GV["GRN-v3 (values)"]
GQ --> Q["Q"]
GK --> K["K"]
GV --> V["V"]
Q --> A["Self-attention (unchanged)"]
K --> A
V --> A
A --> FF["Feed-forward"]
FF --> Out["Block output"]
Because the GRNs are identity-equivalent at initialization (weights start as all-ones / zeros), adding DCA to a pretrained model does not change its function. This is the property that makes retrofitting safe.
4. Theory: when does it help?
The paper analyzes a stylized low-rank linear model y = A x + ε with T layers of rank r_t, collective rank r* = Σ r_t < d. It characterizes the functions expressible by Baseline, ResNet, GRN-v1/v2/v3 and derives excess-risk bounds.
The key result (Theorem 4.3) gives sufficient conditions for GRN-v1/v2/v3 to achieve a better excess-risk / model-size trade-off than ResNet. In readable form:
- The benefit depends on the ratio
r*/d(collective rank over ambient dimension) and on task complexityκ = λ_min/λ_maxofA − I. - If
r*/dis below a threshold that grows withκ, the generalized residual wins. For more complex tasks (higherκ), the winning range ofr*is wider. - The gain grows with input dimension
d: larger models in larger spaces benefit more. - The gain shrinks as
r*grows: a ResNet that is already rich enough is hard to beat.
A second result (Proposition 4.4) shows GRNs can match ResNet's test error with a strictly smaller collective rank, i.e. fewer parameters for the same quality.
The nonlinear extension (Section 4.4) replaces matrix rank with bottleneck rank (Jacot, 2023), so the same intuition carries to MLP and transformer blocks: residual sums dilute information whenever the network's effective rank is small relative to dimension.
Practical reading of the theory:
- Small/medium-width models and high-dimensional embeddings see the largest gains.
- Very wide models (high
d-relative rank) see smaller gains — consistent with the width-scaling experiment. - Deeper models do not lose the gain: depth scaling keeps the improvement, unlike width scaling.
5. Empirical results
All language-modeling experiments use embedding dim 512, MLP dim 4×, sequence length 128, batch 2048, 500k steps (131B tokens) on LM1B/C4 unless noted.
Depth scaling (LM1B, Figure 6). DCA has lower perplexity for a given parameter budget across 6–42 layers. A 30-layer DCA beats a 42-layer transformer — DCA is more parameter-efficient than adding layers.
First/last-k (24-layer, LM1B, Table 1).
| Method | Speed (batches/s) | Time to transformer PPL | Final PPL |
|---|---|---|---|
| Transformer | 8.14 | 1.00 | 15.14 |
| 1-DCA | 5.62 | 0.33 | 14.48 |
| 2-DCA | 5.39 | 0.33 | 14.41 |
| 4-DCA | 5.01 | 0.37 | 14.50 |
| 8-DCA | 4.35 | 0.47 | 14.49 |
| 16-DCA | 3.86 | 0.40 | 14.35 |
| 24-DCA | 3.72 | 0.39 | 14.35 |
Small k (1–2) is the sweet spot: DCA reaches the transformer's final perplexity in about one third of the training time, and k = 2 has 48% lower inference latency than k = 24.
Training-time trade-off (Figure 7). 2-DCA reaches better perplexity than the transformer for the same wall-clock training time across 24/36/42-layer models.
Width scaling (12-layer, LM1B, Table 2). Benefit shrinks as embedding dim grows (delta −2.82 at width 64 down to −0.39 at width 1024), matching the theory.
Model scaling (C4, Table 3). Consistent gains up to 449M parameters; absolute delta shrinks for large models but stays negative.
Retrofitting (Table 4). Adding DCA to a 500k-step pretrained 6-layer transformer and continuing training yields −0.19 perplexity after 60k steps, versus −0.02 for continuing the plain transformer. Because DCA is function-preserving at init, this is a zero-risk way to upgrade an existing checkpoint.
Training stability. DCA shows no significant loss spikes where the transformer shows clear spikes, including on large models. This matters for expensive pretraining runs.
Comparison with related work (Tables 5–6). On LM1B (6-layer) and C4 (13-layer, dim 1111), DCA beats LAuReL, DenseFormer, and dynamic Hyper-Connections; on LM1B the gap over the prior best (Hyper-Connections) is 0.59 perplexity points.
Vision (Table 8). ViT-S/16 on ImageNet: loss 0.5698 → 0.5284, accuracy 76.4% → 77.1% (+0.7%).
6. Practical paths to make use of DCA
The paper is not a drop-in library release; it is an architecture recipe. Below are the realistic adoption paths, ordered from lowest to highest commitment.
Path A — Retrofit an existing pretrained transformer (lowest risk)
What. Add DCA (or even just GRN-v1) on top of a finished checkpoint and continue training for a modest number of steps.
Why it works. GRN/DCA is identity-equivalent at initialization: weights start so that the new model computes exactly the old function. No warm-start shock, no catastrophic forgetting of the pretrained representation.
Expected gain. Table 4: −0.19 perplexity over 60k extra steps on LM1B (vs −0.02 without DCA). Small but essentially free.
How.
- Replace each residual addition
x + f(x)in the attention/FFN paths with a GRN over the residual stack, initialized to all-ones. - Start with GRN-v1 only (biggest single gain, fewest moving parts) if you want minimal risk; upgrade to GRN-v3 / full DCA in a second pass.
- Keep
ksmall (1–2) for inference latency; the retrofit gain does not require full depth access. - Continue training with the original optimizer/schedule for 20k–60k steps and measure perplexity on a held-out set; gate the change on a statistically significant improvement.
Best for: teams with sunk training cost in a checkpoint, or anyone who wants a cheap quality bump.
Path B — Train new models from scratch with k-DCA (highest leverage)
What. Build new transformers with DCA from the start, using k = 1 or 2.
Why. 2-DCA reaches the plain transformer's final perplexity in ~0.33 of the time (Table 1) and has lower inference latency than full-depth DCA. That is the single most actionable number in the paper for practitioners.
How.
- Implement GRN-v3 and three instances per block (Q/K/V).
- Maintain a residual stack containing the input, the sum of intermediate block outputs, and the last-2 block outputs; apply ordinary residual addition in between.
- Train with the paper's recipe (AdamW, lr ~0.0016, 1000 warmup, inverse-sqrt schedule) or your own; expect fewer loss spikes, so you can push learning rates slightly harder — validate empirically.
- Use
k = 2as the default; only raisekif ablations show a perplexity win worth the latency.
Best for: new pretraining runs, research ablations, and any setting where training time dominates cost.
Path C — Trade depth for DCA at fixed parameter budget
What. When you have a fixed parameter budget, prefer a shallower DCA over a deeper plain transformer.
Evidence. A 30-layer DCA beats a 42-layer transformer on LM1B (Figure 6). Replacing ~25–30% of the layers with DCA's residual machinery buys quality without growing parameters.
How. Hold params constant, sweep (layers, DCA on/off) on your data, and pick the point on the Pareto frontier. Report both perplexity and wall-clock training time, not just params.
Best for: edge/on-prem models where parameter count is the binding constraint.
Path D — Vision transformers
What. Apply DCA to ViT-style models.
Evidence. ViT-S/16 on ImageNet: +0.7 accuracy (76.4 → 77.1) with lower loss.
How. Same recipe as Path B, applied to the ViT encoder blocks. Evaluate on your actual downstream tasks (detection/segmentation, not just ImageNet top-1) before committing, since the paper only reports classification.
Best for: vision teams already investing in transformer backbones.
Path E — Generalized residuals in non-transformer ResNets
What. Even outside transformers, replace x + f(x) with GRN-v1 (or v2/v3) in MLP/CNN residual stacks.
Evidence. The ablation shows GRN-v1 alone gives the largest single perplexity drop (18.98 → 18.80) at zero parameter increase, and the theory's bottleneck-rank argument applies to any residual network.
How. Start with GRN-v1 (scalar weights per layer, tiny parameter cost T(T−1)/2), measure, then consider v2/v3. This is the cheapest experiment in the paper to reproduce.
Best for: teams with custom residual architectures (diffusion backbones, audio models, GNNs with residual skips).
Path F — Stability-critical large runs
What. Use DCA specifically to reduce loss spikes during large-model pretraining.
Evidence. Figures 7–8: DCA shows no significant spikes where the transformer does, including on large models.
How. Add DCA to the architecture before the run; monitor spike rate and gradient norms as primary metrics alongside perplexity. Combine with existing spike-mitigation (z-loss, gradient clipping) rather than replacing them.
Best for: anyone who has lost a multi-week run to a spike.
7. When not to bother
The paper is unusually honest about diminishing returns. Skip or deprioritize DCA when:
- The model is already very wide. The benefit shrinks from −2.82 perplexity at width 64 to −0.39 at width 1024 (Table 2). At frontier scales the absolute gain may not justify the engineering.
- The collective rank is already high relative to dimension. If
r*/dis above the threshold in Theorem 4.3, the plain ResNet is already rich enough. - The task is simple/low-complexity. The winning range of
r*widens with task complexityκ; for easy targets the gain is small. - Inference latency is the binding constraint and you cannot use small
k. Full-depth DCA (k = 24) is slower; if you must keep all layers in the stack, re-measure latency before shipping. - You cannot afford any retraining. DCA is not a post-hoc weight transform; retrofitting needs at least tens of thousands of steps to realize the gain (Table 4).
8. Implementation sketch
A minimal GRN-v3 over a residual stack (PyTorch-style pseudocode):
import torch
import torch.nn as nn
class GRNv3(nn.Module):
def __init__(self, d, max_layers):
super().__init__()
# static per-feature weights: (d, max_layers)
self.b = nn.Parameter(torch.ones(d, max_layers))
# input-dependent scalar weights: (max_layers, d) -> scalar per layer
self.w = nn.Parameter(torch.zeros(max_layers, d)) # w_t in paper
self.act = nn.ReLU()
def forward(self, G): # G: (batch, d, t) stack of layer outputs
b, t = G.shape[0], G.shape[-1]
# static part
weights = self.b[:, :t] # (d, t)
# input-dependent part: scalar per layer, broadcast over d
# \bar w_t = 1 * sigma(w_t^T G_t) (ReLU), same for all d dims
inp = G.mean(dim=1) # (batch, t) crude proxy; use full G in practice
wbar = self.act(inp @ self.w[:t].T) # (batch, t)
wbar = wbar.unsqueeze(1) # (batch, 1, t)
weights = weights.unsqueeze(0) + wbar # (batch, d, t)
out = (G * weights).sum(dim=-1) # (batch, d)
return out
DCA block (attention inputs only):
class DCABlock(nn.Module):
def __init__(self, d, n_heads, max_layers):
super().__init__()
self.grn_q = GRNv3(d, max_layers)
self.grn_k = GRNv3(d, max_layers)
self.grn_v = GRNv3(d, max_layers)
self.attn = nn.MultiheadAttention(d, n_heads, batch_first=True)
self.ffn = ... # standard FFN
self.norm1 = nn.LayerNorm(d)
self.norm2 = nn.LayerNorm(d)
def forward(self, x, stack):
# stack: (batch, seq, d, t) residual outputs
q = self.grn_q(stack) # (batch, seq, d)
k = self.grn_k(stack)
v = self.grn_v(stack)
a, _ = self.attn(q, k, v)
x = self.norm1(x + a)
x = self.norm2(x + self.ffn(x))
return x
Residual-stack bookkeeping (first/last-k):
def update_stack(stack, new_output, k=2):
# stack holds: input, sum_of_intermediates, last-k outputs
# on intermediate layers, only the running sum is updated
if is_intermediate:
stack.sum_intermediates = stack.sum_intermediates + new_output
else:
stack.last_outputs.append(new_output)
if len(stack.last_outputs) > k:
stack.last_outputs.pop(0)
return stack
Notes for a faithful implementation:
- Keep the GRN weights' initialization so the model is identity-equivalent at step 0 (all-ones
b, zerow). This is what makes retrofitting safe and training stable. - The paper's
\bar w_tis a scalar per layer broadcast over dimensions; do not make it per-dimension or you change the parameter count and the theory. - When
kis small, store only those vectors; do not materialize the fullG_tfor deep models. - Measure batches/s and inference latency alongside perplexity; the trade-off is the whole point.
9. Evaluation and rollout checklist
Before adopting DCA in a production training run, gate on:
- Perplexity / task metric on a held-out set, vs. a matched plain-transformer baseline trained for the same wall-clock time (not just steps).
- Time to target metric. Does DCA reach the baseline's final number in ~⅓ of the time? If not, your setup differs from the paper's (width, data, schedule) — investigate before scaling.
- Loss-spike rate during training (count of steps with >N× median loss). DCA should reduce this.
- Inference latency (p50/p99) with your chosen
kand batch size. - Parameter count (should rise by less than 0.2% for typical models).
- Ablation matrix: GRN-v1 only → GRN-v3 → full DCA (3 instances); and
k ∈ {1, 2, 4, 8}. The paper's ablation (Table 7) is the template. - Comparison against the real competitors you would otherwise use: DenseFormer, LAuReL, dynamic Hyper-Connections. DCA won on LM1B/C4, but your data may differ.
- Downstream tasks for vision (detection, segmentation), not only ImageNet top-1.
10. Limitations and open questions
- Scope of evidence. Experiments cover LM1B, C4, and ImageNet classification. There is no evidence yet for long-context models, multimodal LLMs, RLHF/post-training, or non-English data. Extrapolate cautiously.
- Width dependence. The gain shrinks with width; at frontier model scales the absolute improvement may be modest. The paper argues training-time and stability gains still justify it.
- Theory is linear. The guarantees are for low-rank linear models; the nonlinear extension uses bottleneck rank, which is harder to compute for real networks. Treat the theory as guidance for where to expect gains, not as a proof for transformers.
- No official implementation is referenced in the paper. Reproduction requires implementing the recipe above; budget engineering time for the residual-stack bookkeeping, which is the fiddly part.
- Memory for the residual stack. Even with first/last-k, the stack and three GRNs add activation memory; profile before assuming it is free.
- Open question: whether combining DCA with other residual innovations (e.g. Hyper-Connections' mixing) compounds or cancels. The paper compares them but does not compose them.
11. Conclusion
DCA is a small, well-motivated change to the residual path that the paper shows to be: (a) theoretically justified for the regime most real models live in (moderate r*/d, non-trivial task complexity), (b) empirically better on perplexity, training time, and stability, and (c) cheap to retrofit because it is function-preserving at initialization.
If you take only one thing from it: start with GRN-v1 on your next residual model — it is the largest single gain for the least engineering — and, for new transformer training runs, default to 2-DCA and measure time-to-target-perplexity rather than final perplexity alone. That measurement is where the paper's headline 3× result lives, and it is the number most likely to survive contact with your own data.
References
- Heddes, M., Javanmard, A., Axiotis, K., Fu, G., Bateni, M., Mirrokni, V. DeepCrossAttention: Supercharging Transformer Residual Connections. ICML 2025, PMLR 267. arXiv:2502.06785v2.
- He, K., Zhang, X., Ren, S., Sun, J. Deep Residual Learning for Image Recognition. CVPR 2016.
- Huang, G., Liu, Z., van der Maaten, L., Weinberger, K. Q. Densely Connected Convolutional Networks. CVPR 2017.
- Pagliardini, M., Mohtashami, A., Fleuret, F., Jaggi, M. DenseFormer: Enhancing Information Flow in Transformers via Depth Weighted Averaging. arXiv:2402.02622.
- Menghani, G., Kumar, R., Kumar, S. LAuReL: Learned Augmented Residual Layer. 2024.
- Zhu, D. et al. Hyper-Connections. arXiv:2409.19606.
- Jacot, A. Implicit Bias of Large Depth Networks: A Notion of Rank for Nonlinear Functions. ICLR 2023.
- Srivastava, R. K., Greff, K., Schmidhuber, J. Training Very Deep Networks. NeurIPS 2015.
- Vaswani, A. et al. Attention Is All You Need. NeurIPS 2017.
- Dosovitskiy, A. et al. An Image Is Worth 16×16 Words. ICLR 2021.