Emergence in non-neural models: grokking modular arithmetic via average gradient outer product

Neil Mallinar, Daniel Beaglehole, Libin Zhu, Adityanarayanan Radhakrishnan, Parthe Pandit, Mikhail Belkin

TL;DR

Grokking—the sudden, delayed generalization of a model long after achieving perfect training accuracy—is widely seen as a unique quirk of neural networks and gradient descent. This paper turns that assumption on its head by demonstrating that kernel machines can also grok modular arithmetic. The authors show that grokking is driven entirely by the gradual learning of structured, block-circulant features, a process captured by the Average Gradient Outer Product (AGOP).

What Problem Does This Paper Address?

Grokking and "emergence" are major talking points in modern machine learning, often described as sudden phase transitions where a model abruptly "clicks" and learns a skill. However, the underlying mechanics remain heavily contested. Some researchers argue that emergence is a "mirage" caused by analyzing discontinuous metrics like accuracy rather than continuous loss. Others believe grokking is inherently tied to deep learning phenomena, such as representation learning via stochastic gradient descent (SGD) or weight decay dynamics.

The authors of this paper investigate a fundamental question: Is grokking unique to neural networks and gradient-based optimization? By decoupling feature learning from neural architectures, they test whether simpler, non-neural models can exhibit the same sudden leaps in generalization.

Methods

The authors employ Recursive Feature Machines (RFM), an iterative algorithm designed to enable feature learning in kernel machines (which natively lack a mechanism to alter their representations).

RFM works by alternating between three steps:

  1. Training a standard kernel machine (using quadratic or Gaussian kernels) to fit the training data.
  2. Computing the Average Gradient Outer Product (AGOP) matrix over the data to identify the most task-relevant feature directions.
  3. Transforming the input data using this learned feature matrix.

Crucially, because RFM solves kernel ridgeless regression exactly at each step, the training loss is identically zero from the very first iteration.

To peek under the hood during training, the authors introduce two "hidden progress measures":

  • Circulant deviation: A metric quantifying how close a feature matrix is to having constant diagonals (a circulant structure).
  • AGOP alignment: The cosine similarity between the feature matrix at iteration $t$ and the final matrix of a fully trained model.

Datasets

The paper evaluates these methods on synthetic modular arithmetic tasks—specifically addition, subtraction, multiplication, and division—using prime moduli (such as $p = 59, 61,$ and $97$). The inputs are formatted using standard one-hot encodings of integer pairs concatenated together (e.g., $e_a \oplus e_b$).

Key Insights and Ideas

  • Grokking is Not Neural: RFM exhibits classic grokking behavior, sharply transitioning from random guessing to 100% test accuracy. Because this happens in a kernel machine with zero training loss throughout, grokking cannot be blamed on SGD optimization paths or neural-specific regularization.
  • The Secret is Block-Circulant Features: To solve modular arithmetic, both RFM and neural networks naturally learn feature matrices with a "block-circulant" (striped) structure.
  • The Discrete Logarithm Trick: For multiplication and division, the block-circulant structure is initially invisible. It only reveals itself when the rows and columns are reordered using the discrete logarithm—mathematically transforming the multiplication problem into an addition problem (see Figure 6).
Figure 3: RFM with the quadratic kernel for modular arithmetic tasks with modulus p = 61. (A) The square root of the kernel AGOPs for addition (Add), subtrac- tion (Sub) visualized without their diagonals to em- phasize circulant structure in off-diagonal blocks. (B) Square root of the kernel AGOPs for multiplication (Mul), division (Div). (C) For Mul and Div, rows and columns of the individual sub-matrices of the AGOP are re-ordered by the discrete logarithm base 2, reveal- ing the block-circulant structure in the features.
  • Grokking is Not a Mirage: Even though standard metrics like test loss and test accuracy look completely flat before the model "groks" the task, the hidden progress measures improve linearly from day one. The sudden phase transition in accuracy is just the visible threshold of a steady, continuous feature-learning process (see Figure 2).
Accuracy, loss, and progress measures across different modular arithmetic tasks

Key Results

  • Sharp Transitions: On a modular addition task ($mod\ 59$), RFM maintains near-zero test accuracy for the first 10 iterations before abruptly climbing to 100% accuracy by iteration 15 (see Figure 1).
Figure 1: Recursive Feature Machines grok the modular arithmetic task f ∗(x, y) = (x + y) mod 59.
  • Bypassing Grokking Entirely: When the authors bypassed RFM training and simply initialized standard kernel machines with random block-circulant features, the models generalized perfectly without needing any iterations.
  • Algorithmic Convergence: The authors mathematically prove that kernel machines utilizing these block-circulant features implicitly implement the Fourier Multiplication Algorithm (FMA). This matches prior mechanistic interpretability work showing that neural networks learn the FMA to solve modular math.

Limitations and Future Work

  • Model Size Constraints: Kernel machines can be viewed mathematically as infinite-width neural networks. As a result, this framework cannot be used to analyze how model size parameters (like width or depth thresholds) impact emergence.
  • Task-Specific Progress Measures: While AGOP alignment is a general metric, circulant deviation relies entirely on knowing the mathematical symmetries of modular arithmetic beforehand. Developing task-agnostic progress measures that can detect hidden feature structures in more complex domains (like natural language) remains an open challenge.

Summary updated

Abstract

Neural networks trained to solve modular arithmetic tasks exhibit grokking, a phenomenon where the test accuracy starts improving long after the model achieves 100% training accuracy in the training process. It is often taken as an example of "emergence", where model ability manifests sharply through a phase transition. In this work, we show that the phenomenon of grokking is not specific to neural networks nor to gradient descent-based optimization. Specifically, we show that this phenomenon occurs when learning modular arithmetic with Recursive Feature Machines (RFM), an iterative algorithm that uses the Average Gradient Outer Product (AGOP) to enable task-specific feature learning with general machine learning models. When used in conjunction with kernel machines, iterating RFM results in a fast transition from random, near zero, test accuracy to perfect test accuracy. This transition cannot be predicted from the training loss, which is identically zero, nor from the test loss, which remains constant in initial iterations. Instead, as we show, the transition is completely determined by feature learning: RFM gradually learns block-circulant features to solve modular arithmetic. Paralleling the results for RFM, we show that neural networks that solve modular arithmetic also learn block-circulant features. Furthermore, we present theoretical evidence that RFM uses such block-circulant features to implement the Fourier Multiplication Algorithm, which prior work posited as the generalizing solution neural networks learn on these tasks. Our results demonstrate that emergence can result purely from learning task-relevant features and is not specific to neural architectures nor gradient descent-based optimization methods. Furthermore, our work provides more evidence for AGOP as a key mechanism for feature learning in neural networks.
BibTeX
@inproceedings{mallinar2025emergence,
  author = {Neil Mallinar and Daniel Beaglehole and Libin Zhu and Adityanarayanan Radhakrishnan and Parthe Pandit and Mikhail Belkin},
  title = {{Emergence in non-neural models: grokking modular arithmetic via average gradient outer product}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=36hVB7DEB0},
}
Figure