Depth Memory
The Depth Memory framework the mixing of representations over depth as a problem of storing and retrieving information across layers. Linear Depth Memory (LDM) builds on this idea with a queryable, fixed-size memory alongside the residual stream.
Abstract
Residual connections propagate information through a network by additively accumulating layer outputs. Recently proposed alternatives, such as Manifold-Constrained Hyper-Connections (mHC) and Attention Residuals (AttnRes), instead use more expressive depth aggregation mechanisms that improve language modeling performance at scale. In this work, we consider the mixing of representations over depth as a problem of storing and retrieving information across layers. Formalizing this perspective, we introduce Depth Memory (DM), a unified framework that describes the standard pre-layer-norm (PreLN) transformer, mHC, and AttnRes in terms of streams that carry representations through the network. One such stream, for example, could be an explicit memory stream that is queried to enrich the input to every layer, and whose output is subsequently written back into the memory for use by later layers. For AttnRes, this memory stream is a growing cache of explicit layer representations. For mHC, it is an expanded residual stream. Building on this view, we propose Linear Depth Memory (LDM), which formulates information retrieval across depth as a regression problem solved using recursive least squares. The resulting architecture propagates three streams across depth: the standard residual stream, a linear associative memory stream, and an inverse covariance stream. For high-throughput training and inference, we propose a hardware-aware implementation of LDM that reduces peak activation memory and memory traffic. LDM consistently achieves the lowest perplexities among PreLN, mHC and AttnRes baselines at the 400M and 1.5B parameter scales, alongside competitive zero-shot accuracy.
Depth Memory
The transformer architecture underpins modern language modeling. Since its introduction, architecture research has mainly seen innovation along two axes: sequence mixing, which includes softmax attention, linear attention, and state-space models, and channel mixing, through works like gated MLPs and MoEs. The standard mechanism for propagating information across depth, however, has remained largely unchanged since the introduction of ResNet: layer outputs are accumulated additively through residual connections. Recent works have established alternatives to this standard mechanism at scale. For example, Hyper-Connections (HC) and Manifold-Constrained Hyper-Connections (mHC) maintain an expanded residual stream, while Attention Residuals (AttnRes) explicitly attend to previous layer outputs. Analogous to sequence and channel mixing operators, we refer to these methods as depth mixing mechanisms.
Our Depth Memory framework describes depth mixing through a set of streams and their read and write operations. For each token, a read forms the next layer's input, and a write incorporates the layer output into the streams. This framework unifies standard pre-layer-norm (PreLN) transformers, AttnRes, and mHC.
A single residual stream accumulates layer outputs. Each layer reads the current sum and adds its output to it.
Full AttnRes attends to the embedding and all earlier layer outputs, retaining an explicit cache that grows with depth. Block AttnRes instead sums outputs within groups of layers.
An expanded residual stream acts as an implicit memory of fixed size. Learned mappings combine streams for the layer input, distribute its output, and densely mix streams between layers.
Three streams carry the residual representation, a memory matrix, and an inverse key covariance. Recursive least squares updates the memory, whose readout enriches the next layer's input.
Equations are for one token: \(\mathbf v_l\) is the layer output, and the read after layer \(l\) supplies the next layer's input before normalization. LDM gates and the inverse covariance update are omitted here.
Linear Depth Memory
The simplest version of a linear associative memory over depth carries two streams: the standard PreLN residual stream \(\mathbf x_l\) and a matrix-valued memory \(\mathbf M_l\). Each layer writes its output \(\mathbf v_l\) into both streams. It adds the output to the residual stream and stores it in the memory under a key \(\mathbf k_l\):
The next layer then reads \(\mathbf x_l+\mathbf M_l\mathbf q_l\) with a query \(\mathbf q_l\). Queries and keys are computed from the residual stream by small MLPs with \(L^2\)-normalized outputs:
Since \(\mathbf M_l=\sum_{i\le l}\mathbf v_i\mathbf k_i^\top\), this read is unnormalized linear attention over depth. Instead of a growing collection of layer outputs, as in AttnRes, the network keeps a fixed-size summary of them. Keeping the two streams separate matters. Supplying only the memory readout to each layer, or removing the residual addition after it, underperforms PreLN in our ablations.
The outer-product write only approximates what the linear depth memory should hold: the linear map that best reconstructs every layer output so far from its key. Akin to test time regression over time, we call this the depth regression objective:
Along the sequence axis, the need for parallelizability of the solve requires approximate solutions to the test time regression objective. Over depth, however, layers are already evaluated one after another. LDM can therefore maintain the exact solution with recursive least squares (RLS). It solves a weighted and regularized version of the objective, with learnable per-layer forgetting factors \(\lambda_l\), dynamic importance weights \(\omega_l\) that the key's MLP also produces, and a ridge penalty scaled by \(\alpha^{-1}\):
Solving it with RLS adds a third stream, the inverse key covariance \(\mathbf P_l\). With the weighted observations \(\bar{\mathbf k}_l=\sqrt{\omega_l}\mathbf k_l\) and \(\bar{\mathbf v}_l=\sqrt{\omega_l}\mathbf v_l\), each layer computes a gain \(\boldsymbol\kappa_l\) and the prediction error \(\mathbf u_l\) of the current memory:
The memory is corrected by what it failed to predict, and the inverse covariance is updated alongside it:
We initialize \(\mathbf M_{-1}=\mathbf 0\) and \(\mathbf P_{-1}=\alpha\mathbf I\), with \(\alpha=1\) in our experiments. Our main models partition the memory into 16 groups. Each group has its own inverse covariance and forgetting factors and is queried independently. The group readouts are concatenated into the full memory readout.
Results at a glance
We train 400M Llama-like models on 50B FineWeb-Edu tokens and 1.5B Qwen-like models on 100B, with matched backbones and a learning rate tuned for each method. Our main LDM configuration achieves the lowest validation, WikiText-2, and LAMBADA perplexity at both scales. Average zero-shot accuracy ranks first at 1.5B and second at 400M.
Evaluation
| Method | Zero-shot accuracy (%) ↑ | Perplexity ↓ | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| ARC-E | ARC-C | HellaSwag | PIQA | WinoGrande | OpenBookQA | LAMBADA | Average | LAMBADA | WikiText-2 | Val | |
| PreLN | 74.07 | 41.47 | 62.04 | 75.14 | 62.35 | 42.60 | 51.19 | 58.41 | 10.49 | 15.06 | 9.48 |
| AttnRes (Block) | 75.88 | 42.92 | 63.51 | 75.03 | 60.77 | 43.60 | 54.22 | 59.42 | 8.84 | 14.54 | 9.26 |
| mHC | 75.67 | 41.72 | 63.32 | 75.57 | 62.98 | 44.40 | 54.08 | 59.68 | 9.05 | 14.44 | 9.25 |
| LDM (ours) | 76.35 | 42.66 | 63.98 | 75.14 | 62.83 | 42.00 | 55.00 | 59.71 | 8.42 | 14.21 | 9.15 |
Training loss
Throughput
Efficient implementation
A naive implementation of LDM stores the memory of every layer for backpropagation and moves the full state through GPU memory at every read and write. Our CuTe DSL implementation avoids both. State unwinding updates the memory in place and reconstructs earlier states during the backward pass, \(\mathbf M_{l-1}=\mathbf M_l-\mathbf u_l\boldsymbol\kappa_l^\top\). Windowed writes partition the layers into windows of \(E\) consecutive layers. Within a window, reads and writes use the memory from the window's start plus the deferred updates of earlier layers in the window, so the memory is only updated once per window.
In the below interactive element, each layer pairs its write with the next layer's read.
Citation
@misc{gonzalezmartínez2026depthmemory,
title={Depth Memory},
author={David González-Martínez and Philipp Nazari and T. Konstantin Rusch and Shiwei Liu},
year={2026},
eprint={2610.18809},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2610.18809},
} Enjoy Reading This Article?
Here are some more articles you might like to read next: