{
  "File Number": "1074",
  "Title": "When Do Flat Minima Optimizers Work?",
  "5 Limitations and Future Work": "First, some of the fixed, shared hyperparameter values we used from previous works may harm the effect of flat optimizers. The ideal experimental design includes tuning all hyperparameters independently for the non-flat optimizer, SWA, SAM, and WASAM. However, this forces the number of required runs to grow exponentially in unique hyperparameters and quickly renders this benchmark infeasible.\nSecond, despite our best efforts to evaluate the optimizers on a broad range of benchmark tasks, there are still plenty of unexplored domains; especially some of which are known to be sensitive to careful optimization. For example, bi-level optimization problems [24] are common in generative modeling [31, 42], deep reinforcement learning [60, 44], meta-learning [81, 52], or causal machine learning [53, 54]. We are unaware of an investigation of flat minima optimization for such problems.\nThird, in general, we believe fruitful directions of research include (a) optimizers that explicitly find basins where training loss flatness more directly corresponds to higher hold-out accuracy, (b) post-processing methods for existing optimization runs to move into flatter regions of these basins [2], (c) loss functions whose contours more tightly align with accuracy contours, (d) the study of flat-minima hyperparameter interactions (e.g., learning rate and neighborhood radius in SAM) (see Appendices A.5 and A.6 for first results), (e) analyses of flat minima optimization on convergence speed [51].\nOur benchmark results point to which tasks would most benefit from improving these future work directions: graph learning tasks would benefit from improvements in (a), as SAM is never among the best-performing method, and language tasks would benefit if (b) is improved, as SWA is never among the best performing method).",
  "Reviewer Comment": "Reviewer_3: Strengths\nThe paper tackles a significant and practically-relevant problem supported by a fair amount of experiments conducted across various tasks and domains. There is a need for comparative studies of flat-minima-seeking algorithms.\nOverall, the paper is well-written and easy to follow.\nWeaknesses\n(W1) Robustness to various settings:\nIn Section 3, it is unclear whether the findings in Figure 2 can be generalized to other settings. For instance, is the result robust to varying hyperparameters (e.g. SAM's radius) or even to different random seeds? Considering that this is an analysis paper, the robustness of the findings should be highlighted.\nAlthough the authors stated the scope of the work in Section 2.4, it is questionable whether the results would hold under variants of SWA and SAM (e.g., Adaptive SAM, Fast Geometric Ensemble).\n(W2) Credibility of linear interpolation analysis:\nRegarding observations 3 and 4 in Section 3.1, one may consider asymmetric valleys [1]. While SAM solutions are closer to the sharper basin in certain directions, it is not guaranteed to be true in all directions.\nI cannot find a 2D plot in the Appendix, which was mentioned in line 168.\nIt remains unclear how SAM+SWA solutions escape the saddle point in Fig 3.\n(W3) Novelty of proposed algorithm:\nThe proposed way of mixing SWA and SAM outperforms baselines in half of the proposed cases. In this regard, it lacks novelty.\nFurther, the motivation, i.e., observation 4, needs to be enhanced in line with the previous comment (W2). For example, I wonder if dominant Hessian eigenvalue analysis would hold under different settings since it is well-known that such analysis is not translation invariant w.r.t. neural network parameters.\n(W4) Lack of interpretation:\nWhile the findings in Section 4.4 are interesting, it is mostly devoted to when SWA and SAM fail, not why. In order to conduct future research based on the paper’s observations, well-reasoned interpretations or hypotheses are crucial.\nAs in A.2, a study concerning global flatness and well-connectedness or other distance metrics (e.g., CKA) would be worthwhile [2].\nReferences\n[1] He, Haowei, Gao Huang, and Yang Yuan. \"Asymmetric valleys: Beyond sharp and flat local minima.\" Advances in neural information processing systems 32 (2019).\n[2] Yang, Yaoqing, et al. \"Taxonomizing local versus global structure in neural network loss landscapes.\" Advances in Neural Information Processing Systems 34 (2021): 18722-18733.\n(Post-rebuttal) I have updated my score to 5.\nQuestions:\nDo SWA solutions and non-flat baseline solutions share optimization trajectories? If so, observation 1 seems to be a naïve consequence.\nIn Section 3, is Adam optimizer used for SWA and SAM in GIN/Code2 task? Or, only for non-flat solutions?\nRegarding line 296, I cannot find an explanation in the Appendix as to why SWA and transformers do not work well together.\nLimitations:\nThe paper provided limitations along with future research directions in Section 5.\nEthics Flag: No\nSoundness: 2 fair\nPresentation: 3 good\nContribution: 2 fair\n\nReviewer_4: Strengths:\nThis paper provides lots of experiment results in various tasks to analyze SAM and SWA, which help us better understand them.\nThe proposed method is very clear and simple to reproduce.\nSWA+SAM can achieve better performance in some tasks.\nThe figures and writing are very easy to understand.\nWeakness:\nAlthough the paper provides lots of experiment results, some important experiments are not included in this paper. For example, some related work illustrate that SAM can achieve a huge improvement in ViT training on ImageNet (5% improvement). I think this is very important for people to better understand the relationship between SAM and SWA.\nSome comparison with current state of the art methods, such as GSAM.\nThe accuracy of SAM+SWA is not better than vanilla SAM in some experiments. In addition, in some tasks the performance are very close. I think that will also limit the contribution of this paper.\nAbout the novelty of this paper. Although the paper focus on a very important problem, but the proposed method try to combine current two methods, SAM and SWA, which will also weak the contribution of this paper.\nQuestions:\nIn the experiments, whether the distributed setting is used. The main reason is that we find this setting is very important for SAM, which may also affect the analysis of SAM.\nWe know that data augmentation can improve the generalization of neural networks. When using data augmentation, the improvement of SAM will be reduced. What is the relationship between data augmentation, SAM, and SWA.\nLimitations:\nThe paper provides some experiment analysis to illustrate the properties of SAM and SWA.\nThe contribution of this paper. Combining SAM and SWA is not novel for me.\nThe performance of SWA+SAM is not very great for me. In some tasks, the performance are very close between SAM+SWA and SAM/SWA and in some experiments SAM+SWA will hurt the performance.\nThe experiment results of ViT training on ImageNet. I think this experiment is very important for SAM since SAM can achieve about 5% improvement on ImageNet.\nEthics Flag: No\nSoundness: 3 good\nPresentation: 3 good\nContribution: 3 good\n\nReviewer_5: S = strength, W = weakness, Q = question.\nS1. The authors perform a detailed benchmark study that was missing from the literature. It is interesting to see that SAM and SWA are in fact quite complimentary, without one method clearly dominating the other.\nS2. The benchmarks considered by the authors are quite diverse, including multiple domains. Moreover, the results differ between the different domains, showing the importance of a diverse benchmark.\nS3. The combination SWA+SAM seems to be quite useful for practitioners potentially, as it works consistently well across a broad set of benchmarks, while SWA and SAM are somewhat less consistent.\nS3. The authors perform loss surface analysis experiments to provide intuition behind the results.\nW1. In section 3.1 it is not clear how exactly the solutions\nθ\nN\nF\nare obtained for each optimizer. My guess is that for SWA the authors used the same optimization trajectory but without averaging to obtain\nθ\nN\nF\n, while for SAM they used an independent run? In this case, the relation between\n(\nθ\nN\nF\n,\nθ\nS\nW\nA\n)\nand the relation between\n(\nθ\nN\nF\n,\nθ\nS\nA\nM\n)\nwill be quite different. In particular, I would expect the distance spanned by the horizontal access in Figure 2 to be much larger for SAM compared to SWA, making the interpretation of the plots more nuanced.\nW2. In lines 226-227 the authors mention that for SWA they simply average the iterates of the baseline optimization run, without modifying the learning rate schedule. While this is a valid approach, the authors of SWA emphasize the importance of using a non-standard learning rate schedule (see e.g. the official blogpost). The deviation from the standard SWA recipy makes the benchmarking results a bit harder to interpret.\nQuestions:\nQ1. Could you please comment on the base optimizer used in each data domain (Vision, NLP, GRL)? Could the SWA poor performance on NLP tasks compared to Vision be explained by the different choice of base optimizer?\nQ2. Could you pleas comment on W1? How is\nθ\nN\nF\ncomputed for both SWA and SAM? What is\n|\nθ\nN\nF\n−\nθ\nS\nW\nA\n|\nand\n|\nθ\nN\nF\n−\nθ\nS\nA\nM\n|\nin Fig. 2?\nQ3. Could you pleas comment on W3? Why did you choose not to use a cyclical or constant learning rate schedule for SWA? Would it be possible to evaluate SWA with a constant learning rate schedule after epoch\nE\nfor a subset of your benchmarks to understand whether the choice of the learning rate schedule affected your results?\nLimitations:\nThe authors adequately discuss the limitations of their work.\nEthics Flag: No\nSoundness: 3 good\nPresentation: 4 excellent\nContribution: 3 good\n\nReviewer_6: Strengths:\nThe analysis of the minima found by SAM and SWA has not been studied earlier. The observations are quite interesting and valuable to the community.\nThe authors perform a detailed comparison of SAM and SWA across a wide range of benchmarks. All the results are reported with error bars.\nOverall, the paper is well written, with novel observations clearly stated and explained with supportive evidence.\nWeaknesses:\nThis work has not studied the role of the base optimizer. The authors have compared SAM and SWA across multiple tasks and architectures. However, some methods use SGD, while others use Adam as the base optimizer. The loss landscape and generalization have been compared with SGD and Adam [1]. The comparison of SGD vs. Adam for the same task with SWA and SAM, respectively, would help disentangle the impact of the base optimizer.\nRegarding Observation 3 (L166): \"We visualize 2D plots moving along random directions (not shown here due to space)\". This plot must be added to the Appendix along with the observations. Otherwise, the saddle point hypothesis is not backed up with evidence. Additionally, it would be good to plot the Eigen Spectral Density [2] and show the presence of significant negative eigenvalues, which can confirm the presence of saddle point.\n[1] Zhou, P., Feng, J., Ma, C., Xiong, C., Hoi, S. C. H., et al. Towards theoretically understanding why sgd generalizes better than adam in deep learning. Advances in Neural Information Processing Systems, 33:21285–21296, 2020.\n[2] Ghorbani, Behrooz, Shankar Krishnan, and Ying Xiao. \"An investigation into neural net optimization via hessian eigenvalue density.\" International Conference on Machine Learning. PMLR, 2019.\nQuestions:\nIncluding observations relating to the robustness of the optimizer to its hyperparameters would also add practical value to the work. The role of the hyperparameters of the flat-optimizer in reaching certain minima can also be studied. For example, Does a large\nρ\nlead to a completely different basin than a small\nρ\n?\nIt would be clearer if the authors mentioned the tasks/models where a pretrained model is used. For example, it is mentioned in the Appendix that the CIFAR-10 ViT results used a pretrained ImageNet ViT. The characteristics of the flat optimizers might be very different if a model is trained from scratch with the flat optimizer instead of being finetuned with the flat optimizer.\nIt is mentioned that one of the reasons why flat optimizers fail is because the train and test minimizers are not correlated. Can this hypothesis be more thoroughly evaluated by plotting the linear interpolation plots on an OOD test set?. For example, for the CIFAR-10 dataset, one could evaluate on CIFAR-10.1/ CINIC-10 dataset.\nQuestion 3 (d) of the checklist has been answered: \"Yes, See Appendix.\" But the details regarding the compute are not available in the Appendix.\nWhy does Algorithm 1 returns\nθ\nS\nW\nA\n+\nS\nA\nM\n? Should it not return\nθ\nS\nW\nA\nLimitations:\nThe limitations of the work have been described in detail.\nEthics Flag: No\nSoundness: 4 excellent\nPresentation: 4 excellent\nContribution: 4 excellent",
  "abstractText": "Recently, flat-minima optimizers, which seek to find parameters in low-loss neighborhoods, have been shown to improve a neural network’s generalization performance over stochastic and adaptive gradient-based optimizers. Two methods have received significant attention due to their scalability: 1. Stochastic Weight Averaging (SWA), and 2. Sharpness-Aware Minimization (SAM). However, there has been limited investigation into their properties and no systematic benchmarking of them across different domains. We fill this gap here by comparing the loss surfaces of the models trained with each method and through broad benchmarking across computer vision, natural language processing, and graph representation learning tasks. We discover several surprising findings from these results, which we hope will help researchers further improve deep learning optimizers, and practitioners identify the right optimizer for their problem.",
  "1 Introduction": "Stochastic gradient descent (SGD) methods are central to neural network optimization [6]. Recently, one class of algorithms has focused on biasing SGD methods towards so-called ‘flat’ minima, which are located in large weight space regions with very similar low loss values [43]. Theoretical and empirical studies [21, 77, 9, 55, 49, 5, 12] postulate that such flatter regions generalize better than sharper minima, e.g., due to the flat minimizer’s robustness against loss function shifts between train and test data, as illustrated in Fig. 1. Two popular flat-minima optimization approaches are: 1. Stochastic Weight Averaging (SWA) [48], and 2. Sharpness-Aware Minimization (SAM) [22].\nWhile both strategies aim to find flatter minima, they operate much differently. On the one hand, SWA is based on the intuition that, near a flat minimum, gradients are smaller, leaving many iterates in that flat region. Therefore, averaging iterates will produce a solution that is pulled towards these flatter regions, see Fig. 1, top. On the other hand, SAM minimizes the maximum loss around a neighborhood of the current iterate. This way, a region around the iterate is designed to have uniformly low loss; see Fig. 1, bottom. Crucially, SAM requires an additional forward/backward pass for each parameter update, making it more expensive than SWA.\nDespite the successes [76, 3, 51, 12, 4] of SWA and SAM in some domains, we are unaware of a systematic comparison between them that would help practitioners to choose the right optimizer for their problem and researchers to develop better optimizers. The SWA [48] paper was published in 2018, and the SAM [22] paper in 2021; however, the SAM paper, and its most noticeable follow-ups [65, 12, 103], do not compare against SWA. Further, there is very limited overlap in\n∗Equal contribution, correspondence to {jean.kaddour,linqing.liu}.20@ucl.ac.uk\n36th Conference on Neural Information Processing Systems (NeurIPS 2022).\nterms of the model architecture and dataset used in the experiments among both papers, which are likely further confounded by other differences in the training procedures (e.g. data augmentations, hyper-parameters, etc.).\n<latexit sha1_base64=\"pYM132qgRhMHaU/a61ywLFbdrWg=\">AAAB7XicbVBNS8NAEJ3Ur1q/qh69LBbBU0mkqMeiF48V7Ae0oWy2m3btZhN2J0IJ/Q9ePCji1f/jzX/jts1BWx8MPN6bYWZekEhh0HW/ncLa+sbmVnG7tLO7t39QPjxqmTjVjDdZLGPdCajhUijeRIGSdxLNaRRI3g7GtzO//cS1EbF6wEnC/YgOlQgFo2ilVg9HHGm/XHGr7hxklXg5qUCORr/81RvELI24QiapMV3PTdDPqEbBJJ+WeqnhCWVjOuRdSxWNuPGz+bVTcmaVAQljbUshmau/JzIaGTOJAtsZURyZZW8m/ud1Uwyv/UyoJEWu2GJRmEqCMZm9TgZCc4ZyYgllWthbCRtRTRnagEo2BG/55VXSuqh6l9Xafa1Sv8njKMIJnMI5eHAFdbiDBjSBwSM8wyu8ObHz4rw7H4vWgpPPHMMfOJ8/puWPMQ==</latexit>\n✓\nTrain Test\n×\nSAM\n<latexit sha1_base64=\"KIBUPXdFc9jbwGmlyaMi3aNFjHE=\">AAAB8nicbVDLSgMxFL1TX7W+qi7dBIvgqsxIUZdFNy5cVLAPmA4lk2ba0EwyJBmhDP0MNy4UcevXuPNvzLSz0NYDgcM595JzT5hwpo3rfjultfWNza3ydmVnd2//oHp41NEyVYS2ieRS9UKsKWeCtg0znPYSRXEcctoNJ7e5332iSjMpHs00oUGMR4JFjGBjJb8fYzMmmGf3s0G15tbdOdAq8QpSgwKtQfWrP5QkjakwhGOtfc9NTJBhZRjhdFbpp5ommEzwiPqWChxTHWTzyDN0ZpUhiqSyTxg0V39vZDjWehqHdjKPqJe9XPzP81MTXQcZE0lqqCCLj6KUIyNRfj8aMkWJ4VNLMFHMZkVkjBUmxrZUsSV4yyevks5F3busNx4ateZNUUcZTuAUzsGDK2jCHbSgDQQkPMMrvDnGeXHenY/FaMkpdo7hD5zPH4PzkWs=</latexit>\nL\n+\nSWA\n<latexit sha1_base64=\"KIBUPXdFc9jbwGmlyaMi3aNFjHE=\">AAAB8nicbVDLSgMxFL1TX7W+qi7dBIvgqsxIUZdFNy5cVLAPmA4lk2ba0EwyJBmhDP0MNy4UcevXuPNvzLSz0NYDgcM595JzT5hwpo3rfjultfWNza3ydmVnd2//oHp41NEyVYS2ieRS9UKsKWeCtg0znPYSRXEcctoNJ7e5332iSjMpHs00oUGMR4JFjGBjJb8fYzMmmGf3s0G15tbdOdAq8QpSgwKtQfWrP5QkjakwhGOtfc9NTJBhZRjhdFbpp5ommEzwiPqWChxTHWTzyDN0ZpUhiqSyTxg0V39vZDjWehqHdjKPqJe9XPzP81MTXQcZE0lqqCCLj6KUIyNRfj8aMkWJ4VNLMFHMZkVkjBUmxrZUsSV4yyevks5F3busNx4ateZNUUcZTuAUzsGDK2jCHbSgDQQkPMMrvDnGeXHenY/FaMkpdo7hD5zPH4PzkWs=</latexit>\nL\nContributions",
  "2.1 Stochastic Gradient Descent (SGD)": "The classic optimization framework of machine learning is empirical risk minimization\nL (θ) = 1 N N∑ i=1 ℓ (xi;θ) (1)\nwhere θ ∈ Rd is a vector of parameters, {x1, . . . ,xN} is a training set of inputs xn ∈ RD, and ℓ(x;θ) is a loss function quantifying the performance of parameters θ on x. SGD samples a minibatch S ⊂ {1, . . . , N} of size |S| ≪ N from the training set and updates the parameters through\nθSGDt+1 = θt − ηg (θt) , where g (θ) = 1 |B| ∑ i∈B ∇ℓ (θ;xi) , (2)\nfor a length specified by η, the learning rate.",
  "2.2 Stochastic Weight Averaging (SWA)": "The idea of averaging weights dates back to accelerating the convergence speed of SGD [78, 51]. SWA’s motivation is based on the following observation about SGD’s behavior when training neural networks: it often traverses regions of the weight space that correspond to high-performing models but rarely reaches the central points of this optimal set. Averaging the parameter values over iterations moves the solution closer to the centroid of this space of points.\nThe SWA update rule is the cumulative moving average\nθSWAt+1 ← θSWAt · l + θSGDt\nl + 1 , (3)\nAlgorithm 1 Stochastic Weight Averaging [48] Input: Loss function L, training budget in number of iterations b, training dataset D := ∪ni=1{xi}, mini-batch size |B|, averaging start epoch E, averaging frequency ν, (scheduled) learning rate η, initial weights θ0. for k ← 1, . . . , b do\nSample a mini-batch B from D Compute gradient g ← ∇L (θt) Update parameters θt+1 ← θt − ηg if k ≥ E and mod(k, ν) = 0 then θSWAt+1 = ( θSWAt · l + θSWAt+1 ) / (l + 1)\nend if end for return θSWA\nAlgorithm 2 Sharpness-Aware Minimization [22] Input: Loss function L, training budget in number of iterations b, training dataset D := ∪ni=1{xi}, mini-batch size |B|, neighborhood radius ρ, (scheduled) learning rate η, initial weights θ0. for k ← 1, . . . , b do\nSample a mini-batch B from D Compute worst-case perturbation\nϵ̂← ρ ∇L(θ)∥∇L(θ)∥2 Compute gradient g ← ∇L ( θSAMt +ϵ̂ ) Update parameters θSAMt+1 ← θSAMt − ηg\nend for return θSAM\nwhere l is the number of distinct parameters averaged so far and t is the SGD iteration number.2\nSWA has two hyper-parameters: the update frequency ν and starting epoch E. When using a constant learning rate, Izmailov et al. [48] suggests updating the parameters once after each epoch, i.e., ν ≈ N|B| , and starting at E ≈ 0.75T , where T is the training budget required to train the model until convergence with conventional SGD training.\nHe et al. [39] argue that SWA may always improve generalization, regardless of the loss function’s geometry. Kaddour [51] show that averaging a specific range of weights can speed up training convergence. Cha et al. [8] argue that tuning ν and E carefully is necessary to make it work effectively in domain generalization (DG) tasks. Besides DG tasks, a list of tuned hyper-parameters based on a fair model selection procedure across different architectures and tasks has been missing in the literature. To the best of our knowledge, Cha et al. [8] is the only study that compares SWA and SAM over the same experiments, but it focuses on domain generalization tasks which we, therefore, leave out in this work.",
  "2.3 Sharpness-Aware Minimization (SAM)": "While SWA is implicitly biased towards flat minima, SAM explicitly approximates the flatness around parameters θ to guide the parameter update. It first computes the worst-case perturbation ϵ that maximizes the loss within a given neighborhood ρ, then minimizes the loss w.r.t. the perturbed weights θ + ϵ. Formally, SAM finds θ by solving the minimax problem:\nmin θ max ||ϵ||2≤ρ\nL(θ + ϵ), (4)\nwhere ρ ≥ 0 is a hyperparameter. To find the worst-case perturbation ϵ∗ efficiently in practice, Foret et al. [22] approximates Eq. (4) via a first-order Taylor expansion of L(θ + ϵ) w.r.t. ϵ around 0, obtaining\nϵ∗ ≈ argmax ∥ϵ∥2≤ρ ϵ⊤∇θL(θ) ≈ ρ · ∇θL(θ) ∥∇θL(θ)∥︸ ︷︷ ︸\n=:ϵ̂\n. (5)\nIn words, ϵ̂ is simply the scaled gradient of the loss function w.r.t to the current parameters θ. Given ϵ̂, the altered gradient used to update the current θt (in place of g(θt)) is\n∇θ max ||ϵ||2≤ρ L(θ + ϵ) ≈ ∇θL(θ)|θ+ϵ̂.\nDue to Eq. (5), SAM’s computational overhead consists of an additional forward and backward pass per parameter update step compared to SWA and non-flat optimizers.\n2SWA parameters are constant between averaging steps.\nSAM’s performance strongly depends on the neighborhood radius ρ. For example, Chen et al. [12], Wu et al. [93] show that ρ should be set to values outside the originally considered ranges by Foret et al. [22]. Analogously to Sec. 2.2, this lack of coherence among hyper-parameter tuning protocols in the SAM literature makes it tricky to determine SAM’s comparative effectiveness.",
  "2.4 Other Flat-Minima Optimizers": "There are several extensions of SWA [36, 8] and SAM [65, 103, 101]. For simplicity, we do not consider them in this work. Besides SWA and SAM, other flat-minima optimizers include e.g., [9, 84]. However, due to their computational cost and/or lack of performance gains, we do not include them in this work. Chaudhari et al. [9] requires [5, 20] forward and backward passes per parameter update. Sankar et al. [84] similarly requires [5, 10] forward and backward passes to estimate the Hessian trace and 6 of 7 experiments yield minimal improvement of ≤ 0.27%, see Table 1 in Sankar et al. [84]. In contrast, SWA and SAM have been shown to increase performance by multiple percentage points in some cases [8, 12] while requiring fewer computational resources.",
  "3 How do minima found by SWA and SAM differ?": "In this section, we investigate SWA and SAM solutions in two prototypical deep learning tasks, where these optimizers improve over the baseline. Our goal is to understand better their geometric properties (instead of their generalization performance, which is the focus of Sec. 4).\nFirst, we investigate the behavior of the loss landscape along the line between non-flat and flat solutions (Sec. 3.1). Previous studies successfully used such linear interpolations to gain novel insights, e.g., for training dynamics [32, 25], regularization [69, 28], and network pruning [26]. Second, motivated by findings in Sec. 3.1, we average SAM iterates and visualize interpolations between averaged and non-averaged solutions (Sec. 3.2). Interestingly, the averaged SAM solution is less susceptible to asymmetric directions. Third, we compare quantitative measurements of all solutions’ flatnesses (Sec. 3.3). Here, we compute dominant Hessian eigenvalues, as commonly used in the flat minima literature [9, 98, 12, 22]. Lastly, in Appendix A.1, we further compute CKA [61] and cosine similarities between SWA/SAM’s network output logits.\nWe choose the following two disparate learning settings: (i) a well-known image classification task, widely used for evaluation in flat-minima optimizer papers, and (ii) a novel, challenging Python code summarization task, on which state-of-the-art models achieve only around 16% F1 score on the test set (which is higher than its commonly achieved accuracy on the more challenging training set), and that has not been explored yet in the flat-minima literature. Specifically, for (i), we investigate the loss/accuracy surfaces of a WideResNet28-10 [99] model on CIFAR-100 [63] (baseline non-flat optimizer: SGD with momentum (SGD-M)) [83]. For (ii), we use the theoretically-grounded Graph Isomorphism Network [95] model on OGB-Code2 [45] (baseline optimizer: Adam [56]).\nAll optimizers start from the same initialization. We denote the minimizer produced by the non-flat methods (SGD-M and Adam) by θNF and the flat ones by θSWA and θSAM.",
  "3.1 What is between non-flat and flat solutions?": "We start by comparing the similarity of flat and non-flat minimizers through linear interpolations. This analysis allows us to understand if they are in the same basin and how close they are to a region of sharply-increasing loss, where we expect loss/accuracy to differ widely between train and test. Further, for each of our four observations, we recommend a future work direction.\nTo linearly interpolate between two sets of parameters θ and θ′, we parameterize the line connecting these two by choosing a scalar parameter α and defining the weighted average θ(α) = (1−α)θ+αθ′. If there exists no high-loss barrier between two networks θ,θ′ along the linear interpolation, we say that they are located in the same basin, i.e., {θ,θ′} ∈ Ω. [75, 102]. A basin is an area in the parameter space where the loss function has relatively low values. Due to NN non-linearities, the linear combination of the weights of two accurate models does not necessarily define an accurate model. Hence, we generally expect high-loss barriers along the linear interpolation path.\nWhile there are alternative distance measures that could be used to compare two networks, they typically either (a) do not offer clear interpretations, as pointed out by Frankle et al. [26], or (b) yield\ntrivial network connectivity results, such as non-linear low-loss paths, which can be found for any two network minimizers [20, 27, 33, 23].\nObs. 1: {θSWA,θNF} ∈ ΩNF. θSWA and θNF are in the same basin, as can be seen in Figures 2a and 2e. Additionally, θNF is near the periphery of a sharp increase in loss, as can be seen when moving in the direction from θSWA to θNF (i.e., α > 1). Conversely, θSWA finds flat regions that change slowly in the loss. This bias of SWA to flatter loss beneficially transfers to the accuracy landscape too: Figures 2b and 2f show the accuracy/F1 score rapidly dropping off approaching and beyond θNF. Interestingly, in Figures 2e and 2f, we see that for Code2, for α < 0, there exist solutions with even better training loss/accuracy but worse test loss/accuracy. However, θSWAGIN is close to the test accuracy maximizer along this interpolation. Future work may inspect why the cross entropy loss function used for GIN/Code2 seems less well correlated with its accuracy compared to WRN/CIFAR100.\nObs. 2: θSAM ∈ ΩSAM ̸= ΩNF. θSAM and θNF are not in the same basin: Figures 2c and 2g show that there is a high loss barrier between them, respectively. Figures 2d and 2h show that θSAM and even nearby points in parameter space achieve higher accuracies/F1 scores (i.e., generalize better) than θNF and points around it. This is an interesting result because we expect different basins to produce qualitatively different predictions, one of the motivations behind combining models, even if they exhibit different performances [46, 67]. Grewal & Bui [34] successfully combine models yielded by different optimizers, and we think future work should study ensembling SAM and non-SAM solutions.\nObs. 3: SAM finds a saddle point. Figure 2g shows θSAMGIN being located in a sharp training loss minimum whose loss is much higher than θNF. Yet, its test loss is slightly higher, and its F1 score is better. We visualize 2D plots moving along random directions (not shown here due to space) to confirm that θSAMGIN is a saddle point (Appendix A.2). A common pathology among curvature-based methods is that they attract saddle points [16]. Since SAM takes some form of curvature into account, too, we believe that future work should investigate SAM’s propensity to find saddle points and potential remedies.\nObs. 4: θSAM is closer to sharper directions than θSWA, as can be seen by Ltr/te(θSAM(0.1)) ≈ 2 · Ltr/te(θSAM(−0.1)), while Ltr/te(θSWA(0.1)) ≈ Ltr/te(θSWA(−0.1)), where L(·)tr/te refers to both training and test loss functions. A possible explanation for SAM being closer to sharp sides is that while it finds different basins than SGD/SWA by smoothing the loss surface (as illustrated in Fig. 1), within a local basin, it may oscillate around the minimizer similarly as SGD. One cause for this can be that ΩSAM’s hypersphere is larger than SAM’s radius ρ. If that holds, then given a small enough learning rate, we expect it to oscillate around θ∗ ∈ ΩSAM (the smaller the learning rate, the less likely it escapes the basin due to that stochasticity). Two possible remedies are: (1) adapt/schedule ρ, or (2) average SAM iterates to bias its solution towards the flatter side. (1) has been explored by [103, 101]. We try (2) in the next subsection. Future work may study SAM’s basin escape time, e.g., using convolutions [58] or stochastic differential equations [102].\n3.2 What happens if we average SAM iterates?\nBased on observation 4: “θSAM is closer to sharper directions than θSWA”, averaging SAM iterates may further improve generalization, referred to as Weight-Averaged Sharpness-Aware Minimization (WASAM). The reason is that while SAM finds better-performing basins, within the basin, its final iterate may still be near a side that increases sharply in the loss.\nStarting with the first of the two previously analyzed settings (WRN/CIFAR100), Figures 3a, and 3b show that θSWA+SAMWRN (marker: ⋆) achieves the lowest test loss and highest test accuracy, respectively. What stands out in comparison to the previous plots is θSAMWRN’s (×) proximity to sharp sides, surprisingly similar to θNFWRN (•) here and in Figures 2c and 2e. As we hoped, θSWA+SAMWRN is indeed closer to a flatter region, as can be seen by Ltr/te(θSWA+SAMWRN (−0.2)) ≈ Ltr/te(θSWA+SAMWRN (0.2)). In GIN/OGB-Code2, one unanticipated finding is that θSWA+SAMGIN escapes the (previously discussed) saddle point of θSAMGIN , appearing here as a maximum in Figure 3c. A likely reason is that SAM traversed nearby flatter regions before arriving at the saddle point, especially if it is a non-strict saddle. In terms of F1 score, Figure 3d shows that while θSWAGIN (+) and θ SAM GIN perform about equally well, the flatter region found by θSWA+SAMGIN improves over both.",
  "3.3 How “flat” are the found minima?": "We now quantify the flatnesses of all four optimizers over both tasks by computing the median of the dominant Hessian eigenvalue across all training set batches using the Power Iteration algorithm [74, 98]. This metric measures the worst-case loss landscape curvature. We choose this metric as it is very commonly used in the minima flatness literature, e.g., [9, 12, 22, 97, 18, 62, 85].\nTable 1 shows that SAM leads to flatter minima than SWA in both cases. Interestingly λmax(θNFWRN) ≈ 2.5 · λmax({θSWA,θSAM}), while λmax(θNFWRN) ≈ 5.75λmax(θSWA+SAMWRN ), indicating room for improvement in terms of flatness for both SWA and SAM. The relative differences are less dramatic for GIN/Code2, although surprisingly λmax(θNFGIN) ≈ λmax(θSWAGIN ). In sum, averaging SAM iterates leads to the flattest minima and best-performing minima in both cases (see Sec. 4).",
  "4 How do SWA and SAM perform on a broad set of experiments?": "As we point out in the introduction, there is almost no overlap and consistency regarding reported SWA and SAM results in the literature. This section addresses this gap. For example, Bahri et al. [4], Chen et al. [12] illustrate that the flat minima found by SAM improve generalization on Transformer [90] architectures compared to non-flat optimizers, but they do not compare against SWA. Hence, it is unclear if the computationally cheaper SWA may provide better or similar performance.\nWe compare flat minimizers SWA, SAM, and averaged SWA iterates (WASAM) over the non-flat minimizers across a range of different tasks in the domains of computer vision, natural language processing, and graph representation learning. We average all runs at least three times across random\nseeds (more often for experiments with higher variability, see details in Appendix B), and we report the corresponding standard error. We bold the best-performing approach and any approach whose average performance plus standard error overlaps it.\nHyper-parameters. For all architectures and datasets, we set hyperparameters shared by all methods (e.g., learning rate) mostly to values cited in prior work 3 As explained in Secs. 2.2 and 2.3, the effectiveness of flat-minima optimizers is highly sensitive to their additional hyperparameters. We select hyper-parameters using a grid search over a held-out validation set. Specifically, for SWA we follow Izmailov et al. [48] and hold the update frequency ν constant to once per epoch and tune the start time E ∈ {0.5T, 0.6T, 0.75T, 0.9T} (T is the number of baseline training epochs). Izmailov et al. [48] argue that a cyclical learning rate starting from E helps to encourage exploration of the basin. For the sake of simplicity, we average the iterates of the baseline directly but include even earlier starting times (i.e., 0.5T, 0.6T ). For SAM, we tune its neighborhood size ρ ∈ {0.01, 0.02, 0.05, 0.1, 0.2}, as in previous work [22, 4]. Appendix B contains the values of all hyper-parameters and additional training details (including public model checkpoints, hardware infrastructure, software libraries, etc.) to ensure full reproducibility alongside open-sourcing our code.",
  "4.1 Computer Vision": "Supervised Classification (SC). We evaluate the CNN architectures WideResNets [99] with 28 layers and width 10, and PyramidNet (PN) with 110 layers and widening factor 272 [38] as well as Vision Transformer (ViT) [19] and MLP-Mixer [87] on CIFAR{10, 100} [63]. All experiments use basic data augmentations: horizontal flip, padding by four pixels, random crop, and cutout [17].\nSelf-Supervised Learning (SSL). We consider the following methods on CIFAR10 and ImageNette4: Momentum Contrast [41], a Simple framework for Contrastive Learning (SimCLR) [10], Simple Siamese representation learning (SimSiam) [11], Barlow Twins [100], Bootstrap your own Latent (BYOL) [35], and Swapping Assignments between multiple Views of the same image (SwAV) [7]. All SSL methods use a ResNet-18 [40] as backbone network. To test the frozen representations, we use k-nearest-neighbor classification with a memory bank [94]. We choose k=200 and temperature τ = 0.1 to reweight similarities. Compared to learning a linear model on top of the representations, this evaluation procedure is more robust to hyperparameter changes [59].\n3Sometimes with minor modifications, e.g., adjusting per-device batch sizes to be compatible with our GPU infrastructure.\n4https://github.com/fastai/imagenette",
  "4.2 Natural Language Processing": "We consider the task of open domain question answering (ODQA) using a T5-based model FusionIn-Decoder (FiD) [47]. We evaluate FiD-base on the test sets of Natural Questions (NQ) [64] and TriviaQA [50]. We also consider natural language understanding tasks included in the GLUE benchmark [91], which cover acceptability, sentiment, paraphrase, similarity, and inference. We fine-tune RoBERTa-base [72] for each task individually and report the results on the GLUE dev set.",
  "4.3 Graph Representation Learning": "We use a subset of the Open Graph Benchmark (OGB) datasets [45]. The tasks are node property prediction (NPP), graph property prediction (GPP), and link property prediction (LPP). For each task, we use two of the following GNN architectures and matrix factorization methods: GCN [57], DeeperGCN (DGCN) [68], SAGE [37], GIN [95], ComplEx [89], and CP [66]. We use popular training schemes, such as virtual nodes, cluster sampling [14], or relation prediction as auxiliary training objective [13]. The reported metrics are ROC-AUC for Proteins, Accuracy for Products, F1 score for Code2, Average precision for Molpcba, and Mean Reciprocal Rank for Biokg/Citation2.",
  "4.4 9 Findings": "We use G(·) to describe the generalization accuracy/F1/ROCAUC/AP/MRR of all optimizers {Non-flat baseline(NF),SWA,SAM,WASAM}.\n1. Datasets matter. For example, for node property prediction (Proteins), we see that no flat optimizer improves over the baseline optimizer; however, for (Products), flat-minima optimizers on the same architectures significantly improve over the baseline. We further explore the impact of different data augmentation strategies in Appendix A.7.\n2. Architectures matter, e.g., there is a vast difference across model architectures for link property prediction on the Citation2 dataset: using a GNN with GCN layers, SAM achieves a statistically significant boost of >1.30% and SWA slightly hurts the performance. When we replace the GCN layers with SAGE layers (and fix everything else), we see a boost of > 1.15% for SWA, while SAM hurts the performance by −0.31%.\n3. SWA underperforms on NLP tasks. SAM achieves the best performance in 7/10 experiments on NLP tasks, consistent with the findings of Bahri et al. [4], which show that SAM can boost performance across a wide range of NLP tasks. However, SWA never performs best, only improving the results in 1/10 cases, and even hurting the performance on 4 tasks. Surprisingly, G(WASAM) > G(SAM) for {SST, QNLI} while SWA decreases performance in these cases.\n4. SWA beats SAM on GRL tasks. G(SWA) > G(NF) in 10/12 experiments, while G(SAM) > G(NF) only in 4. We examine why SAM under-performs in Appendix A.4.\n5. SWA does not work well with Transformers. SWA often does not improve and sometimes hurts performances, as can be seen in the ViT results in Table 2, and NLP results in Fig. 4a. In contrast, SAM has some positive effects in these settings. We explore this further in Appendix A.3.\n6. SWA and SAM improve SSL task performance. This is non-trivial as the theoretical motivation behind finding flat minima is linked to supervised learning losses [43, 77, 21]. Concurrently to our work, Ramesh et al. [82] report that SAM helps for contrastive CLIP [79] models too.\n7. Flat optimizers do not strictly improve over non-flat optimizers. The non-flat optimizer is nearly always the best for NPP Proteins and SSL methods on CIFAR10. We investigate the NPP Proteins solutions in the next subsection and recommend a more thorough investigation of the landscapes of SSL objectives for future work.\n8. Flat-minima optimizers offer asymmetric payoffs: at worst, they decreased performance by −0.30%, at best, they increased it by 2.60%.\n9. Averaging SAM iterates often improves over SWA or SAM alone. G(WASAM) > min(G(SWA),G(SAM)) in 39/42 cases. We hypothesize that asymmetric payoffs are the reason: when either SWA or SAM does not improve over the baseline (as discussed above), it does not hurt (much) either, hence WASAM is more robust across all tasks.",
  "4.5 Why do flat-minima optimizers fail?": "Here, we audit one of the cases, where neither θSWA nor θSAM improves over θNF (this happens in 3 out of 42 cases): training a GraphSAGE [37] model on OGB-Proteins: a protein-protein interaction graph where the goal is to predict the presence of protein functions (multi-label binary classification) [45]. θSWA performs noticeably worse; θSAM performs about equally well.\nFig. 5 shows two linear interpolations: between θNF (ADAM) and (1) θSWA (Figures 5a and 5b), and (2) θSAM (Figures 5c and 5d). In contrast to success cases in Fig. 2, here: (a) for both SWA and SAM, the training loss minimizer is very uncorrelated with the test loss minimizer; (b) SAM and ADAM seem to be contained in the same test loss/accuracy basin. More analyses can be found in the Appendix.",
  "6 Conclusion": "We investigated when flat minima optimizers work by conducting a fair comparison of two popular flatminima optimizers. We examined the behavior of SWA/SAM by analyzing their loss landscapes on two representative deep learning tasks. Our next step was to evaluate their generalization performance on a broad and diverse set of tasks (in data, learning settings, and model architectures). Based on this benchmarking, we identified 9 findings, of which some directly guide future work directions. Finally, when SWA/SAM did not improve over baselines, common assumptions seemed broken (i.e., train-to-test loss minimizers were not correlated).",
  "Acknowledgements": "We are very grateful to Kilian Q. Weinberger and Gao Huang for initial discussions and intuition, Pontus Stenetorp for NLP experimental design advice, and Oscar Key for feedback on the draft. JK and LL acknowledge support by the Engineering and Physical Sciences Research Council with grant number EP/S021566/1. This research was supported through Azure resources provided by The Alan Turing Institute and credits awarded by Google Cloud.",
  "Reviewer Summary": "Reviewer_3: This paper compares two well-known flat-minima-seeking methods, stochastic weight averaging (SWA) and sharpness aware minimization (SAM). Based on the geometric loss landscape analysis, the paper suggests combining SWA and SAM. Through experiments conducted on a wide range of tasks, the paper attempts to address when and why each method fails.\n\nReviewer_4: This paper focuses on two famous flat-minima optimizers, SAM and SWA. They provide lots of experiment results to analyze the solution of these two optimizers and find that they focus on different aspects. Finally, they try to combine them to get better performance than SAM or SWA and conduct some experiments in a variety of tasks to help us better understand these two algorithms.\n\nReviewer_5: The authors perform a detailed comparison of stochastic weight averaging (SWA) and sharpness-aware minimization (SAM), first with loss landscape analysis and then with a broad set of benchmarks. The authors find several surprising results, and in particular show that combining the two methods, it is often possible to achieve improvements over both of them, leading to consistently good performance.\n\nReviewer_6: This paper analyses the properties of two flat minima optimizers, Stochastic Weight Averaging (SWA) and Sharpness-Aware Minimization (SAM). The nature of the minima reached by the two methods is studied through linear interpolations and dominant Hessian eigenvalues. SWA and SAM are benchmarked across a wide range of tasks in Natural language understanding, Graph Representation Learning, and Image Classification. Based on these results, a set of observations about SWA and SAM are described."
}