TL;DR
Grokking—where a neural network suddenly generalizes long after perfectly overfitting—is widely believed to depend on regularization like weight decay. This paper reveals that without regularization, grokking is actually cut short by hardware-level floating-point errors ("Softmax Collapse") caused by uncontrolled logit scaling. By introducing a numerically stable activation function (StableMax) or a gradient-projecting optimizer ($\perp$Grad), the authors achieve grokking without regularization or eliminate the generalization delay entirely.
What Problem Does This Paper Address?
When training neural networks on algorithmic datasets (like modular arithmetic), models often hit 100% training accuracy quickly but take thousands of additional epochs to achieve good test accuracy. This sudden, delayed leap in generalization is called grokking.
Standard deep learning wisdom says that grokking requires regularization (like weight decay) to push the model toward simpler, more generalizable solutions. However, why generalization is so heavily delayed—and why it fails completely without regularization—remains poorly understood.
This paper tackles this mystery from a fresh perspective: numerical stability. The authors investigate whether the failure to grok without regularization isn't a failure of the optimization landscape, but rather a consequence of hardware limitations—specifically, floating-point arithmetic errors.
Methods
The authors identify two interconnected culprits behind the failure to grok without weight decay:
- Naïve Loss Minimization (NLM): After a network reaches 100% training accuracy under cross-entropy loss, the gradient descent updates don't change the model's decision boundaries. Instead, they simply scale up the weights and logits to drive the training loss closer to absolute zero.
- Softmax Collapse (SC): As the logits grow excessively large due to NLM, the network hits the limits of floating-point precision (
float32orfloat16). The exponential terms in the Softmax function trigger absorption errors, where smaller values are mathematically swallowed by larger ones during addition. This forces the cross-entropy loss to evaluate to exactly zero, killing the gradients and halting all further learning before generalization can occur.
To fix these issues, the authors introduce two novel interventions:
- StableMax: A numerically stable alternative to Softmax. Instead of using exponential functions ($e^x$), it uses a softer, piecewise linear ramp function ($s(x) = x + 1$ for $x \ge 0$, and $1/(1-x)$ for $x < 0$). This prevents explosive logit growth and eliminates absorption errors.
- $\perp$Grad (Ortho-grad): A training modification that projects the gradient onto a hyperplane orthogonal to the current weight vector. By stripping away the NLM component (the gradient direction that merely scales weights), the optimizer focuses exclusively on updates that alter the model's actual predictions.
Datasets
The authors evaluate their methods on standard grokking benchmarks and classic datasets:
- Modular Arithmetic: Addition, subtraction, and multiplication modulo 113.
- Sparse Parity: A supervised task predicting the parity of $k$ bits within a larger binary vector.
- MNIST: A subset of 200 training samples evaluated on the full test set to validate the approach in a standard image classification setting.
Key Insights and Ideas
- Grokking is Limited by Hardware Precision: The classic observation that models "overfit and never generalize" without weight decay is often an artifact of floating-point limitations. If you prevent Softmax Collapse, models can grok perfectly fine without any explicit regularization.
- Weight Decay’s Hidden Role: Weight decay is traditionally viewed as a tool to favor simpler solutions. This paper argues its primary benefit in grokking tasks is simply counteracting NLM—pulling the weights back to prevent the model from sliding into numerical instability.
- Delayed Generalization is Optional: The long, agonizing delay before a model groks is the time it spends wasting capacity on scaling up logits via NLM. When $\perp$Grad removes this wasteful optimization direction, the model generalizes almost instantly.
Key Results
The authors demonstrate their findings across several experiments, showing how changing the optimizer or activation function alters the training trajectory:
- Grokking Without Regularization: Replacing Softmax with StableMax allowed MLPs and Transformers to successfully grok on modular arithmetic and sparse parity tasks without weight decay, even as the weight norms grew substantially.
- Instant Generalization: Training with $\perp$Grad ($\perp$AdamW and $\perp$SGD) completely bypassed the prolonged overfitting phase. On a modular subtraction task, the model achieved 100% test accuracy in under 400 iterations, compared to the tens of thousands of epochs required by standard AdamW.
- Precision Effects: Upgrading the precision of standard Softmax from
float32tofloat64delayed the onset of Softmax Collapse, allowing models to make more progress toward generalization before stalling.
Limitations and Future Work
- Homogeneity Assumptions: The theoretical formulation of Naïve Loss Minimization relies on positive homogeneity (properties found in ReLU networks without biases). While the authors show empirical success on architectures with biases and skip connections (like ResNets and GPT2), a formal mathematical characterization for these "quasi-homogeneous" models is still needed.
- Effective Learning Rate: The authors note that weight decay also impacts the effective learning rate of a network. A deeper analysis combining numerical stability with effective learning rate dynamics could provide an even clearer picture of the sudden nature of grokking transitions.
Summary updated