Measuring Sharpness in Grokking

Jack W. Miller, Patrick Gleeson, Charles O'Neill, Thang Bui, Noam LeviarXiv 2024 · DOI · OpenReview

Introduction

Grokking is a remarkable phenomenon in deep learning where a model, after long periods of zero validation accuracy, suddenly achieves near-perfect generalization. While extensive research has focused on the grokking gap—the temporal delay between training and validation success—the internal dynamics of this transition remain poorly understood. This paper introduces a robust framework to quantify the "sharpness" of the grokking event, investigating whether the jump to generalization is instantaneous or gradual.

Methodology: Quantifying the "Aha!" Moment

To measure the suddenness of generalization, the authors propose fitting accuracy curves to a mathematical functional form. Specifically, they utilize the Error Function (Erf) to model the sigmoidal path of accuracy jumps:

$$A(t) = a \cdot \text{Erf}(s[t - t^*]) + b$$

From this fit, two primary parameters are extracted:

  1. Jump-time ($t^*$): The midpoint of the transition.
  2. Sharpness ($s$): A measure of the horizontal compression of the jump.

The study defines two metrics for evaluation: Relative Sharpness ($R_{rel}$), the ratio of validation sharpness to training sharpness, and Absolute Sharpness ($R_{abs}$), defined as the maximum gradient of the accuracy curve. This curve-fitting approach provides a noise-robust lens that focuses on underlying trends rather than epoch-to-epoch fluctuations.

Experimental Framework

The researchers evaluated these metrics across two distinct environments designed to induce grokking:

  • Linear Student-Teacher Setup: A theoretical framework allowing for closed-form mathematical analysis of loss and generalization.
  • MLP with Concealed Parity: A two-layer Multi-Layer Perceptron trained on bit parity tasks. Grokking was induced using a "concealment strategy," where noisy dimensions were added to the input to delay generalization.

The Sharpness-Gap Tradeoff

A central finding of this work is the existence of a fundamental trade-off between the grokking gap and the sharpness of the transition. In both theoretical and experimental setups, a larger grokking gap consistently correlates with lower sharpness. This suggests that if a model takes longer to "grok," the eventual transition to perfect accuracy is more gradual.

Relative and Absolute Sharpness metrics for the MLP model, demonstrating a clear downward trend as the grokking gap increases.

In the MLP experiments, the authors hypothesize that for small gaps, the transition is driven by a rapid "data fit" mechanism. Conversely, for larger gaps induced by higher noise, a slower "complexity penalty" (regularization) dominates, leading to a "softer" transition.

Theoretical results from the Linear Student-Teacher model, showing the same inverse relationship between sharpness and the grokking gap.

Key Results and Discussion

  • Consistency Across Metrics: Both Relative and Absolute Sharpness metrics yielded similar downward trends, validating the robustness of the curve-fitting methodology.
  • Power-Law Scaling: Log-log analysis suggests a power-law relationship between the grokking gap and sharpness, indicating that this trade-off may be a fundamental property of gradient-based optimization.
  • Universality: The appearance of this trend in both simple linear models and non-linear MLPs suggests a universal dynamic in how neural networks transition from memorization to generalization.

Limitations and Future Work

The current framework assumes that accuracy jumps follow an S-curve, which may not apply to tasks where training accuracy increases immediately. Future research aims to test these trends in large-scale models, such as Large Language Models (LLMs), and to unify various grokking induction methods under this single theoretical lens. By quantifying sharpness, researchers can better predict when a model is on the verge of a breakthrough and understand the nature of that transition.

Summary updated

Abstract

Neural networks sometimes exhibit grokking, a phenomenon where perfect or near-perfect performance is achieved on a validation set well after the same performance has been obtained on the corresponding training set. In this workshop paper, we introduce a robust technique for measuring grokking, based on fitting an appropriate functional form. We then use this to investigate the sharpness of transitions in training and validation accuracy under two settings. The first setting is the theoretical framework developed by Levi et al. (2023) where closed form expressions are readily accessible. The second setting is a two-layer MLP trained to predict the parity of bits, with grokking induced by the concealment strategy of Miller et al. (2023). We find that trends between relative grokking gap and grokking sharpness are similar in both settings when using absolute and relative measures of sharpness. Reflecting on this, we make progress toward explaining some trends and identify the need for further study to untangle the various mechanisms which influence the sharpness of grokking.
BibTeX
@misc{miller2024measuring,
  author = {Jack W. Miller and Patrick Gleeson and Charles O'Neill and Thang Bui and Noam Levi},
  title = {{Measuring Sharpness in Grokking}},
  year = {2024},
  eprint = {2402.08946},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2402.08946},
}
Figure