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.
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:
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.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.
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:
f_t are 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.
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:
g_t = G_t b_t, with a single vector b_t ∈ R^t shared across all d features. Learnable linear combination of previous outputs.g_t = (G_t ⊙ b_t) 1, with b_t ∈ R^{d×t}. Different weights per feature dimension, still static.g_t = (G_t ⊙ (b_t + \bar w_t)) 1, where b_t is static per-feature and \bar w_t = 1 σ(w_t^T G_t) is a scalar (same for all d dimensions) 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.
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.
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:
r*/d (collective rank over ambient dimension) and on task complexity κ = λ_min/λ_max of A − I.r*/d is below a threshold that grows with κ, the generalized residual wins. For more complex tasks (higher κ), the winning range of r* is wider.d: larger models in larger spaces benefit more.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:
d-relative rank) see smaller gains — consistent with the width-scaling experiment.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%).
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.
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.
x + f(x) in the attention/FFN paths with a GRN over the residual stack, initialized to all-ones.k small (1–2) for inference latency; the retrofit gain does not require full depth access.Best for: teams with sunk training cost in a checkpoint, or anyone who wants a cheap quality bump.
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.
k = 2 as the default; only raise k if ablations show a perplexity win worth the latency.Best for: new pretraining runs, research ablations, and any setting where training time dominates cost.
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.
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.
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).
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.
The paper is unusually honest about diminishing returns. Skip or deprioritize DCA when:
r*/d is above the threshold in Theorem 4.3, the plain ResNet is already rich enough.r* widens with task complexity κ; for easy targets the gain is small.k. Full-depth DCA (k = 24) is slower; if you must keep all layers in the stack, re-measure latency before shipping.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:
b, zero w). This is what makes retrofitting safe and training stable.\bar w_t is a scalar per layer broadcast over dimensions; do not make it per-dimension or you change the parameter count and the theory.k is small, store only those vectors; do not materialize the full G_t for deep models.Before adopting DCA in a production training run, gate on:
k and batch size.k ∈ {1, 2, 4, 8}. The paper's ablation (Table 7) is the template.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.