Language Models "Grok" to Copy

Ang Lv, Ruobing Xie, Xingwu Sun, Zhanhui Kang, Rui Yan

Abstract

Large Language Models (LLMs) do not learn to copy text from their context through steady, incremental improvement. Instead, they "grok" the ability: copying accuracy remains near zero for billions of training tokens before suddenly spiking to saturation long after the training loss has stabilized. This discovery suggests that the fundamental mechanics of In-Context Learning (ICL) can be accelerated and improved using optimization techniques typically reserved for algorithmic "grokking" tasks.

Introduction

While Large Language Models (LLMs) are highly capable of In-Context Learning (ICL) and Retrieval-Augmented Generation (RAG), the "pre-training dynamics"—the specific timeline and mechanics of how these models acquire these skills—remain largely a black box. A core component of ICL is the ability to "copy and paste" relevant information from a prompt. Previous research identified "induction heads" as the neural circuits responsible for this, but the timing and nature of their formation during massive pre-training were unknown. This study investigates whether this skill develops alongside general language modeling or follows a different evolutionary path, specifically looking for signs of "grokking"—sudden generalization long after overfitting or loss stabilization.

Methodology

The researchers trained a 162M parameter Llama-style model (12 layers, 12 heads) from scratch on a 40-billion-token subset of the RedPajama dataset. To track the development of copying skills, checkpoints were saved at regular intervals throughout the training process.

The Context Copying Test

To isolate copying from semantic reasoning, the authors created a synthetic evaluation task. The model was presented with a long sequence of 50 random-token subsequences. It was then given a unique prefix from one of those sequences and required to complete the corresponding suffix. Success in this task proves the model is "copying" from the context rather than relying on internal knowledge.

The Context Copying test uses random token sequences to isolate the model's ability to retrieve and copy information from its context.

Key Insights and Results

Copying as a "Grokked" Skill

In a typical training run, the general language modeling loss stabilizes relatively early (around 5 billion tokens). However, the model’s ability to copy text remains near zero until roughly 15 billion tokens, at which point accuracy suddenly skyrockets. This delay and subsequent sharp jump characterize the skill acquisition as a form of grokking.

Optimization Intensity vs. Data Volume

The speed at which a model learns to copy is not solely a function of the total number of tokens seen. Instead, it depends heavily on the number of update steps. Larger batch sizes, which result in fewer updates for the same amount of data, significantly delay the emergence of copying abilities.

Comparison of training dynamics for Batch Size 32 (top) and Batch Size 128 (bottom). Accuracy (Acc.) in copying jumps suddenly even as the Loss curve remains flat, with smaller batch sizes reaching saturation much earlier.

Regularization and Circuit Migration

Since copying behaves like grokking, the authors applied grokking-enhancement techniques, specifically attention dropout and weight decay. These techniques acted as catalysts, significantly accelerating the "aha moment" and moving the accuracy jump from 15B tokens down to 10B tokens. Furthermore, the study found that induction heads form in a "shallow-to-deep" progression, starting in early layers and migrating to deeper layers as more robust circuits develop.

Discussion and Limitations

The findings suggest a potential "knowledge-skill trade-off" in LLM training. While large batch sizes are efficient for absorbing factual knowledge quickly, smaller batch sizes (providing more update steps) appear superior for developing structural skills like copying.

However, several limitations remain. Due to computational constraints, the study focused on a 162M parameter model; whether these dynamics scale identically to larger models remains to be empirically proven. Additionally, the study focused on simple copying of random tokens. Real-world ICL often involves "fuzzy" copying and reasoning, which may follow more complex developmental curves. Future work is needed to find the optimal training balance for both factual knowledge and procedural skills.

Summary updated

BibTeX
@inproceedings{lv2025language,
  author = {Ang Lv and Ruobing Xie and Xingwu Sun and Zhanhui Kang and Rui Yan},
  title = {{Language Models "Grok" to Copy}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.naacl-short.61},
}
Figure