Omnigrok: Grokking Beyond Algorithmic Data

Ziming Liu, Eric J Michaud, Max Tegmark

TL;DR

Grokking—the phenomenon where a model suddenly generalizes long after overfitting—isn't just a quirk of mathematical puzzles. This paper introduces the "LU mechanism," showing that grokking occurs due to a mismatch between training and test loss landscapes, and demonstrates that it can be induced in standard tasks like image classification and sentiment analysis by simply tweaking initialization scales and data sizes.

What Problem Does This Paper Address?

In 2022, researchers noticed a bizarre behavior in neural networks trained on "algorithmic" datasets (like modular addition): the model would hit 100% training accuracy almost immediately (overfitting) but stay at 0% test accuracy for thousands of iterations before suddenly "clicking" and achieving perfect generalization. This is grokking.

Until now, grokking was thought to be a mysterious property unique to symbolic, algorithmic data. This paper addresses two fundamental questions:

  1. The Origin: Why is generalization so delayed after overfitting?
  2. The Prevalence: Can grokking happen on "normal" datasets like MNIST or IMDb?

The LU Mechanism

The authors propose the LU mechanism to explain the geometry of grokking. They analyze "reduced" loss landscapes—essentially looking at how loss changes as you vary the weight norm ($L_2$ norm of all parameters) while optimizing for the best possible direction.

The LU Mechanism: Training loss forms an "L" shape, while test loss forms a "U" shape against the weight norm. Grokking is the slow drift from the overfitted region to the generalizing Goldilocks zone.
  • The "L": Training loss typically looks like an "L" against the weight norm. It’s high when weights are small but drops and stays flat (near zero) once weights are large enough to overfit the data.
  • The "U": Test loss typically looks like a "U." It is high at small norms (underfitting) and high at large norms (overfitting), with a "Goldilocks zone" in the middle where generalization is optimal.

Grokking happens when a model is initialized with very large weights (to the right of the "U"). It quickly drops into the "L" (overfitting) and then slowly drifts toward the center of the "U" (generalizing) driven by regularization like weight decay.

Datasets

The study moves beyond toy problems to show grokking is universal:

  • Toy Teacher-Student: A simple MLP setup to validate the LU theory.
  • Algorithmic Data: Modular addition (the original grokking benchmark).
  • MNIST: The classic handwritten digit dataset.
  • IMDb: Movie reviews for sentiment analysis (using LSTMs).
  • QM9: A chemical database for predicting molecular properties (using Graph Convolutional Neural Networks).

Key Insights and Results

Empirical evidence of the LU mechanism, the effect of initialization scale on grokking, and the inverse relationship between grokking time and weight decay.
  • Initialization is the Trigger: Most practitioners don't see grokking because standard initialization schemes (like Kaiming or Xavier) usually place the model near or inside the "Goldilocks zone." By artificially increasing the initialization scale ($\alpha$), the authors forced models to overfit first, inducing grokking in every dataset tested.
  • The Weight Decay Inverse: The time it takes to grok ($t$) is inversely proportional to the weight decay ($\gamma$). Specifically, $t \propto \gamma^{-1}$. If you want a model to "click" twice as fast, double your weight decay.
  • Universal Grokking: The authors successfully induced grokking on MNIST, IMDb, and QM9. For example, on MNIST, by using only 1k training samples and a large initialization, they showed test accuracy staying low for $10^3$ steps before surging to match training accuracy.
  • Representation is the "Drama" Factor: Why is grokking so much more dramatic in math problems than in MNIST? The authors argue it's about the quality of the raw representation. In MNIST, even a "bad" representation (raw pixels) allows for decent accuracy. In algorithmic tasks, a bad representation is no better than a random guess. This makes the transition from "overfitted" to "generalized" look like a sudden jump rather than a gradual climb.
  • Data Size Matters: Increasing the amount of training data widens the "Goldilocks zone," making it easier for the model to find a generalizing solution and effectively "de-grokking" the task (speeding up generalization).

Limitations and Future Work

While the paper successfully generalizes grokking, the authors note that the signals in standard ML datasets are often "less dramatic" than in algorithmic ones. The "LU mechanism" also relies on the assumption that we can find a global minimum on a spherical surface, which might not hold for extremely complex, non-convex landscapes.

Future research could explore whether these insights can be used to prevent grokking (i.e., speed up training) in large-scale industrial models or if this "slow drift" into generalization is a hidden feature of how Large Language Models (LLMs) learn complex reasoning.

Summary updated

BibTeX
@inproceedings{liu2023omnigrok,
  author = {Ziming Liu and Eric J Michaud and Max Tegmark},
  title = {{Omnigrok: Grokking Beyond Algorithmic Data}},
  booktitle = {International Conference on Learning Representations},
  year = {2023},
  url = {https://openreview.net/forum?id=zDiHoIWa0q1},
}
Figure