Abstract
Standard learning theory suggests that once a model has perfectly fit its training data but fails to generalize, it has entered a state of overfitting where further training is counterproductive. This paper explores "grokking," a phenomenon where neural networks suddenly achieve perfect validation accuracy on algorithmic tasks long after training performance has saturated. We demonstrate that for certain structured problems, generalization is not a steady progression but a late-stage emergence requiring significantly more optimization than simple memorization.
Introduction
The gap between memorization (rote learning of specific examples) and generalization (understanding underlying rules) is a central challenge in deep learning. While large models often generalize well despite being overparameterized, the mechanics of this transition are often opaque. By utilizing small, "clean" algorithmic datasets—essentially multiplication tables for mathematical structures—we can observe the precise moment a model moves from memorizing individual entries to "grokking" the global logic.
Methodology
We employed a standard decoder-only Transformer architecture consisting of 2 layers, a width of 128, and 4 attention heads. The models were trained on binary operations of the form $a \circ b = c$, where each element was represented as an abstract token. This setup prevents the model from relying on pre-existing numerical relationships.
The training process utilized the AdamW optimizer. A critical component of the methodology was the use of heavy weight decay. This regularization technique penalizes the $L_2$ norm of the weights, effectively pushing the model toward lower-complexity solutions. Training runs were extended significantly beyond typical durations, reaching up to $10^6$ optimization steps.
The Grokking Phenomenon
The most striking finding is the abruptness of generalization. In many algorithmic tasks, validation accuracy remains at chance levels for hundreds of thousands of steps while training accuracy is already 100%.
As illustrated in the figure above, for modular division with a 50% training split, the model "memorizes" the training set within $10^3$ steps. However, it does not "grok" the underlying division rule until nearly $10^6$ steps. This 1000x difference in training time highlights that generalization can be a much harder optimization problem than memorization, even when the underlying rule is simple.
Compute-Data Trade-offs
The onset of grokking is highly sensitive to the amount of available training data. There exists a steep trade-off between data volume and the compute required for generalization.
As the training data fraction decreases, the number of optimization steps required to reach 99% validation accuracy increases exponentially. Below a certain data threshold, the model may fail to generalize entirely within the allocated compute budget, remaining stuck in the memorization phase.
The Role of Weight Decay and Structure
Weight decay appears to be essential for grokking. Without it, models often remain in a state of perfect training accuracy and zero validation accuracy indefinitely. Weight decay acts as a "simplicity bias," forcing the network to find the most compact representation of the data. In mathematical tasks, the most compact representation is typically the correct algorithmic rule.
Furthermore, the nature of the operation affects the speed of grokking. Commutative operations, such as modular addition, are generally learned faster than non-commutative operations like those found in the symmetric group $S_5$.
Conclusion and Future Work
Grokking provides a unique window into the dynamics of generalization. It suggests that for structured problems, the "overfitting" phase may actually be a precursor to a more profound understanding, provided the model is given sufficient time and the right inductive biases. Future research should investigate whether similar "delayed clicks" occur in natural language or vision tasks and whether grokking is linked to the geometric properties of the loss landscape, such as the transition from "sharp" memorized minima to "flat" generalized valleys.
Summary updated