TL;DR
This paper extends the study of "grokking"—the phenomenon where models suddenly generalize long after overfitting—from simple modular addition to complex operations like multiplication and polynomials. The authors demonstrate that Transformers learn distinctive internal "circuits" based on Fourier representations for these tasks and introduce two new metrics, Fourier Frequency Density (FFD) and Fourier Coefficient Ratio (FCR), to track this late-stage generalization.
What Problem Does This Paper Address?
Grokking has fascinated the machine learning community because it defies standard intuition: a model first memorizes the training data (reaching 100% train accuracy but 0% test accuracy) and then, after much more training, suddenly "clicks" and achieves perfect generalization.
While previous research successfully "reverse-engineered" how Transformers solve modular addition using trigonometric identities and Fourier bases, it remained unclear if these findings were a special case. This paper asks: Do these Fourier-based internal representations hold for more complex math? Can we find common features that transfer between different operations? And does training on multiple tasks at once help or hinder this mysterious process?
Methods
The researchers trained small, single-layer causal Transformers on various modular arithmetic tasks (modulo $p=97$). To look under the hood, they employed several key techniques:
- Mechanistic Interpretability: They analyzed the weights and logits using Discrete Fourier Transforms to see which frequencies the model prioritized.
- New Progress Measures: They introduced Fourier Frequency Density (FFD) to measure the sparsity of representations (key for addition) and Fourier Coefficient Ratio (FCR) to measure sinusoidal bias (key for multiplication).
- Pre-Grokked Modules: As shown in Figure 1, they tested transferability by taking a module (like the embedding layer) from a model that had already "grokked" one task and freezing it while training a new model on a different task.
Datasets
The study uses synthetic algorithmic datasets consisting of pairs of integers $(a, b)$ and a target $c$ defined by a modular operation $(a \circ b) \pmod p$.
- Elementary Arithmetic: Addition, subtraction, and multiplication.
- Modular Polynomials: A wide range of expressions including univariate terms ($a^2 + b$), cross terms ($ab + a + b$), and higher-degree factorizable polynomials like $(a+b)^n$.
- Multi-task Mixtures: Combined datasets of different operations to study "co-grokking."
Key Insights and Ideas
- Factorizability is the "Secret Sauce": One of the most striking findings is that polynomials that can be factored into simpler terms (like $(a+b)^2$) grok much more easily than non-factorizable ones (like $a^2 + ab + b^2$). Factorization seems to provide a "pathway" for the model to reuse simpler circuits.
- Subtraction’s Hidden Asymmetry: Mathematically, subtraction is just addition with a negative sign. However, the Transformer sees it differently. While addition learns symmetric representations, subtraction imposes a strong asymmetry in the model's internal "neuron-logit map," making it surprisingly difficult to transfer knowledge between the two.
- Representational Superposition: For complex polynomials, the model doesn't just learn a brand-new algorithm. Instead, it often discovers a superposition of the Fourier representations used for elementary addition and multiplication.
- Co-Grokking: In multi-task settings, the model can experience "co-grokking," where generalization for all tasks happens simultaneously. Interestingly, training on a mixture of "easy" and "hard" tasks can sometimes accelerate generalization for the harder task.
Key Results
The authors found that their new metrics, FFD and FCR, act as excellent "thermometers" for grokking, decreasing sharply exactly when test accuracy begins to climb.
As seen in Figure 2, transferability is highly specific. Pre-grokked embeddings for addition and subtraction accelerate each other, but multiplication requires a fundamentally different representation. Furthermore, transferring a pre-grokked Transformer block for subtraction is notoriously difficult, even when transferring to another subtraction task with a different initialization.
Quantitatively, the study shows that while simple tasks grok within $10^3$ steps, complex polynomials can require upwards of $10^5$ steps, and some non-factorizable expressions fail to generalize entirely within the experimental window.
Limitations and Future Work
The authors acknowledge that their work is limited to synthetic, small-scale models. While these provide a "clean" laboratory for studying grokking, the gap between modular polynomials and the massive, real-world datasets used by Large Language Models (LLMs) remains significant.
Future research directions include:
- Deriving exact analytical solutions for the internal circuits of multiplication and polynomials (currently, the interpretations are largely empirical).
- Investigating if similar "circuit formation" phases occur during the training of LLMs on natural language.
- Exploring how these findings relate to "emergent capabilities" in larger models.
Summary updated