Grokfast: Accelerated Grokking by Amplifying Slow Gradients
Jaerin Lee, Bong Gyun Kang, Kihoon Kim, Kyoung Mu Lee
TL;DR
Grokfast addresses the puzzling grokking phenomenon—delayed generalization long after training accuracy saturates—by treating parameter updates as a stochastic signal and amplifying the slow, generalization-inducing gradient components. It introduces two practical gradient-filter augmentations, Grokfast-MA and Grokfast-EMA, that effectively implement a low-pass frequency boost on gradients (and thus on updates) to hasten the transition from overfitting to generalization. The authors provide theoretical justification showing that gradient filtering before the optimizer preserves the same transfer characteristics as filtering the gradient signal itself, and validate the approach across algorithmic data, MNIST, QM9, and IMDb, achieving large reductions in grokking time and improvements in final metrics. While memory/compute trade-offs exist—especially for the MA variant—the EMA version delivers substantial speedups with a modest footprint and broad compatibility, offering a practical tool for studying and exploiting grokking in diverse settings.
Abstract
One puzzling artifact in machine learning dubbed grokking is where delayed generalization is achieved tenfolds of iterations after near perfect overfitting to the training data. Focusing on the long delay itself on behalf of machine learning practitioners, our goal is to accelerate generalization of a model under grokking phenomenon. By regarding a series of gradients of a parameter over training iterations as a random signal over time, we can spectrally decompose the parameter trajectories under gradient descent into two components: the fast-varying, overfitting-yielding component and the slow-varying, generalization-inducing component. This analysis allows us to accelerate the grokking phenomenon more than $\times 50$ with only a few lines of code that amplifies the slow-varying components of gradients. The experiments show that our algorithm applies to diverse tasks involving images, languages, and graphs, enabling practical availability of this peculiar artifact of sudden generalization. Our code is available at https://github.com/ironjr/grokfast.
