Manuscript Offprint
arXiv:2610.11206Do Flatter Minima Drive Better Generalization? An Algorithmic Separation in Grokking
Abstract
Flat loss landscapes have long been linked to better generalization in neural networks. However, its role as a causal mechanism for generalization is less established. Grokking provides an unique testbed to understand this distinction: models are prone to fit observed data using non-generalizing structure and remain in that regime for prolonged periods, transitioning to generalization only under particular training conditions. In this work, we study whether flat loss landscapes can act as a driving mechanism in this transition. While recent work has argued for flatness as a necessary geometric condition for this transition, we find that biasing training toward flatter solutions using sharpness-aware minimization (SAM) is insufficient to reliably induce this transition, despite producing flatter solutions. However, when SAM is paired with mechanisms that drive generalization such as weight decay, an interesting property emerges: SAM can accelerate the transition to generalizing solutions by up to 4x at the epoch-level. We theoretically untangle this relationship between SAM and weight decay using a minimal interpolating two-layer ReLU model with both memorizing and generalizing solutions. We show that even in this simple setup, flatness alone cannot distinguish a memorizing solution from a generalizing one, while weight decay favors generalizing solutions. However, under a local stability analysis, there exists a window where a memorizing interpolant is locally stable under gradient descent but unstable under SAM in the low-norm regime, which can explain SAM's ability to accelerate this transition. Overall, our results provide a more interpretable account of the role of flatness in driving generalization, especially in settings where models are vulnerable to minimizing loss through learning non-generalizing structure.
1 Introduction
Distinguishing properties that correlate with generalization from those that causally drive it is especially important when learning from noisy, real-world data. In these settings, models can exploit sample-specific features and noise to achieve high performance on their training data, while failing to generalize on unseen data. An attractive mechanism for inducing generalization is biasing training towards flatter loss landscapes which have long been associated with generalization in artificial neural networks. Models that converge to flatter minima often exhibit better performance on unseen data [Hochreiter & Schmidhuber, 1997, Keskar et al., 2017], motivating optimization methods such as sharpness-aware minimization (SAM) [Foret et al., 2021] that explicitly bias training toward locally flat solutions at an additional computational cost [Andriushchenko & Flammarion, 2022, Compagnoni et al., 2023, Wen et al., 2023].
To understand whether flatness drives generalization in settings where memorizing solutions are particularly attractive, we study grokking, a unique phenomenon where models first reach near-zero training loss while remaining near chance on held-out data, and only after prolonged optimization abruptly transition to high test accuracy [Power et al., 2021]. Unlike conventional training, where
Preprint.
memorization and generalization often develop simultaneously, grokking exposes a temporally separated transition from a memorizing solution to a generalizing one. This makes it possible to algorithmically separate and track differing characteristics between memorizing and generalizing interpolants. Prior work has uncovered two leading mechanisms that can induce this transition from memorization to generalization. Mechanistic studies of modular arithmetic have established a decrease in parameter norm as central in inducing this transition from memorization to generalization, arguing that generalizing circuits become favorable once they are cheaper than memorizing alternatives [Varma et al., 2023]. More recently, flatness has been proposed as a necessary geometric condition to induce this transition, [Han et al., 2025] which stands as an alternative explanation.
Our observations reconcile these two threads of prior research on mechanisms that induce generalization in grokking. We use SAM to directly test whether biasing optimization toward flatter solutions is sufficient to trigger the memorization-to-generalization transition. Across several architectures on modular arithmetic tasks, we find that it is not: SAM alone consistently produces substantially flatter solutions while models remain memorizing. These experiments provide direct counterexamples to the hypothesis that flatness alone selects generalizing solutions, challenging existing work. [Han et al., 2025] However, when pairing SAM with weight decay, we observe that the system reaches generalizing regimes substantially earlier at an epoch level: up to 4x faster than weight decay alone. This acceleration increases with the strength of SAM's flatness regularization, until SAM can no longer meaningfully enforce flatness due to inaccuracy of the first-order Taylor estimate that it relies upon. Figure 1 summarizes this contrast. We explain these phenomena through an algorithmic separation: while SAM fails to distinguish memorizing and generalizing interpolants (whereas parameter norm does), SAM changes the local stability of memorizing solutions once weight decay has moved the system into the appropriate low-norm regime.
To develop a theoretical understanding of this algorithmic separation, we construct a minimal two-layer interpolating network that isolates the sufficient structural conditions under which this separation emerges. We explicitly construct two classes of local optima—memorizing and generalizing interpolants—which, by design, have identical trace flatness; thus flatness does not distinguish between them. At the same scale, however, generalizing interpolants use shared features rather than sample-specific neurons, and (for sufficiently large training set size) the norm of the generalizing solutions is strictly smaller than that of the memorizing solutions. Thus, incorporating

Figure 1: Flatness regularization accelerates generalization in grokking where grokking already occurs. It does not, however, trigger generalization alone. Lighter colors correspond to stronger regularization. Stronger regularization is linked with faster generalization.
ing weight-decay into optimization can trigger grokking as it leads to eventual decrease in the norm of the parameters. We then analyze local stability under gradient descent (GD) and SAM. Under the quadratic SAM approximation, SAM changes the ‘effective’ local curvature, producing a regime in which a memorizing interpolant is stable under GD but unstable under SAM. This shows that SAM is not the selector of generalization: selection is driven by norm and weight decay [Loshchilov & Hutter, 2019, D’Angelo et al., 2024]. SAM instead conditionally accelerates escape from memorizing solutions faster than GD once the trajectory has entered low-norm regimes where memorizing solutions become fragile.
We make three key contributions in this work. First, we provide empirical counterexamples to flatness-as-selector explanations of grokking on interpretable, modular arithmetic tasks: SAM-only produces very flat models that remain memorizing, while WD and SAM+WD grok. Second, we prove an algorithmic separation between flatness, norm, and local stability in an interpolating ReLU model. Third, we extend our findings beyond modular arithmetic to show strikingly similar acceleration-flatness relationships in image classification and natural language processing tasks across several architectures, demonstrating the broader applicability of our work beyond interpretable settings. Together, these results highlight the interplay between loss landscape geometry (via flatness), model capacity (via norm), and generalization.
SAM and the flatness hypothesis. The hypothesis that flat minima generalize better has a long history [Hochreiter & Schmidhuber, 1997, Keskar et al., 2017]. One popular optimization algorithm in this line of research is Sharpness-Aware Minimization (SAM), which minimizes maximum loss in the vicinity of the current minima [Foret et al., 2021]. Dinh et al. [2017] showed that sharpness measures can be manipulated by reparametrization, and Kaur et al. [2022] demonstrated that can decrease under SAM without generalization gains. Theoretical analyses have revealed that SAM's implicit bias differs from direct curvature minimization: Andriushchenko & Flammarion [2022] showed SAM biases toward -norm minimization in diagonal linear networks, while Compagnoni et al. [2023] showed via SDE analysis that SAM implicitly regularizes the gradient norm rather than the Hessian. Wen et al. [2023] argued that sharpness alone is neither necessary nor sufficient for generalization, which is consistent with the flat-but-memorizing counterexample we isolate here in grokking.
Flatness in grokking. Han et al. [2025] observes that regularizing for sharper solutions delays generalization, resulting in grokking-like phenomena. They conclude that flatness must, in turn, be a necessary prerequisite for generalization within grokking. We recreate their work on language and vision tasks, as well as more canonical grokking setups such as modular arithmetic, finding that 1) flatness can occur without generalization in grokking and 2) sharp solutions often generalize. Specifically, our work challenges the necessity claim: while relative flatness can correlate with the onset of generalization, our results show that this correlation does not extend to flatness being a causal selector of this transition. Additionally, we refine their work to demonstrate specific ways flatness can be used to actually accelerate generalization (as opposed to using sharpness to delay it) which can explain the benefit of methods like SAM in practice. We distinguish a relationship between the extent of flatness and the speed of generalization in grokking. Lastly, we discuss how their proposed metric of relative flatness is not invariant under changes in confidence or scaling, which can potentially be misleading, motivating our work further. See Section A.1.
Grokking beyond algorithmic data. Rather than attributing delayed generalization solely to the discrete structure of algorithmic tasks, Liu et al. [2023] argue that grokking can arise from a geometric mismatch between the training and test loss landscapes. Grokking occurs when optimization first reaches a high-norm memorizing solution, after which regularization slowly moves the model toward the lower-norm region where test performance improves. By increasing initialization scale and controlling regularization, this work induces this transition on image, language, and molecular prediction tasks. We recreate their setup, training MLPs on MNIST and LSTMs on IMDb with larger initialization scales and weight decay, reinforcing the existence of a relationship between the extent of flatness and the speed of grokking in more practical training regimes, further demonstrating the broader applicability of our results.
3 Preliminaries
To enforce flatter loss landscapes and test our claim, we use SAM, as introduced by Foret et al. [2021]. SAM relies on a first-order Taylor estimate of the Hessian to estimate the degree of flatness in the loss landscape, with a higher value of indicating an estimated flatter region, until becomes too large and the flatness can no longer be enforced due to the first-order Taylor estimate degrading in accuracy.
Specifically, consider a model parameterized by a weight vector and a per-sample loss function . Define training data sampled i.i.d. from a data distribution D. The traditional training loss is defined as . SAM searches for a flatter minimum by combining the traditional loss with maximum loss in the vicinity defined by perturbation radius . Formally, it is defined as follows:
4 Theoretical Motivation
In this section, we construct and analyze a 2-layer ReLU network to motivate why flatness can accelerate but not induce generalization. We find that, in this minimal example, flatness by itself may not be able to act as a selector between memorizing and generalizing branches because these branches can have identical trace flatness while generalizing branches have strictly smaller parameter norms. We then analyze local stability under gradient descent (GD) and SAM, showing how in these solutions a memorizing interpolant can be unstable under SAM but not GD, indicating a potential avenue through which SAM can conditionally accelerate escape from memorizing solutions faster and thus accelerate the transition to generalizing solutions.
4.1 Setup: Interpolating ReLU construction
Let , , and be a training set with distinct inputs and labels . We consider a two-layer ReLU network , with . We use the squared training loss . At an interpolating differentiable solution, the Hessian is: , with .
Memorizing interpolant. For each training sample , define one neuron , , . This neuron activates only on the full data point , thus memorizing it. Thus, the resulting network interpolates the training set but outputs zero on hypercube points not in the training set.
-generalizing interpolant. Fix . For each pattern , define one neuron , , . For an input , exactly one neuron matching the pattern activates . The output is then . Thus, multiple inputs can activate the same neuron, in contrast with the memorizing interpolant where each neuron is activated by exactly a single data point. Thus the -interpolant generalizes because it has learnt a superset of the pattern necessary for generalization. Smaller corresponds to sparser learning. Further define . As we shall see in the sequel, measures the flatness of the interpolant, entirely dependent on and independent of . Thus interpolants identify a set of solutions with varying complexity and flatness (dependent on ).
4.2 Algorithmic separation of solutions
We analyze selection among interpolating solutions through local stability of these optima [Chang & Khanna, 2025, Dexter et al., 2024]. Since both memorizing and generalizing solutions can achieve zero training loss, the tool of local stability tells us which of them are stable under the optimizer.
dynamics. In other words, given certain local properties of the optimum, will an optimization algorithm (e.g. gradient descent or SAM) settle at this optimum (i.e., be stable) or escape from it (unstable). We use flatness and norm to compare relative stability properties of SAM and GD on memorizing vs generalizing minima.
Definition 1 (Linear stability under GD and SAM [Chang & Khanna, 2025]). Let be an interpolating solution with Hessian . Under local quadratic approximation, GD with stepsize has linearized update . Under the quadratic approximation for SAM used by Chang & Khanna [2025], the effective curvature is , , and the linearized update is .
Under the localized stability analysis, we say is linearly stable under a method if the corresponding update matrix has spectral radius strictly less than one, which ensures that lies in an attractor basin from which the optimizer will not escape (is stable within). We now present our result.
Theorem 1 (Algorithmic separation). Consider the memorizing interpolant and the -generalizing interpolant defined in Section 4.1. Then the following hold.
- Flatness does not separate. Both interpolants have the same trace flatness:
- Norm separates. For any fixed scale r > 0 and sufficiently large n > ,
Thus, among interpolating solutions at the same scale, the generalizing interpolant has strictly smaller parameter norm.
- SAM accelerates within the low-norm regime. There exist thresholds , such that for any the memorizing interpolant is locally stable under GD but unstable under SAM.
Discussion. Theorem 1 separates three roles that are often conflated in explanations of grokking. First, flatness does not distinguish between memorizing and generalizing solutions: both interpolants have identical trace flatness, so flatness alone cannot act as a selector. Second, norm provides a clear separation: at the same scale, the generalizing interpolant uses shared features and therefore achieves strictly smaller parameter norm than the memorizing interpolant. This identifies weight decay, rather than flatness, as the mechanism that selects the generalizing branch.
Finally, the theorem clarifies the role of SAM. In high-norm regimes, memorizing solutions remain stable under both GD and SAM i.e., GD and SAM can both get “stuck” in these minima. However, once weight decay reduces the norm into a low-norm regime, SAM destabilizes memorization earlier than GD, leading to faster escape from such minima. Thus SAM accelerates the transition to generalization, but only after the system has entered the regime selected by weight decay. While our theoretical result and empirical evaluation are in the context of norm and weight decay, we believe the norm here is just a proxy for model capacity in general. We leave these investigations as future work, and instead utilize this framework to motivate why this phenomenon occurs in grokking.
5 Experiments
Motivated by our theoretical analysis, we examine the effect of SAM and weight decay on several datasets and architectures. We design two sets of experiments. First, we attempt to isolate causal mechanisms in generalization through modular arithmetic, a series of canonical grokking tasks where the epoch-level transition between memorizing and generalizing interpolants is large, and is well studied and more interpretable [Nanda et al., 2023]. In this setting, we demonstrate how flatness is insufficient to trigger generalization, while weight decay is. We also show how SAM paired with weight decay accelerates the grokking transition as increases, until the benefits begin to taper off as SAM is unable to enforce flatness at high values of .
Second, we show on vision and language tasks that demonstrate grokking-like behavior [Han et al., 2025, Liu et al., 2023] and generalize consistently through standard training conditions, SAM maintains this trend of accelerating how fast generalizing solutions are reached at the epoch-level. While it is challenging to isolate causal mechanisms of generalization on these tasks, they support our claim that SAM accelerates the transition to a generalizing regime once sufficient conditions to trigger generalization are already present.
5.1 Grokking on Modular Arithmetic
Modular arithmetic tasks are particularly attractive for testing mechanisms that induce generalization, because the onset of generalization is well studied and linked to mechanisms such as the development of Fourier-like circuits [Nanda et al., 2023]. This allows us to design experiments that isolate what drives the transition to generalizing solutions.
Table 1: Experimental conditions. WD = Weight Decay
| Condition | Description |
|---|---|
| A | WD grokking baseline |
| B | SAM |
| C | SAM + WD |
| D | No regularization (memorizing baseline) |
For these tasks, we consider for . We train 1 and 2-layer transformers, in 4 conditions, summarized in Table 1. We train each condition on each model size, with 5 seeds (treating each as an independent condition for SAM-based methods). Each signifies a different level of flatness enforced by SAM. Detailed descriptions of the experiments are located in Appendix A.2.
Measuring Acceleration in Generalization Acceleration is calculated as how much faster methods reach the required accuracy threshold (see Appendix A.2). Precisely, we define to be the acceleration of how much faster SAM with weight decay (WD) with generalizes over just WD:
Here, indexes the random seed, is the SAM radius, and are defined as the first epoch at which the WD or SAM+WD run with seed completes its transition, respectively. The plotted value is the median same-seed acceleration across seeds.
Measuring Curvature For modular arithmetic tasks, we verify that SAM approaches flatter solutions through 3 curvature metrics. First, we estimate the largest training-loss Hessian eigenvalue using Hessian-vector products computed by automatic differentiation, avoiding explicit Hessian materialization, and apply 50 iterations of the Lanczos method to the empirical training-loss Hessian with respect to all trainable parameters [Pearlmutter, 1994, Lanczos, 1950, Yao et al., 2020]. We additionally report the scale-normalized variant of this. Lastly, we also report the relative flatness metric as implemented by Han et al. [2025] who studied flatness in grokking, although we believe the Hessian eigenvalue metrics provide a more accurate estimation of flatness (See Appendix A.1). The full tables containing all results are located in Appendix 2, 3.
Flatness does not Drive Generalization Figure 2 shows our results training all experimental conditions on modular arithmetic tasks. The results demonstrate that SAM-only finds flattest solutions, evidenced by the lowest maximum eigenvalues of the Hessian. Tables 2, 3 shows that this is true for other flatness metrics as well. Despite being flatter solutions, however, these models do not grok in any setting, regardless of the value of or seed. This suggests that flatness of the underlying solution by itself is not sufficient to produce the generalization transition. Conversely, weight decay methods often find sharper solutions, and yet exhibit grokking behavior on nearly all settings, achieving high validation accuracy. Thus, our results highlight a lack of any direct link between flatness of the minima and the presence of grokking. These results corroborate our theoretical insights that flatness alone cannot act as a reliable selector between the memorizing and generalizing branches while weight norm can.

Figure 2: Flatness alone does not explain the generalization transition. Red bars (left axis) show the percentage of modular arithmetic runs reaching the generalization transition; blue bars (right axis, log scale) show the mean final-checkpoint sharpness of the training-loss Hessian. SAM-only finds by far the flattest solutions yet no run generalizes, while weight-decay-based runs generalize in 99% of cases despite substantially sharper final solutions. No regularization pools 20 runs (4 settings 5 seeds); SAM-only pools 180 runs across several values of ; Weight Decay methods pool WD and SAM+WD runs across all values of (200 runs).

Figure 3: SAM accelerates generalization. Acceleration of the grokking transition under SAM+WD relative to WD alone, as a function of the SAM radius , across Transformer architectures on modular addition. Acceleration is the median per-seed ratio of the WD grokking epoch to the SAM+WD grokking epoch; the dashed line marks the WD baseline ( ). Shaded regions show standard deviation of the SAM+WD grokking epoch across 5 seeds. Blue stars mark increases in the scale-normalized sharpness , indicating where first-order Taylor estimates from SAM begin to degrade and can no longer enforce flatness.
Flat Solutions Transition Faster Figure 3 shows that pairing SAM with weight decay substantially accelerates the transition to generalizing solutions across all modular arithmetic tasks. In the addition task with p = 97 and a 1-layer transformer, for instance, the appropriate value of can achieve up to epoch-level acceleration compared to using only weight decay. We observe that the acceleration tends to increase with the size of , suggesting a relationship between flatness regularization strength and the time it takes to make the generalizing transition. This effect, however, is not indefinite. As grows over a certain threshold, acceleration can start to slow down rapidly. This slowdown may be attributed to the first-order approximation used by SAM to estimate the maximum loss in a local neighborhood, which becomes inaccurate as increases beyond a certain threshold. Appendix A.4 supports this, showing that the maximum eigenvalue of the Hessian decreases as increases up to the same approximate threshold that shows a decrease in generalization speed in Figure 3. These results suggest that SAM can no longer meaningfully increase flatness as rho gets too large, which

Figure 4: Relationship between SAM radius and grokking speedup across models trained on CIFAR-10 (left) and SST-5 (right). Larger generally induces stronger flatness regularization and leads to a faster grokking transition when combined with weight decay until is too large. Shaded regions indicate one standard deviation above and below the median across 3 seeds.

Figure 5: Relationship between SAM radius and grokking speedup across models trained on MNIST and IMDB as defined by Omnigrok. Larger generally induces stronger flatness regularization and leads to faster grokking transition when combined with weight decay until is too large. Shaded regions indicate one standard deviation above and below the median across 3 seeds.
can cause an eventual decline in grokking speed. Together, these results show that moving towards flatter solutions with lower weight norm provides good guidance to the generalizing trajectory.
5.2 Accelerating Generalization on Practical Tasks
These results indicate broader applicability than on modular arithmetic. Several datasets across vision and language tasks are observed to exhibit grokking-like phenomena. Liu et al. [2023] demonstrate delayed generalization in grokking through a mismatch between the training and test image, language, and molecular datasets, known as Omnigrok. Han et al. [2025] demonstrate delayed grokking through regularization for sharpness across vision and language tasks. We recreate these setups with the addition of SAM, showing that, while difficult to isolate core mechanisms of generalization in these less interpretable datasets, SAM continues the pattern of accelerating this transition when these core mechanisms are already present. Figure 4 demonstrates the relationship between flatness and the speed of generalization by training ResNets on CIFAR-10 and TinyBERT and DistilGPT2 on SST-5. Figure 5 demonstrates this trend on the setup on LSTMs and MLPs used in Omnigrok. Full experimental details are provided in the Appendix.
5.3 Results
Our experimental results highlight three key findings across all tasks, including modular arithmetic, image classification, and natural language processing:
-
SAM-based training results in solutions that are the flattest, but those solutions fail to generalize in interpretable tasks where other factors are known to induce grokking.
-
SAM-based training, combined with conditions that reliably induce generalization (e.g. weight decay), makes the transition to generalizing solutions far quicker than with weight decay alone.
-
The acceleration of the transition to generalization regimes is well explained by the increase in perturbation radius up to the threshold where SAM-based methods can meaningfully induce flatness.
These results show that seeking flatter minima by itself does not make the transition to the generalizing branch, but accelerates the generalization transition on tasks where grokking already happens (usually through weight decay), corroborating our hypothesis.
6 Limitations
In this section, we discuss limitations of our work. First, our theoretical analysis that isolates the roles of flatness, norm, and local stability applies to an analytically tractable setting, and does not fully model the extensive architectures used in our experiments, such as Transformers, ResNets, LSTMs, etc. The theoretical analysis also makes assumptions on the loss and the quadratic approximation to SAM that make the separation of memorization and generalization phases transparent, but do not imply that the same stability thresholds or norm comparisons hold unchanged for cross-entropy loss, attention layers, normalization layers, or stochastic minibatch training. Our conclusions are also scoped to the optimization regimes we study. We demonstrate that flatness cannot cause generalization alone through modular arithmetic, a more interpretable task where weight decay has been shown to be key to grokking. In tasks on image classification and natural language processing, we do not show this, because isolating the impact of weight decay and other factors that may cause generalization is significantly more challenging. We do, however, demonstrate that the relationship between the speed of generalization and the strength of flatness regularization through SAM persists on all tasks. Lastly, SAM introduces additional computational costs that may limit its use in practice. Each SAM update requires computing an adversarial perturbation in parameter space, which adds an extra forward-backward pass compared with standard training. This overhead may offset some of the benefits in speed from reaching the generalizing regime in fewer epochs. Our speedup metric focuses on epoch-level transition time rather than total compute, memory cost, or energy usage, as the focus of this paper is on interpretability and understanding the role of flatness, rather than producing new optimizers or regularization. Future work may consider variations of SAM that retain many of the same benefits with lower computational cost [Becker et al., 2025, Ji et al., 2024].
7 Conclusion
In this work, we study whether flatness can act as a causal mechanism for driving generalization in regimes where memorizing solutions are more favored. We revisit the role of flatness in grokking and find that it is not necessary for generalization, challenging existing work. Through sharpness-aware minimization, we disentangle the influence of flatness and find that while it cannot reliably drive generalization, it can accelerate the transition significantly. We provide new evidence for a strong relationship between the approximate strength of flatness regularization and the speed of generalization, uncovering new perspectives on the role of flatness that extend meaningfully to practical settings, including computer vision and natural language processing tasks across several architectures.
We provide a theoretical construction that can explain this behavior through an algorithmic separation between flatness, norm, and stability. In a two-layer ReLU model with both memorizing and generalizing interpolants, trace flatness is identical and cannot distinguish them. Parameter norm, however, separates the branches: the generalizing interpolant uses shared structure and has lower norm than the memorizing interpolant once the training set is sufficiently large. This identifies how weight decay can act as the mechanism that selects generalizing structure, while SAM destabilizes memorizing solutions in the low-norm regime, thereby accelerating escape, while being unable to move optimization toward the generalizing branch by itself. Together, these results better reconcile two threads of research: flatness and grokking, while casting further light onto causal mechanisms for generalization.
8 Acknowledgments
This work was done at Purdue University. We thank Professor Rajiv Khanna and Young In Kim at Purdue University for their valuable insights, especially towards developing theoretical models to explain these results.
References
Andriushchenko, M. and Flammarion, N. Towards understanding sharpness-aware minimization. In ICML, 2022.
Jiao, X., Yin, Y., Shang, L., Jiang, X., Chen, X., Li, L., Wang, F., and Liu, Q. TinyBERT: Distilling BERT for natural language understanding. In EMNLP, 2020.
Sanh, V., Debut, L., Chaumond, J., and Wolf, T. DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter. In NeurIPS, 2019.
Chen, X., Hsieh, C.-J., and Gong, B. When vision transformers outperform ResNets without pre-training or strong data augmentations. In ICLR, 2022.
Monzio Compagnoni, E., Biggio, L., Orvieto, A., Proske, F. N., Kersting, H., and Lucchi, A. An SDE for modeling SAM: Theory and insights. In ICML, 2023.
Dinh, L., Pascanu, R., Bengio, S., and Bengio, Y. Sharp minima can generalize for deep nets. In ICML, 2017.
Foret, P., Kleiner, A., Mobahi, H., and Neyshabur, B. Sharpness-aware minimization for efficiently improving generalization. In ICLR, 2021.
Han, T., Adilova, L., Petzka, H., Kleesiek, J., and Kamp, M. Flatness is necessary, neural collapse is not: Rethinking generalization via grokking. In NeurIPS, 2025.
Yao, Z., Gholami, A., Keutzer, K., and Mahoney, M. W. PyHessian: Neural networks through the lens of the Hessian. In 2020 IEEE International Conference on Big Data, 2020.
Pearlmutter, B. A. Fast exact multiplication by the Hessian. Neural Computation, 1994.
Lanczos, C. An iteration method for the solution of the eigenvalue problem of linear differential and integral operators. Journal of Research of the National Bureau of Standards, 1950.
Hochreiter, S. and Schmidhuber, J. Flat minima. Neural Computation, 9(1):1–42, 1997.
Kaur, S., Cohen, J., and Lipton, Z. C. On the maximum Hessian eigenvalue and generalization. In NeurIPS Workshop: I Can't Believe It's Not Better!, 2022.
Keskar, N. S., Mudigere, D., Nocedal, J., Smelyanskiy, M., and Tang, P. T. P. On large-batch training for deep learning: Generalization gap and sharp minima. In ICLR, 2017.
Liu, Z., Michaud, E. J., and Tegmark, M. Omnigrok: Grokking beyond algorithmic data. In ICLR, 2023.
Loshchilov, I. and Hutter, F. Decoupled weight decay regularization. In ICLR, 2019.
D'Angelo, F., Andriushchenko, M., Varre, A., and Flammarion, N. Why do we need weight decay in modern deep learning? In NeurIPS, 2024.
Nanda, N., Chan, L., Lieberum, T., Smith, J., and Steinhardt, J. Progress measures for grokking via mechanistic interpretability. In ICLR, 2023.
Petzka, H., Kamp, M., Adilova, L., Sminchisescu, C., and Boley, M. Relative flatness and generalization. In NeurIPS, 2021.
Power, A., Burda, Y., Edwards, H., Babuschkin, I., and Misra, V. Grokking: Generalization beyond overfitting on small algorithmic datasets. In 1st Mathematical Reasoning in General Artificial Intelligence Workshop, ICLR, 2021.
Varma, V., Shah, R., Kenton, Z., Kramár, J., and Kumar, R. Explaining grokking through circuit efficiency. arXiv:2309.02390, 2023.
Wen, K., Li, Z., and Ma, T. Sharpness minimization algorithms do not only minimize sharpness to achieve better generalization. In NeurIPS, 2023.
Zhang, X., Shang, Y., Yang, E., and Zhang, G. Is grokking a computational glass relaxation? In NeurIPS, 2025.
Zhong, Z., Liu, Z., Tegmark, M., and Andreas, J. The clock and the pizza: Two stories in mechanistic explanation. In NeurIPS, 2023.
Li, Z., Fan, C., and Zhou, T. Grokking in LLM pretraining? Monitor memorization-to-generalization without test. In ICLR, 2026.
Dexter, G., Ocejo, B., Keerthi, S. S., Gupta, A., Acharya, A., and Khanna, R. A precise characterization of SGD stability using loss surface geometry. In ICLR, 2024.
Wei-Kai Chang and Rajiv Khanna. A unified stability analysis of SAM vs SGD: Role of data coherence and emergence of simplicity bias. In NeurIPS, 2025.
Becker, M., Altrock, F., and Risse, B. Momentum-SAM: Sharpness aware minimization without computational overhead. In NeurIPS, 2025.
Ji, J., Li, G., Fu, J., Afghah, F., Guo, L., Yuan, X., and Ma, X. A single-step, sharpness-aware minimization is all you need to achieve efficient and accurate sparse training. In NeurIPS, 2024.
A Appendix
A.1 A note on Relative Flatness [Han et al., 2025]
In addition to measuring sharpness using methods based on the maximum eigenvalue of the Hessian during training, we report sharpness on the relative flatness metrics used by prior works Han et al. [2025].
Let denote the softmax probability vector, the penultimate representation used by the final classifier, and W the final unembedding/classifier matrix. The base final-layer Hessian factor is
Relative flatness is defined as
While this metric may not be as consistent as the other flatness metrics we use, our results do not necessarily contradict Han et al. [2025], due to this metric not being invariant to several function-preserving changes in the classifier. For example, this quantity can change substantially under changes in confidence or scaling even though the final induced classifier is unchanged. Thus, an observed increase in this metric along a grokking trajectory does not by itself imply that flatness is the causal variable selecting the generalizing solution.
A.2 Experimental Details
Modular Arithmetic For modular arithmetic tasks, we consider for . For each setting, all unordered pairs are split 30%/70% into train and validation sets with a fixed seed. These pairs are generated synthetically through uniform sampling. Input tokens are ; the target is the residue. We employ a single-layer Transformer ( , 4 heads, , parameters), and a 2-layer Transformer with the same width ( parameters). All experiments use full-batch training, learning rate , and AdamW [Loshchilov & Hutter, 2019], and cross-entropy loss. This experimental setup is an adaptation of existing work by Nanda et al. [2023].
For SAM-based methods (SAM-only and SAM with weight decay), we use the following values of : . We consider a model to have fully transitioned once it has reached a generalizing interpolating solution with both training and validation accuracy above 99%.
Relative Flatness in Grokking [Han et al., 2025] demonstrates delayed grokking through regularization for sharpness. We recreate several of their tasks to demonstrate specific ways flatness can be used to actually accelerate their grokking on image and language tasks.
We train ResNet-10s and ResNet-18s on CIFAR-10 and fine-tune DistilGPT2 and TinyBERT on SST-5 as outlined in their work. The threshold to determine when a generalizing interpolant is reached is 99% training set accuracy, 75% validation set accuracy for CIFAR-10, and 99% training set accuracy and 45% validation set accuracy for language tasks on SST-5.
Omnigrok Omnigrok demonstrates delayed generalization in grokking through a mismatch between the training and test image, language, and molecular datasets. We recreate their setup and demonstrate the flatness-generalization relationship on their image and language tasks.
Specifically, we train MLPs on MNIST and LSTMs on IMDB as they outline and pair them with SAM. The respective thresholds to determine if a generalizing interpolant is reached are 60% and 54%, respectively.
A.3 Proofs
Proof of Theorem 1. We prove the three claims in order:
- Flatness does not separate. For the memorizing interpolant, recall that for each training point , , , . At , . For any in , we have , and hence . Thus neuron activates only on , and . So the memorizing construction interpolates the training set.
For the -generalizing interpolant, . The neuron indexed by this satisfies . Every other pattern differs in at least one coordinate, so , and hence . Therefore exactly one neuron activates, and . Thus computes the target rule on the full hypercube.
At an interpolating differentiable solution for squared loss,
Therefore
For both constructions, exactly one neuron is active on . For the active neuron, , , . Thus
Averaging over i gives
- Norm separates. Define , . For the memorizing interpolant, each of the neurons satisfies , , . Hence
For the -generalizing interpolant, there are neurons, each satisfying , , . Thus, . Therefore if ,
- SAM destabilizes memorization in a low-norm stability window. For the memorizing interpolant, the gradients have disjoint parameter support, so they are mutually orthogonal. Since , the nonzero eigenvalues of are all equal to . Thus .
Under GD, the ‘top-mode’ multiplier is . Therefore GD is locally stable iff , equivalently .
Under the quadratic SAM approximation, , . Thus the effective top curvature is , and the top-mode SAM multiplier is . SAM is locally unstable whenever , which holds when . The SAM stability threshold is the positive solution of , namely . Since , .
Therefore, whenever , we have and . Thus the memorizing interpolant is locally stable under GD but locally unstable under SAM. Perturbations in the top Hessian eigendirection decay geometrically under GD and grow geometrically under SAM.
Equivalently, this condition defines a nonempty low-norm stability window whenever the equation has solutions. On the low-r branch, this corresponds to an interval .
A.4 Full Tables, Grokking in Modular Arithmetic
We provide a table with all modular arithmetic results and three sharpness metrics, including a parameter-normalized variant to the maximum eigenvalue of the Hessian, and the sharpness metrics discussed in other works Han et al. [2025].
(a) 1-layer Transformer, add mod 113
| Condition | Grok | Grok epoch | Val. acc. | Speedup | Han RF | |||
|---|---|---|---|---|---|---|---|---|
| No reg | - | 0/5 | - | - | ||||
| WD | - | 5/5 | 1x | |||||
| SAM-only | 0.01 | 0/5 | - | - | ||||
| SAM-only | 0.05 | 0/5 | - | - | ||||
| SAM-only | 0.2 | 0/5 | - | - | ||||
| SAM-only | 0.3 | 0/5 | - | - | ||||
| SAM-only | 0.4 | 0/5 | - | - | ||||
| SAM-only | 0.5 | 0/5 | - | - | ||||
| SAM-only | 0.75 | 0/5 | - | - | ||||
| SAM-only | 1.25 | 0/5 | - | - | ||||
| SAM+WD | 0.01 | 5/5 | 1.202x | |||||
| SAM+WD | 0.05 | 5/5 | 1.813x | |||||
| SAM+WD | 0.2 | 5/5 | 2.752x | |||||
| SAM+WD | 0.3 | 5/5 | 2.856x | |||||
| SAM+WD | 0.4 | 5/5 | 2.099x | |||||
| SAM+WD | 0.5 | 5/5 | 2.93x | |||||
| SAM+WD | 0.75 | 5/5 | 3.205x | |||||
| SAM+WD | 1 | 5/5 | 3.378x | |||||
| SAM+WD | 1.25 | 5/5 | 2.301x |
(b) 1-layer Transformer, add mod 97
| Condition | Grok | Grok epoch | Val. acc. | Speedup | Han RF | |||
|---|---|---|---|---|---|---|---|---|
| No reg | - | 0/5 | - | - | ||||
| WD | - | 5/5 | 1x | |||||
| SAM-only | 0.01 | 0/5 | - | - | ||||
| SAM-only | 0.05 | 0/5 | - | - | ||||
| SAM-only | 0.2 | 0/5 | - | - | ||||
| SAM-only | 0.3 | 0/5 | - | - | ||||
| SAM-only | 0.4 | 0/5 | - | - | ||||
| SAM-only | 0.5 | 0/5 | - | - | ||||
| SAM-only | 0.75 | 0/5 | - | - | ||||
| SAM-only | 1.25 | 0/5 | - | - | ||||
| SAM+WD | 0.01 | 5/5 | 1.156x | |||||
| SAM+WD | 0.05 | 5/5 | 2.033x | |||||
| SAM+WD | 0.2 | 5/5 | 2.002x | |||||
| SAM+WD | 0.3 | 5/5 | 2.456x | |||||
| SAM+WD | 0.4 | 5/5 | 2.775x | |||||
| SAM+WD | 0.5 | 5/5 | 2.815x | |||||
| SAM+WD | 0.75 | 5/5 | 3.395x | |||||
| SAM+WD | 1 | 5/5 | 3.992x | |||||
| SAM+WD | 1.25 | 5/5 | 2.532x |
Table 2: Modular-addition results for 1-layer Transformers. Grokking and validation summaries use matched five-seed runs. Speedup is the median paired-seed SAM+WD speedup over WD. Han RF is the official Han et al. relative-flatness metric. Hessian columns use the previously computed three-seed Hessian-50 posthoc table matched by task, condition, and .
(c) 2-layer Transformer, add mod 113
| Condition | ρ | Grok | Grok epoch | Val. acc. | Speedup | Han RF ↓ | λ50max↓ | λ50max/||θ||2↓ |
|---|---|---|---|---|---|---|---|---|
| No reg | - | 0/5 | - | 0.311 ± 0.032 | - | 1.23e+04 ± 2.12e+04 | 7.04 ± 12.14 | 0.00107 ± 0.00184 |
| WD | - | 5/5 | 11266 ± 9705.0 | 0.876 ± 0.174 | 1x | 6.44e+06 ± 1.99e+06 | 5.91e+04 ± 2.06e+04 | 83.45 ± 63.48 |
| SAM-only | 0.01 | 0/5 | - | 0.41 ± 0.171 | - | 3.877 ± 2.619 | 0.00403 ± 0.00223 | 7.42e-07 ± 4.63e-07 |
| SAM-only | 0.05 | 0/5 | - | 0.44 ± 0.177 | - | 900.7 ± 1558.1 | 0.48 ± 0.826 | 7.57e-05 ± 1.30e-04 |
| SAM-only | 0.2 | 0/5 | - | 0.39 ± 0.119 | - | 2.052 ± 1.191 | 0.00105 ± 6.43e-04 | 1.75e-07 ± 1.05e-07 |
| SAM-only | 0.3 | 0/5 | - | 0.383 ± 0.101 | - | 13.66 ± 20.79 | 0.00301 ± 0.00365 | 4.87e-07 ± 5.87e-07 |
| SAM-only | 0.4 | 0/5 | - | 0.32 ± 0.029 | - | 1.164 ± 1.013 | 4.32e-04 ± 3.01e-04 | 6.39e-08 ± 4.44e-08 |
| SAM-only | 0.5 | 0/5 | - | 0.342 ± 0.0796 | - | 3.86 ± 4.179 | 8.53e-04 ± 6.96e-04 | 1.17e-07 ± 9.60e-08 |
| SAM-only | 0.75 | 0/5 | - | 0.328 ± 0.0572 | - | 0.431 ± 0.586 | 1.48e-04 ± 1.58e-04 | 1.82e-08 ± 1.87e-08 |
| SAM-only | 1.25 | 0/5 | - | 0.301 ± 0.00727 | - | 75.43 ± 130.5 | 0.121 ± 0.21 | 9.81e-06 ± 1.70e-05 |
| SAM+WD | 0.01 | 4/5 | 9196.7 ± 1299.2 | 0.995 ± 0.0116 | 1.225x | 4.23e+04 ± 4.08e+04 | 275.3 ± 342.9 | 0.439 ± 0.547 |
| SAM+WD | 0.05 | 5/5 | 7883.8 ± 2164.2 | 1 ± 2.90e-04 | 1.429x | 5413.5 ± 4751.9 | 15.15 ± 9.783 | 0.0267 ± 0.022 |
| SAM+WD | 0.2 | 5/5 | 5616.2 ± 1133.3 | 1 ± 1.23e-04 | 2.006x | 1675.8 ± 814.8 | 5.077 ± 0.31 | 0.00841 ± 8.15e-04 |
| SAM+WD | 0.3 | 5/5 | 5870.8 ± 1226.2 | 1 ± 3.68e-04 | 1.919x | 938.9 ± 172.3 | 2.184 ± 0.806 | 0.00339 ± 0.00147 |
| SAM+WD | 0.4 | 5/5 | 8241.4 ± 569.7 | 1 ± 4.11e-04 | 1.367x | 1076.5 ± 33.77 | 2.144 ± 0.407 | 0.00313 ± 6.04e-04 |
| SAM+WD | 0.5 | 5/5 | 6523.5 ± 904.6 | 0.999 ± 3.79e-04 | 1.727x | 4229.5 ± 6177.6 | 6.003 ± 7.931 | 0.00845 ± 0.0109 |
| SAM+WD | 0.75 | 5/5 | 6190.1 ± 894.6 | 0.999 ± 1.87e-04 | 1.82x | 798.0 ± 104.0 | 1.515 ± 0.281 | 0.00215 ± 4.90e-04 |
| SAM+WD | 1 | 5/5 | 9219.3 ± 860.7 | 1 ± 3.26e-04 | 1.222x | 4000.0 ± 3268.2 | 7.145 ± 6.088 | 0.00972 ± 0.00934 |
| SAM+WD | 1.25 | 5/5 | 7525.7 ± 1732.6 | 0.95 ± 0.11 | 1.497x | 1.21e+04 ± 8775.4 | 6.843 ± 3.611 | 0.00787 ± 0.00576 |
(d) 2-layer Transformer, add mod 97
| Condition | ρ | Grok | Grok epoch | Val. acc. | Speedup | Han RF ↓ | λ50max↓ | λ50max/||θ||2↓ |
|---|---|---|---|---|---|---|---|---|
| No reg | - | 0/5 | - | 0.345 ± 0.0369 | - | 1669.3 ± 1582.0 | 4.054 ± 3.549 | 7.02e-04 ± 6.27e-04 |
| WD | - | 4/5 | 6770 ± 1526.4 | 0.821 ± 0.133 | 1x | 3.84e+06 ± 3.58e+06 | 2.33e+04 ± 3.02e+04 | 20.06 ± 21.73 |
| SAM-only | 0.01 | 0/5 | - | 0.311 ± 0.0102 | - | 213.0 ± 304.3 | 0.339 ± 0.402 | 6.14e-05 ± 7.38e-05 |
| SAM-only | 0.05 | 0/5 | - | 0.329 ± 0.0212 | - | 6.473 ± 4.836 | 0.00978 ± 0.00722 | 2.01e-06 ± 1.67e-06 |
| SAM-only | 0.2 | 0/5 | - | 0.324 ± 0.0394 | - | 5.838 ± 6.646 | 0.00533 ± 0.00553 | 9.62e-07 ± 1.04e-06 |
| SAM-only | 0.3 | 0/5 | - | 0.303 ± 0.0106 | - | 0.402 ± 0.396 | 1.92e-04 ± 1.51e-04 | 3.16e-08 ± 2.38e-08 |
| SAM-only | 0.4 | 0/5 | - | 0.302 ± 0.0096 | - | 0.3 ± 0.384 | 2.72e-04 ± 2.49e-04 | 4.28e-08 ± 3.83e-08 |
| SAM-only | 0.5 | 0/5 | - | 0.298 ± 0.00274 | - | 0.885 ± 1.209 | 0.00102 ± 0.00152 | 1.51e-07 ± 2.29e-07 |
| SAM-only | 0.75 | 0/5 | - | 0.296 ± 0.0018 | - | 0.309 ± 0.43 | 1.25e-04 ± 1.59e-04 | 1.58e-08 ± 1.98e-08 |
| SAM-only | 1.25 | 0/5 | - | 0.297 ± 0.00145 | - | 1.696 ± 2.799 | 8.37e-04 ± 0.00122 | 7.40e-08 ± 1.07e-07 |
| SAM+WD | 0.01 | 5/5 | 5572.0 ± 1413.1 | 0.993 ± 0.0158 | 1.215x | 1.33e+04 ± 6963.0 | 189.2 ± 211.1 | 0.166 ± 0.12 |
| SAM+WD | 0.05 | 5/5 | 7497.2 ± 2891.2 | 0.999 ± 1.98e-04 | 0.903x | 5149.1 ± 3155.8 | 15.29 ± 7.406 | 0.0286 ± 0.0154 |
| SAM+WD | 0.2 | 5/5 | 5416.0 ± 1068.8 | 1 ± 3.04e-04 | 1.25x | 3712.1 ± 4173.1 | 14.14 ± 17.51 | 0.0236 ± 0.0287 |
| SAM+WD | 0.3 | 5/5 | 4856.5 ± 526.9 | 1 ± 3.72e-04 | 1.394x | 1070.3 ± 352.8 | 2.694 ± 0.732 | 0.00421 ± 0.00107 |
| SAM+WD | 0.4 | 5/5 | 5171.9 ± 1428.9 | 1 ± 1.73e-04 | 1.309x | 2177.1 ± 2167.2 | 7.391 ± 7.756 | 0.0109 ± 0.0108 |
| SAM+WD | 0.5 | 5/5 | 4255.2 ± 918.8 | 1 ± 2.63e-04 | 1.591x | 2191.7 ± 1788.9 | 5.266 ± 3.768 | 0.00745 ± 0.00445 |
| SAM+WD | 0.75 | 5/5 | 4825.4 ± 708.8 | 0.999 ± 3.62e-04 | 1.403x | 5992.0 ± 7701.6 | 11.68 ± 15.58 | 0.02 ± 0.0282 |
| SAM+WD | 1 | 5/5 | 4633.8 ± 1497.1 | 1 ± 4.75e-04 | 1.461x | 1294.1 ± 838.0 | 2.02 ± 1.294 | 0.00265 ± 0.00155 |
| SAM+WD | 1.25 | 5/5 | 5003.7 ± 1238.2 | 1 ± 4.07e-04 | 1.353x | 8109.4 ± 569.8 | 19.08 ± 3.056 | 0.029 ± 0.00289 |
Table 3: Modular-addition results for 2-layer Transformers. Grokking and validation summaries use matched five-seed runs. Speedup is the median paired-seed SAM+WD speedup over WD. Han RF is the official Han et al. relative-flatness metric. Hessian columns use the previously computed three-seed Hessian-50 posthoc table matched by task, condition, and .
A.5 Computational Costs
We report computational cost in GPU-hours, computed as the sum of single-GPU wall-clock time across runs. All training runs used a single GPU; we do not normalize for GPU model, since experiments were scheduled opportunistically across A10, A30, A100 devices. SAM-based methods, including SAM and SAM+WD, require two gradient evaluations per optimizer step, requiring more time. However, the required time varies largely across conditions and tasks, so we report empirical run times rather than multiplying baseline costs by a fixed factor.
| Experiment | Runs | Seeds | Wall time / run | Total GPU-hours |
|---|---|---|---|---|
| Modular Arithmetic | 400 | 5 | 0.2–41 min | 73 |
| CIFAR-10 | 96 | 3 | 0.9–2.0 h | 113 |
| SST-5 | 168 | 3 | 0.35–3.82 h | 290 |
| MNIST | 110 | 3 | - | 2 |
| IMDb | 261 | 3 | 0.5–1.2 h | 113 |
Table 4: We report the number of total runs, seeds, wall-time per run, and total GPU-hours to recreate all results on each task independently.
Computing sharpness measurements adds additional costs beyond training. Han-style final-layer flatness metrics are inexpensive relative to training, while Hessian maximum-eigenvalue estimates require repeated Hessian-vector products. For the modular-arithmetic tables, final values were computed with 50 iterations of the Lanczos method to the empirical training-loss Hessian with respect to all trainable parameters at the final checkpoint; this was run post hoc and is therefore not included in the training-time estimates in Table 4.