Manuscript Offprint

arXiv:2611.06835

LooM: Loop-Invariant Memory for Causal Encoder-Decoder Language Models

Lele Yang, Muxi Diao, Zhonghao Yan, Jiankang Chen, Bin Wen, Tingting Gao, Wentao Zhang, Kongming Liang, Zhanyu Ma, Weiran Xu

Abstract

Looped Transformers increase effective depth by re-executing shared layers, but three limitations hinder their adoption: memory grows with the loop count, compute can only be adjusted in whole-block steps, and the loop count is hard to change after training. We propose LooM (Loop-invariant Memory), which addresses each in turn. In a causal encoder-decoder (CED), LooM loops only the decoder layers after the first, which read a global memory written once per token, and each of them publishes the key-value (KV) entry for a token only on its first visit, so the cache does not grow with the loop count. These layers loop independently, providing every budget from 3 to 21 layer executions per token, and one model trained on randomly sampled budgets covers all of them without a router. With enough loops, LooM outperforms a single-pass baseline trained on the same data on language modeling, zero-shot accuracy and long-context perplexity, while using the same cache size. Our analysis further shows that the training budget distribution decides what extra depth buys. These results suggest that a CED is a natural place to loop: memory is written once, and depth becomes a budget chosen at deployment.

1 Introduction

Looped Transformers apply the same stack of layers repeatedly to each token's hidden state, increasing effective depth without adding parameters (Dehghani et al., 2019; Geiping et al., 2025; Zhu et al., 2025b; He et al., 2026; Chen et al., 2026a). This added depth improves performance: looped models rival much larger standard models (Zhu et al., 2025b) and scale test-time computation in latent space (Geiping et al., 2025). However, three limitations hinder their wider adoption. (1) Memory grows with the loop count. In a looped Transformer, the same layers both build the context

and refine each token's state, so every loop writes new key-value (KV) entries. With a standard KV cache, as in Ouro, memory therefore grows linearly with the number of loops (Zhu et al., 2025b; Conchello Vendrell et al., 2026). (2) Compute can only be adjusted coarsely. Looped language models typically repeat a whole block of layers (Geiping et al., 2025; Zhu et al., 2025b; Bae et al., 2025b; Liang et al., 2026), so budgets come in multiples of that block and none lies below one full pass. (3) The loop count is hard to change after training. A model trained at one loop count degrades when run with fewer loops (Section 5.1). Varying compute therefore usually requires a learned router or halting policy (Graves, 2016; Banino et al., 2021; Raposo et al., 2024; Bae et al., 2025b; Zhu et al., 2025b) or loop conditioning (Jeddi et al., 2026).

To address these limitations, we propose LooM (Loop-invariant Memory), with one design for each. (1) In a causal encoder-decoder (CED) (DeepSeek-AI, 2026), the encoder and the first decoder layer write the global memory once per token, and LooM loops only the remaining decoder layers, which we call reader layers. Each reader layer writes (publishes) a token's local KV entry only on its first visit, so the cache does not grow with the loop count (Figure 1). (2) Each reader layer loops independently, zero to four times, so one model offers every budget from 3 to 21 decoder calls (layer executions) per token; publish-once keeps the cache unchanged even when a layer is skipped. (3) During training, each update samples a budget and then a random path, that is, how many times each reader layer runs, with that many calls, so the model learns to run at every budget. At inference we fix one path per budget, chosen on validation data, and need no router.

Trained on 5B tokens, the resulting 204M-parameter model beats a single-pass model trained on the same data from 11 calls on. At 21 calls its test cross-entropy is 0.020 nats lower and its zero-

*Equal contribution. †Project lead. ‡Corresponding author.

(a) Causal encoder–decoder, with one square per decoder call

Figure

(b) Publish once

Figure 1: Loop-invariant memory in LooM. (a) Decoder layer 1 (D1) writes global memory once per token, before any repetition; each of D2–D6 then runs dℓ∈{0,…,4}d_\ell \in \{0, \ldots, 4\} times (D3 and D5 at least once). Squares are decoder calls on Random-Depth's locked paths at three budgets. Every visit re-reads global memory (left), but only a layer's first visit publishes the token's local KV entry (right); publishing arrows are drawn for the 21-call path only. (b) D2, standing for any of D2–D6: a later token reads one local entry per earlier token however often the layer ran, so the cache (after a 128-token prompt) is the same on every path. CSA2 modes are defined in Section 3.1.

shot average 0.79 points higher at the same cache size. (Table 2).

Our contributions are:

  • Loop-invariant memory. We loop only the reader layers of a CED and publish each local KV entry once, so the cache does not grow with the loop count, even when layers loop independently or are skipped (Section 3.2).

  • Layer-level loops in one router-free model. Each reader layer loops independently, giving budgets from 3 to 21 calls in steps of one layer execution; with Random-Depth training, one checkpoint serves them all (Section 5.1).

  • An analysis of how to spend the budget. The training budget distribution decides what extra depth buys (Section 5.2), repeated reads re-retrieve memory (Section 5.4), and static paths nearly match a learned router (Section 5.5).

References (41)