Manuscript Offprint

arXiv:2610.31421

How Depth Growth and Looping Shape In-Context Learning in Language Models

Ferdinand Kapl, Kaitlin Maile, Stefan Bauer, Johannes von Oswald

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Looped and depth-grown language models reuse computations across depth and have attracted interest for their reasoning capabilities. Building on prior suggestive evidence of improved in-context-learning (ICL), we investigate how such reuse favors ICL, including how it shapes the acquisition, retention, and mechanisms of this ability. Our analysis spans pretrained language models up to 3B parameters and controlled tasks. The experiments provide evidence for a shared inductive bias toward learning from context: grown and looped models rely more on information in context and, compared with a full-depth dense reference, acquire ICL earlier in controlled tasks and retain it more strongly when learning fixed associations in the weights is also possible. Tracing attention heads through training reveals that depth growth propagates early induction heads across layers. Ablations show that grown and looped models rely more strongly on induction-ranked heads for both few-shot performance and later-token prediction. Together, these findings provide evidence for a shared inductive bias toward learning from context and suggest that (soft) parameter reuse shapes how this ability develops and which attention mechanisms support it.

1 INTRODUCTION

How a language model acquires its depth can shape the computations it learns. Depth growing trains an initially shallow network and progressively duplicates blocks of layers, allowing later training stages to reuse computations learned earlier. Looping instead repeatedly applies a shared block within each forward pass. Originally motivated by training efficiency (Fahlman & Lebiere, 1989) and parameter efficiency, respectively, both approaches have attracted renewed interest for their reasoning capabilities (Saunshi et al., 2024; 2025; Geiping et al., 2025). Although grown layers become independent after duplication, whereas looped layers remain tied, the two approaches can produce related patterns of iterative computation across depth (Kapl et al., 2026a;b).

This reuse of computation may also favor in-context learning (ICL), as suggested by initial evidence in both grown and looped models (Kapl et al., 2026b). ICL is the ability to use information supplied in a prompt or sequence without updating the model's parameters (Brown et al., 2020). A model that repeatedly refines its representations might also be better equipped to extract and apply patterns from context. Yet, improved reasoning performance alone does not establish this ability. Predictions can rely on associations stored in the weights, on information inferred from the current sequence, or on both. Moreover, a model's improvement in predicting later tokens and its ability to learn a task from demonstrations are related but distinct measurements, with potentially different underlying mechanisms (Olsson et al., 2022; Yin & Steinhardt, 2025).

Prior work provides promising evidence for a connection between depth reuse and ICL. Looped Transformers can learn synthetic regression and other data-fitting tasks with substantially fewer parameters than standard Transformers (Yang et al., 2024; Von Oswald et al., 2023). Studies of pretrained language models also report improved adaptation from demonstrations in grown and looped models for synthetic reasoning tasks (Kapl et al., 2026b). Concurrently, Wang et al. (2026) report

*Correspondence: ferdinand.kapl@tum.de.

†^{\dagger}Provided equal feedback and guidance.

stronger gains with increasing context length and demonstration count in compute-matched looped mixture-of-experts models. What remains less understood is how these behavioral differences arise during training: whether growing and looping favor a context-based solution when memorization is also possible, how they affect the persistence of that solution, and how changes in attention-head mechanisms relate to the different measures of ICL.

In this work, we investigate these questions through complementary experiments on natural language and controlled tasks. We compare dense baselines with depth-grown and looped models on language-model configurations with dense reference sizes from 360M to 3B parameters. We measure position-dependent token loss and scaling with the number of demonstrations for few-shot learning. We then use RegBench (Akyürek et al., 2024) to study learning previously unseen formal languages, and Omniglot-based tasks (Chan et al., 2022; Singh et al., 2023) to separate learning from context from learning fixed associations in the weights. Finally, we track induction and function-vector heads through training and intervene on them in the final models. Our contributions are the following:

• Grown and looped language models benefit more from context. In the main 3B language-model comparison, both achieve larger early-to-late token-loss reductions than the dense baseline, with the grown model also attaining lower absolute late-token loss. Both models also achieve higher GSM8K accuracy across all demonstration counts. On RegBench, grown and looped models predict unseen formal languages more accurately, with their advantage emerging within the first string (Figures 1 and 2).

• Growing and looping favor earlier acquisition and stronger retention of ICL. In controlled Omniglot tasks where both context and fixed class–label associations can solve training queries, grown and looped models retain higher ICL accuracy and exhibit lower in-weights learning (IWL) accuracy than the full-depth dense reference. When labels are reassigned in every sequence, removing a fixed class–label solution, both acquire ICL earlier than the same reference (Figure 3).

• Depth growth propagates early induction heads across layers. Tracing final induction heads backward through training shows that strong heads in the grown model predominantly descend from heads already exhibiting strong induction behavior in early growing stages. Layer duplication produces repeated patterns of this behavior across depth, while looped models exhibit analogous patterns across successive applications of their shared looped block (Figures 4 and 5).

• Grown and looped models rely more strongly on induction heads for ICL. In the main language-model comparison, ablating induction-ranked heads causes larger drops in few-shot performance and larger increases in late-token loss than in the dense baseline. These interventions establish a greater contribution from induction-ranked heads to both behaviors, while function-vector heads remain important (Figure 6).

Together, these experiments show that constructing depth through (soft) parameter reuse shapes both the development of context use and the attention mechanisms supporting it.

References (88)

  • In-context language learning: Architectures and algorithms
  • Predicting the emergence of induction heads in language model pretraining
  • Relaxed recursive transformers: Effective parameter sharing with layer-wise IoRA
  • Eliciting latent predictions from transformers with the tuned lens (opens arXiv in a new tab)
  • SmolLM-corpus, July 2024
  • Language models are few-shot learners
  • Data distributional properties drive emergent in-context learning in transformers
  • Net2net: Accelerating learning via knowledge transfer (opens arXiv in a new tab)
  • Training Verifiers to Solve Math Word Problems
  • MOEUT: Mixture-of-experts universal transformers
  • Recurrent stacking of layers for compact neural machine translation models
  • Universal transformers
  • Stacking your transformers: A closer look at model growth for efficient llm pre-training
  • A mathematical framework for transformer circuits, 2021
  • The cascade-correlation learning architecture
  • Looped transformers for length generalization
  • What can transformers learn in-context? a case study of simple function classes
  • Can looped transformers learn to implement multi-step gradient descent for in-context learning? In International Conference on Machine Learning, 2024
  • Scaling up test-time compute with latent reasoning: A recurrent depth approach
  • Composable function-preserving expansions for transformer architectures (opens arXiv in a new tab)
  • Looped transformers as programmable computers
  • Efficient training of BERT by progressively stacking
  • Olmes: A standard for language model evaluations
  • Measuring massive multitask language understanding
  • Alexia Jolicoeur-Martineau. Less is more: Recursive reasoning with tiny networks. arXiv preprint arXiv:2510.04871, 2025. (opens arXiv in a new tab)
  • Do depth-grown models overcome the curse of depth? an in-depth analysis
  • From growing to looping: A unified view of iterative computation in LLMs
  • Scaling large language models with simple yet effective depth up-scaling
  • Encode, think, decode: Scaling test-time reasoning with recursive latent thoughts (opens arXiv in a new tab)
  • Albert: A lite bert for self-supervised learning of language representations
  • Teaching pretrained language models to think deeper with retrofitted recurrence (opens arXiv in a new tab)
  • In-context learning and induction heads, 2022
  • ICLR: In-Context Learning of Representations
  • Efficient training of language models using few-shot learning
  • On the inductive bias of stacking towards improving reasoning
  • Reasoning with latent thoughts: On the power of looped transformers
  • The Transient Nature of Emergent In-Context Learning in Transformers
  • What needs to go right for an induction head? A mechanistic study of in-context learning circuits and their formation
  • Lessons on parameter sharing across layers in transformers
  • Function vectors in large language models
  • Transformers learn in-context by gradient descent
  • Hierarchical reasoning model (opens arXiv in a new tab)
  • Learning to grow pretrained models for efficient transformer training
  • SMELT: Scaling Laws for Compute-Matched MoE Looped Transformers
  • Looped transformers are better at learning learning algorithms
  • Masked structural growth for 2x faster language model pre-training
  • Which attention heads matter for in-context learning? In International Conference on Machine Learning, 2025
  • Rui-Jie Zhu, Zixuan Wang, Kai Hua, Tianyu Zhang, Ziniu Li, Haoran Que, Boyi Wei, Zixin Wen, Fan Yin, He Xing, et al. Scaling latent reasoning via looped language models. arXiv preprint arXiv:2510.25741, 2025. (opens arXiv in a new tab)
  • The 360M and 1.7B configurations follow SmolLM (Ben Allal et al., 2024), and the 3B configuration follows SmolLM3 (Bakouch et al., 2025)
  • The 360M and 1.7B models use the SmolLM-corpus mixture of FineWeb-Edu-dedup, Cosmopedia-v2, Python-Edu, and Open-Web-Math (Ben Allal et al., 2024), contributing approximately 70%, 15%, 9%, and 6% of training tokens, respectively
  • All models use AdamW with the hyperparameters in Table 1
  • The dense baseline has $L$ independently parameterized layers throughout training
  • For $K = L/b$ stages, stage i has depth ib and receives
  • The budget $T_{prop}$ excludes learning-rate decay, which is appended to the final full-depth stage
  • The 1.7B and 3B trajectories generally use checkpoints every 2000 steps, with additional saves at growth boundaries and at the final step
  • There is no 3B MIDAS run
  • Shared training configurations and the size-specific Loop definitions are given in Appendix A
  • step 200,000 for 360M/1.7B and step 42,400 for 3B
  • >360M</td><td>Baseline</td><td>54.69</td><td>34.67</td></tr><tr><td>MIDAS</td><td>56.00</td><td>34.11</td></tr><tr><td>LIDAS</td><td>57.10</td><td>34.09</td></tr><tr><td>Loop 4-12×2-4</td><td>54.21</td><td>33.69</td></tr><tr><td rowspan=
  • ARC-Easy, BoolQ, HellaSwag, PIQA, and Social IQa use the standard fixed 1000-example subsamples; ARC-Challenge, CommonsenseQA, OpenBookQA, and Wino-Grande use their full splits of 1172, 1221, 500, and 1267 examples, respectively
  • After tokenization, we retain documents with at least $C + 1$ tokens and truncate to $C + 1$, yielding $C$ next-token predictions per document
  • Position labels in the trajectory and position plots use this one-based prediction index
  • With $D = 10,000$ documents and $C$ scored prediction positions per document ($C = 2048$ at 360M/1.7B and 4096 at 3B), the reference for model $m$ is
  • It is not an unweighted average of the logarithmic bin means, whose position counts differ
  • Columns show 360M, 1.7B, and 3B, using the position bins of Figure 1
  • We use lm-eval-harness version 0.4.3, bf16 weights, and a maximum input length equal to the training context
  • Figure 9 reports separate averages over two fixed task sets, both evaluated at $k \in \{0, 1, 2, 4, 8\}$ across all model sizes
  • Zero centered accuracy denotes chance performance and 100 denotes perfect performance
  • Columns show 360M, 1.7B, and 3B
  • Nine or sixteen distinct single-token nouns label the nodes of a $3 \times 3$ or $4 \times 4$ grid, respectively
  • Embedding and attention dropout are 0.1
  • The learning rate warms up for 25,000 steps and then decays by a cosine schedule to one tenth of its peak
  • Their widths are 128 except for Loop 2×6, which uses 256
  • Full-test scores retain the evaluator's batch aggregation; position statistics pool sums and counts within each seed, then average over seeds
  • We merge the Omniglot training and test splits, giving 1623 character classes with twenty $105 \times 105$ grayscale exemplars each
  • Their embeddings are interleaved as $[x_1, y_1, \ldots, x_8, y_8, x_9]$, giving seventeen tokens, with sinusoidal absolute positional encodings
  • Figure 3 compares dense depths 4 and 12, a Loop 4×3 model, and a LIDAS-grown model
  • The context contains four distinct exemplars per class, and the query is a fifth exemplar of one of them
  • The same prompts and random sequences are reused across checkpoints and models within each size
  • A document-start token is prepended
  • Display smoothing averages up to three adjacent shared checkpoints within 2000 steps of the center, including across growth boundaries
  • We select the final top-2% heads independently by PS and FV (10, 16, and 12 heads at 360M, 1.7B, and 3B) and trace these fixed identities backward through training
  • Figures 15 and 17 independently select the final top-2% heads by PS and by FV, giving 10, 16, and 12 heads at 360M, 1.7B, and 3B
  • Exact growth-step measurements are omitted except for the first 360M pre-growth checkpoint at step 4722: its explicit pre-growth stage identifies the four-layer source, and it is the only measured point in that stage
  • For each generated token, we run only the first $l$ layers and decode their residual stream
  • Training uses SGD with Nesterov momentum 0.9, initial learning rate 0.1 with linear decay, weight decay $10^{-3}$, gradient clipping at norm 1, and bf16 autocast
  • An identity-translator (zero-lens) control reproduces the logit lens, and the full-depth exit reproduces the original model
  • The combined figure uses exclusive PS and FV rankings; additional sweeps also include non-exclusive and random rankings