Manuscript Offprint

arXiv:2610.33360

LSTM-Style Looped Transformers with Shared KV Caches

Andreas Kirsch

Abstract

Recurrent transformers reuse weights to perform deep computation with fewer parameters. We study an LSTM-style transformer that also shares one key-value cache across its recurrent core. At width 1024, it uses 40.4% fewer parameters than an untied control at nearly matched forward FLOPs, and reduces persistent cache sets from fifteen to four. Parallel training supplies cache entries from a standard-attention pass, whereas continuation reads entries produced recursively using shared attention. We address this mismatch by aligning the two training passes' cache entries with a consistency loss during the final 10% of a fixed training-token budget. Across three model widths on FineWeb, this removes 81–89% of the continuation-loss penalty relative to full-cache evaluation. The improvement replicates on disjoint documents for two training seeds. Across four widths and 1.05–4.19B training tokens, the loss cost of weight tying is smallest at lower token budgets, suggesting an opportunity to use recurrent computation when data and model storage are limited.

1 Introduction

Applying the same transformer blocks repeatedly separates parameter count from computational depth. Universal Transformers, ALBERT, and recurrent language models use this principle to share parameters across layers or iterations (Dehghani et al., 2019; Lan et al., 2020; Geiping et al., 2025). The corresponding attention caches are usually not shared: at each iteration, a token attends to representations of earlier tokens from that same iteration. A direct decoder therefore stores keys and values for every block application, even when its weights are reused.

Shared attention memories already reduce this storage in both untied and looped models (Wu & Tu, 2024; Sun et al., 2024; Conchello Vendrell et al., 2026; O'Neill & Reid, 2026). We study the loss and computation costs of combining weight tying with one cache for the entire recurrent core. The central question is whether a parallel training objective prepares the model to reuse entries produced recursively during inference.

Our default model places four distinct transformer blocks between one untied prologue block and two epilogue blocks. An LSTM-style update (Hochreiter & Schmidhuber, 1997; Gers et al., 2000) combines each core application with a carried state through input and forget gates, then normalizes the state before its next use. Three iterations give fifteen block applications but only seven sets of block weights. All core blocks read the final block's final-iteration cache for preceding tokens (Figure 1).

We use a common framework derived from modded-nanogpt (Jordan et al., 2024a) 1^{1} to compare untied, standard-cache recurrent, and shared-cache recurrent models across four widths and three token budgets. Each width has a 15-layer untied control that approximately matches the recurrent model's forward computation. Weight tying reduces parameters at this fixed computational depth, with higher loss under the tested recipe. A separate comparison pairs recurrent width 1024 with untied width 768 to approximately match parameter count; the wider recurrent model achieves lower continuation loss using more forward and training computation (Figure 1, Table 1).

Cache sharing introduces a second tradeoff. A two-pass objective can train all core blocks to read a common cache, but its parallel second pass reads caches produced by standard attention. During continuation, newly appended entries are themselves produced using shared attention. We measure the total penalty of

1^{1}https://github.com/KellerJordan/modded-nanogpt

Figure

s=N(prologue output)s = N(\text{prologue output})

NgN_g: learned RMSNorm; NN: gain-free RMSNorm

One core KV cache, shared across all slots and passes

F4F_4's final-pass K/V ⟶\longrightarrow persistent cache ⟶\longrightarrow earlier-token attention in F1,F2,F3,F4F_1, F_2, F_3, F_4

Each block uses its own current-token K/V. Prologue and epilogue caches stay separate.

(a) LSTM-style recurrence with one shared core cache.

Figure

Figure

(b) Continuation loss versus parameter count and forward computation.

Figure 1: Parameter and cache sharing have distinct costs. (a) The four core blocks have distinct weights, reused across iterations; preceding tokens supply one common donor cache. Prologue and epilogue retain their own caches. (b) Widths 512, 768, and 1024 after 4.19B training tokens, evaluated on the same 1,280 document continuations with 2,048 prompt tokens and 512 scored targets. Repaired models add donor consistency during the final training stage. The FLOPs panel estimates one inference forward, not latency or the two-pass training cost (Appendix D). All points use one training seed.

switching cache policies on matched targets and examine the role of cache histories separately. Adapting the KV-consistency idea of Wu & Tu (2024), we encourage the two passes to write similar donor keys and values during the final training stage. The intervention improves shared-cache continuation at widths 512–1024, with a small full-cache loss cost, and its effect replicates on disjoint documents for two width-768 training seeds.

Finally, we compare recurrent update rules and inference depths. Gated carry improves loss at the trained depth in a controlled ablation; a Huginn-style injection baseline also supports additional depth when trained across depths. Variable-depth training and cache consistency can be combined, but the tested state-based stopping rule does not beat fixed depth four. We therefore evaluate parameter efficiency, cache storage, and adaptive computation separately.

Table 1: Continuation loss, model size, forward computation, and persistent KV storage after 4.19B training tokens. Full-cache and shared-cache losses score identical targets under ordinary prompt prefill (Section 3). Repaired models repeat their parents' final training stage with donor consistency, retaining the same token budget. FLOPs use the reference attention lengths in Appendix D; two-pass training costs about twice as much at fixed width and tokens. Sets and KV storage describe each model's serving layout: shared-cache columns use four sets; recurrent full-cache evaluation requires fifteen. BF16 KV storage is calculated from tensor dimensions for equal-length cache sets, excluding scratch space; window-sized allocations are discussed in Section 4.3.2. Lower loss is better.

WidthModelParams (M)Forward FLOPs (M/token)SetsKV (KiB/token)Full-cache loss ↓Shared-cache loss ↓
512Untied70.01178.015153.3679—
Two-pass46.93181.1443.43953.5589
Repaired46.93181.1443.44203.4570
768Untied135.98328.91522.53.2393—
Two-pass85.24336.0463.28273.3347
Repaired85.24336.0463.28393.2938
1024Untied228.49532.915303.1515—
Two-pass136.20545.5483.18673.2518
Repaired136.20545.5483.18783.1953

References (88)