Abstract: Large Language Models (LLMs) are prevalent in modern applications but often memorize training data, leading to privacy breaches and copyright issues. Existing research has mainly focused on post-hoc analyses—such as extracting memorized content or developing memorization metrics—without exploring the underlying architectural factors contributing to memorization. In this work, we investigate memorization from an architectural lens by analyzing how attention modules at different layers impact its memorization and generalization performance. Using attribution techniques, we systematically intervene in the LLM's architecture by bypassing attention modules at specific blocks while keeping other components like layer normalization and MLP transformations intact. We provide theorems analyzing our intervention mechanism from a mathematical view, bounding the difference in layer outputs with and without our attributions. Our theoretical and empirical analyses reveal that attention modules in deeper transformer blocks are primarily responsible for memorization, whereas earlier blocks are crucial for the model's generalization and reasoning capabilities. We validate our findings through comprehensive experiments on different LLM families (Pythia and GPT-Neo) and five benchmark datasets. Our insights offer a practical approach to mitigate memorization in LLMs while preserving their performance, contributing to safer and more ethical deployment in real-world applications.
Introduction
Large Language Models (LLMs) are notorious for "parroting" their training data, a phenomenon that raises significant privacy and copyright concerns. While previous research has focused on detecting memorization through post-hoc analysis or removing it via unlearning, the specific architectural components responsible for this behavior have remained largely a "black box." This paper aims to bridge this gap by investigating the trade-off between reasoning and memorization. The central question is whether we can isolate the specific components of a transformer that contribute to rote memorization without damaging its ability to reason and generalize.
Methodology: Attention Short-Circuiting
The researchers introduce a technique called "Attention Short-Circuiting" to probe the functional role of different layers. In a standard transformer block, the attention mechanism mixes information across different tokens. Simply zeroing out a layer typically causes the model to collapse and produce gibberish because the mathematical distribution of internal representations is destroyed.
To avoid this, the authors systematically bypass the attention modules at specific blocks by replacing the attention weight matrix with an identity matrix. This effectively "mutes" the contextual mixing of that layer while keeping other components, such as Layer Normalization and MLP transformations, intact. This empirical approach is supported by a theoretical framework that provides bounds on the difference in model outputs when attention is bypassed. The mathematical analysis suggests that interventions in earlier layers cause errors that amplify through the network, whereas interventions in later layers produce more localized changes.
Experimental Setup
The study evaluates six LLMs across two families: Pythia (ranging from 1.4B to 12B parameters) and GPT-Neo (1.3B and 2.7B).
- Memorization Source: The researchers utilized 15,000 samples from The Pile (the models' training set) known to be highly memorized, with extraction rates exceeding 90%.
- Evaluation Benchmarks: To measure general intelligence and reasoning, the models were tested on ARC-Easy (elementary science), HellaSwag (commonsense reasoning), PIQA (physical commonsense), LAMBADA (contextual word prediction), and Wikitext (general language modeling).
Results and Discussion
The findings reveal a clear "functional depth" within transformer architectures. Early layers appear to be the "engineers" responsible for grammar, semantics, and logic. In contrast, later layers act more like "librarians" or lookup tables, storing specific, high-resolution sequences from the training data.
Targeted Mitigation and Performance Preservation
A key insight is that reasoning and memorization are not as deeply intertwined as previously assumed. Short-circuiting the last quartile of layers (e.g., layers 18-24 in GPT-Neo 1.3B) led to a near-zero Exact Match (EM) memorization score. Crucially, while memorization plummeted, performance on reasoning benchmarks like ARC and PIQA remained nearly identical to the original, unedited model.
Early Layer Sensitivity
The model's "logic" appears to be baked into the early-to-mid representations. Bypassing attention in the first few blocks caused total model collapse, with accuracy dropping to random chance levels. This sensitivity is clearly visible in perplexity measurements; while Wikitext perplexity barely moved when later layers were intervened upon, interventions in early layers caused massive spikes, indicating a loss of coherence.
Conclusion and Future Work
This research demonstrates that memorization is architecturally localized, primarily residing in the deeper layers of the transformer. By "short-circuiting" attention in these blocks, researchers can significantly reduce verbatim memorization with negligible impact on the model's actual intelligence.
While this study focused on attention modules, future work is needed to investigate the role of MLP layers in knowledge storage. Additionally, while single-block interventions were the primary focus here, bypassing groups of blocks simultaneously might offer more effective mitigation for larger models. These insights provide a practical path toward mitigating memorization in LLMs, contributing to safer and more ethical deployment in real-world applications.
Summary updated