Manuscript Offprint

arXiv:2610.18809

Depth Memory

David González-Martínez, Philipp Nazari, T. Konstantin Rusch, Shiwei Liu

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.

Code

Checkpoints

1 INTRODUCTION

The transformer architecture underpins modern language modeling (Vaswani et al., 2023). Since its introduction, architecture research has mainly seen innovation along two axes: sequence mixing, which includes softmax attention (Vaswani et al., 2023), linear attention (Katharopoulos et al., 2020), and state-space models (Gu et al., 2022), and channel mixing, through works like gated MLPs (Shazeer, 2020) and MoEs (Fedus et al., 2022). The standard mechanism for propagating information across depth, however, has remained largely unchanged since the introduction of ResNet (He et al., 2016): layer outputs are accumulated additively through residual connections. Recent works have established alternatives to this standard mechanism at scale (Kimi Team et al., 2026a; DeepSeek-AI et al., 2026). For example, HyperConnections (HC, Zhu et al. (2025)) and Manifold-Constrained Hyper-Connections (mHC, Xie et al. (2026)) maintain an expanded residual stream, while Attention Residuals (AttnRes, Kimi Team et al. (2026b)) explicitly attend to previous layer outputs (Figure 2b). Analogous to sequence and channel mixing operators (Figure 1), we refer to these methods as depth mixing mechanisms.

Figure

Figure 1: The axes of representation mixing: sequence (tokens), channel (features), and depth (layers).

Figure

(a) LDM (ours)

(b) AttnRes

(c) mHC

Figure 2: (a) LDM carries a separate per-token depth memory alongside the residual stream. Read and Write are simplified for brevity (the inverse covariance stream and the write address generation are omitted). (b) AttnRes reads from a growing key-value memory MlM_l and writes the sublayer output back into it. (c) mHC generates its three mappings from the current expanded state and applies them around one transformer branch.

In this work, we approach depth mixing from a different angle. Viewing it as a problem of storing and retrieving information across layers, we introduce Depth Memory, a framework that interprets the propagation of information across depth as a problem of managing layer representations using a set of streams. At each layer, and independently for each token, a Read operation forms the layer input from these streams, and a Write operation updates the streams using the layer output. This framework encompasses the standard residual stream, AttnRes's growing cache of layer representations, and mHC's expanded residual stream, covering both explicit and implicit forms of depth mixing (Figure 2).

Besides taxonomizing existing residual methods using our depth memory framework, we propose instantiating it as a Linear Depth Memory (LDM). LDM maintains three streams: the standard residual stream, a fixed-size matrix-valued memory stream, and an inverse covariance stream (Figure 2a). Analogous to test-time regression for sequence mixing (Wang et al., 2025), we formulate matrix-valued memory stream updates as the solution to a depth regression problem, which fits a linear map to reconstruct previous layer outputs from their corresponding keys. LDM solves this optimization problem optimally through recursive least squares (RLS, Section 3.2).

Our hardware-aware implementation of LDM addresses efficiency challenges posed by a naive instantiation of the framework. First, we implement an unwinding mechanism that does not require storing each layer's memory stream. Second, we employ a windowed Write algorithm that defers parts of the memory updates. Implemented as efficient CuTe DSL kernels, LDM achieves comparable speed to the baselines (Figure 5).

We evaluate LDM on language modeling benchmarks across 400M Llama-like (Touvron et al., 2023) and 1.5B Qwen-like (Yang et al., 2025a) transformer backbones. LDM achieves lower perplexity than a standard pre-layer-norm (PreLN) transformer, mHC and AttnRes at both scales, along with competitive zero-shot accuracy. These gains hold across standard aspect ratios. We furthermore perform extensive ablations to isolate the contributions of different LDM architectural components.

In summary, our main contributions are:

  1. We introduce depth memory, a framework that describes the propagation of information across depth through a collection of streams and their Read and Write operations.

  2. We instantiate this framework in the form of LDM, a linear depth memory that solves a depth regression problem using recursive least squares to store layer representations in a fixed-size state.

  3. We provide an efficient implementation of LDM that combines unwinding and deferred writing techniques to reduce activation memory overhead and memory traffic of LDM.

  4. We show that LDM consistently achieves the lowest perplexities among tuned PreLN, mHC, and AttnRes baselines at the 400M and 1.5B scales, while maintaining competitive zero-shot accuracy, and that these gains hold across standard model aspect ratios.

References (96)