Sharpness-Aware Minimization for Efficiently Improving Generalization | AGIDaily
AGI Daily
资讯日报词条论文人物新创
返回论文列表
1 引言2 锐度感知最小化(SAM)3 实验评估3.1 从头训练的图像分类3.2 微调3.3 对标签噪声的稳健性4 从 SAM 看锐度与泛化4.1 $m$-锐度4.2 Hessian 谱5 相关工作6 讨论与未来工作致谢A 附录A.1 PAC-Bayesian 泛化界B 补充实验结果B.1 SVHN 与 Fashion-MNISTC 实验细节C.1 实验超参数C.2 微调细节C.3 全部使用 $\rho=0.05$ 的实验结果C.4 二阶项消融C.5 $p$-范数的选择C.6 内层最大化的多次迭代
返回论文列表
目录

Sharpness-Aware Minimization for Efficiently Improving Generalization

收录于 ICLR 2021 会议论文被引 1,584 次
打开论文来源

Published as a conference paper at ICLR 2021

Sharpness-Aware Minimization for Efficiently Improving Generalization

Pierre Foret ∗
Google Research
pierre.pforet@gmail.com

Ariel Kleiner
Google Research
akleiner@gmail.com

Hossein Mobahi
Google Research
hmobahi@google.com

Behnam Neyshabur
Blueshift, Alphabet
neyshabur@gmail.com

∗ Work done as part of the Google AI Residency program.

Abstract

摘要

In today's heavily overparameterized models, the value of the training loss provides few guarantees on model generalization ability. Indeed, optimizing only the training loss value, as is commonly done, can easily lead to suboptimal model quality. Motivated by prior work connecting the geometry of the loss landscape and generalization, we introduce a novel, effective procedure for instead simultaneously minimizing loss value and loss sharpness. In particular, our procedure, Sharpness-Aware Minimization (SAM), seeks parameters that lie in neighborhoods having uniformly low loss; this formulation results in a min-max optimization problem on which gradient descent can be performed efficiently. We present empirical results showing that SAM improves model generalization across a variety of benchmark datasets (e.g., CIFAR-{10, 100}, ImageNet, finetuning tasks) and models, yielding novel state-of-the-art performance for several. Additionally, we find that SAM natively provides robustness to label noise on par with that provided by state-of-the-art procedures that specifically target learning with noisy labels. We open source our code at https://github.com/google-research/sam.

在今天这些严重过参数化的模型里,训练损失的大小几乎不能保证模型的泛化能力。事实上,像通常那样只去优化训练损失,很容易得到质量并不理想的模型。受已有工作把损失面几何与泛化联系起来的启发,我们提出一种新的、有效的做法:同时压低损失值与损失锐度。具体而言,我们的方法锐度感知最小化(SAM,Sharpness-Aware Minimization)寻找落在损失处处都低的邻域中的参数;这一表述会得到一个最小-最大优化问题,而梯度下降可以高效地求解它。我们给出的实验表明,SAM 能在多种基准数据集(例如 CIFAR-{10, 100}、ImageNet、微调任务)和多种模型上提升泛化,并在其中若干设定上达到新的当时最佳水平。此外我们还发现,SAM 对标签噪声的稳健性,可以与专门针对带噪标签学习的当时最佳方法相当。我们把代码开源在 https://github.com/google-research/sam。

Introduction

1 引言

Modern machine learning's success in achieving ever better performance on a wide range of tasks has relied in significant part on ever heavier overparameterization, in conjunction with developing ever more effective training algorithms that are able to find parameters that generalize well. Indeed, many modern neural networks can easily memorize the training data and have the capacity to readily overfit (Zhang et al., 2016). Such heavy overparameterization is currently required to achieve state-of-the-art results in a variety of domains (Tan & Le, 2019; Kolesnikov et al., 2020; Huang et al., 2018). In turn, it is essential that such models be trained using procedures that ensure that the parameters actually selected do in fact generalize beyond the training set.

现代机器学习之所以能在越来越多的任务上取得更好的表现,在很大程度上依靠越来越重的过参数化,再加上越来越有效、能够找到泛化良好参数的训练算法。事实上,许多现代神经网络可以轻易记住训练数据,也有能力很快过拟合(Zhang et al., 2016)。在许多领域,目前仍需要这种程度的过参数化才能达到当时最佳结果(Tan & Le, 2019;Kolesnikov et al., 2020;Huang et al., 2018)。因此,必须用能够保证所选参数确实能推广到训练集之外的程序来训练这些模型。

Unfortunately, simply minimizing commonly used loss functions (e.g., cross-entropy) on the training set is typically not sufficient to achieve satisfactory generalization. The training loss landscapes of today's models are commonly complex and non-convex, with a multiplicity of local and global minima, and with different global minima yielding models with different generalization abilities (Shirish Keskar et al., 2016). As a result, the choice of optimizer (and associated optimizer settings) from among the many available (e.g., stochastic gradient descent (Nesterov, 1983), Adam (Kingma & Ba, 2014), RMSProp (Hinton et al.), and others (Duchi et al., 2011; Dozat, 2016; Martens & Grosse, 2015)) has become an important design choice, though understanding of its relationship to model generalization remains nascent (Shirish Keskar et al., 2016; Wilson et al., 2017; Shirish Keskar & Socher, 2017; Agarwal et al., 2020; Jacot et al., 2018). Relatedly, a panoply of methods for modifying the training process have been proposed, including dropout (Srivastava et al., 2014), batch normalization (Ioffe & Szegedy, 2015), stochastic depth (Huang et al., 2016), data augmentation (Cubuk et al., 2018), and mixed sample augmentations (Zhang et al., 2017; Harris et al., 2020).

遗憾的是,只在训练集上最小化交叉熵这类常用损失函数,通常并不足以获得令人满意的泛化。今天这些模型的训练损失面往往复杂且非凸,有许多局部和全局最小点,不同的全局最小点对应的泛化能力也可以很不一样(Shirish Keskar et al., 2016)。于是,在随机梯度下降(Nesterov, 1983)、Adam(Kingma & Ba, 2014)、RMSProp(Hinton et al.)以及其他方法(Duchi et al., 2011;Dozat, 2016;Martens & Grosse, 2015)等众多优化器中如何选择(以及如何设置超参数),本身成了一项重要的设计决定,尽管人们对其与模型泛化的关系仍了解有限(Shirish Keskar et al., 2016;Wilson et al., 2017;Shirish Keskar & Socher, 2017;Agarwal et al., 2020;Jacot et al., 2018)。与此相关,已有大量改写训练过程的方法被提出,包括 dropout(Srivastava et al., 2014)、批归一化(Ioffe & Szegedy, 2015)、随机深度(Huang et al., 2016)、数据增强(Cubuk et al., 2018)以及混合样本增强(Zhang et al., 2017;Harris et al., 2020)。

The connection between the geometry of the loss landscape—in particular, the flatness of minima—and generalization has been studied extensively from both theoretical and empirical perspectives (Shirish Keskar et al., 2016; Dziugaite & Roy, 2017; Jiang et al., 2019). While this connection has held the promise of enabling new approaches to model training that yield better generalization, practical efficient algorithms that specifically seek out flatter minima and furthermore effectively improve generalization on a range of state-of-the-art models have thus far been elusive (e.g., see (Chaudhari et al., 2016; Izmailov et al., 2018); we include a more detailed discussion of prior work in Section 5).

损失面几何——尤其是最小点的平坦程度——与泛化之间的联系,已经从理论和经验两方面得到大量研究(Shirish Keskar et al., 2016;Dziugaite & Roy, 2017;Jiang et al., 2019)。这一联系本应带来新的训练方法、从而得到更好的泛化,但专门去寻找更平坦最小点、并且能在一系列当时最佳模型上切实提升泛化的实用高效算法,至今仍然很难得到(例如可见 Chaudhari et al., 2016;Izmailov et al., 2018;我们在第 5 节对先前工作做更详细的讨论)。

Error rate reduction obtained by switching to SAM, and loss landscapes of a sharp minimum versus a wide minimum

Figure 1: (left) Error rate reduction obtained by switching to SAM. Each point is a different dataset / model / data augmentation. (middle) A sharp minimum to which a ResNet trained with SGD converged. (right) A wide minimum to which the same ResNet trained with SAM converged.

图 1:(左)改用 SAM 后错误率的下降。每个点对应不同的数据集 / 模型 / 数据增强。(中)一个用 SGD 训练的 ResNet 所收敛到的尖锐最小点。(右)同一个 ResNet 用 SAM 训练后所收敛到的宽阔最小点。

We present here a new efficient, scalable, and effective approach to improving model generalization ability that directly leverages the geometry of the loss landscape and its connection to generalization, and is powerfully complementary to existing techniques. In particular, we make the following contributions:

我们在此提出一种新的、高效、可扩展且有效的方法,直接利用损失面几何及其与泛化的联系来提升模型泛化能力,并且与已有技术可以很好地互补。具体来说,我们有如下贡献:

  • We introduce Sharpness-Aware Minimization (SAM), a novel procedure that improves model generalization by simultaneously minimizing loss value and loss sharpness. SAM functions by seeking parameters that lie in neighborhoods having uniformly low loss value (rather than parameters that only themselves have low loss value, as illustrated in the middle and righthand images of Figure 1), and can be implemented efficiently and easily.
  • 我们提出锐度感知最小化(SAM),这是一种同时最小化损失值与损失锐度、从而提升模型泛化的新方法。SAM 寻找落在损失值处处都低的邻域中的参数(而不是只寻找自身损失低的参数,如图 1 中、右两幅所示),并且可以实现得既高效又简单。
  • We show via a rigorous empirical study that using SAM improves model generalization ability across a range of widely studied computer vision tasks (e.g., CIFAR-{10, 100}, ImageNet, finetuning tasks) and models, as summarized in the lefthand plot of Figure 1. For example, applying SAM yields novel state-of-the-art performance for a number of already-intensely-studied tasks, such as ImageNet, CIFAR-{10, 100}, SVHN, Fashion-MNIST, and the standard set of image classification finetuning tasks (e.g., Flowers, Stanford Cars, Oxford Pets, etc).
  • 我们通过系统的实证研究说明,SAM 能在一系列被广泛研究的计算机视觉任务(例如 CIFAR-{10, 100}、ImageNet、微调任务)和多种模型上提升泛化,如图 1 左侧所示。例如,把 SAM 用在 ImageNet、CIFAR-{10, 100}、SVHN、Fashion-MNIST 以及一组标准图像分类微调任务上,为其中若干已经被充分研究过的任务带来了新的当时最佳结果。
  • We show that SAM furthermore provides robustness to label noise on par with that provided by state-of-the-art procedures that specifically target learning with noisy labels.
  • 我们还说明,SAM 对标签噪声的稳健性,可以与专门针对带噪标签学习的当时最佳方法相当。
  • Through the lens provided by SAM, we further elucidate the connection between loss sharpness and generalization by surfacing a promising new notion of sharpness, which we term m-sharpness.
  • 借助 SAM 提供的视角,我们进一步澄清损失锐度与泛化的联系,并提出一种有潜力的新锐度概念,称为 mmm-锐度。

Section 2 below derives the SAM procedure and presents the resulting algorithm in full detail. Section 3 evaluates SAM empirically, and Section 4 further analyzes the connection between loss sharpness and generalization through the lens of SAM. Finally, we conclude with an overview of related work and a discussion of conclusions and future work in Sections 5 and 6, respectively.

第 2 节推导 SAM 方法,并给出完整算法。第 3 节从经验上评估 SAM,第 4 节再从 SAM 的视角分析损失锐度与泛化的联系。最后,我们在第 5 节和第 6 节分别综述相关工作,并讨论结论与后续方向。

Sharpness-Aware Minimization (SAM)

2 锐度感知最小化(SAM)

Throughout the paper, we denote scalars as aaa, vectors as a\mathbf{a}a, matrices as A\mathbf{A}A, sets as A\mathcal{A}A, and equality by definition as ≜\triangleq≜. Given a training dataset S≜∪i=1n{(xi,yi)}\mathcal{S} \triangleq \cup_{i=1}^n \{(\mathbf{x}_i, \mathbf{y}_i)\}S≜∪i=1n​{(xi​,yi​)} drawn i.i.d. from distribution D\mathscr{D}D, we seek to learn a model that generalizes well. In particular, consider a family of models parameterized by w∈W⊆Rd\mathbf{w} \in \mathcal{W} \subseteq \mathbb{R}^dw∈W⊆Rd; given a per-data-point loss function l:W×X×Y→R+l: \mathcal{W} \times \mathcal{X} \times \mathcal{Y} \rightarrow \mathbb{R}_+l:W×X×Y→R+​, we define the training set loss LS(w)≜1n∑i=1nl(w,xi,yi)L_S(\mathbf{w}) \triangleq \frac{1}{n} \sum_{i=1}^n l(\mathbf{w}, \mathbf{x}_i, \mathbf{y}_i)LS​(w)≜n1​∑i=1n​l(w,xi​,yi​) and the population loss LD(w)≜E(x,y)∼D[l(w,x,y)]L_\mathscr{D}(\mathbf{w}) \triangleq \mathbb{E}_{(\mathbf{x}, \mathbf{y}) \sim D} [l(\mathbf{w}, \mathbf{x}, \mathbf{y})]LD​(w)≜E(x,y)∼D​[l(w,x,y)]. Having observed only S\mathcal{S}S, the goal of model training is to select model parameters w\mathbf{w}w having low population loss LD(w)L_\mathscr{D}(\mathbf{w})LD​(w).

全文中,标量记为 aaa,向量记为 a\mathbf{a}a,矩阵记为 A\mathbf{A}A,集合记为 A\mathcal{A}A,定义相等记为 ≜\triangleq≜。给定从分布 D\mathscr{D}D 独立同分布抽出的训练集 S≜∪i=1n{(xi,yi)}\mathcal{S} \triangleq \cup_{i=1}^n \{(\mathbf{x}_i, \mathbf{y}_i)\}S≜∪i=1n​{(xi​,yi​)},我们希望学到一个泛化良好的模型。具体而言,考虑由 w∈W⊆Rd\mathbf{w} \in \mathcal{W} \subseteq \mathbb{R}^dw∈W⊆Rd 参数化的模型族;给定逐点损失函数 l:W×X×Y→R+l: \mathcal{W} \times \mathcal{X} \times \mathcal{Y} \rightarrow \mathbb{R}_+l:W×X×Y→R+​,定义训练集损失 LS(w)≜1n∑i=1nl(w,xi,yi)L_S(\mathbf{w}) \triangleq \frac{1}{n} \sum_{i=1}^n l(\mathbf{w}, \mathbf{x}_i, \mathbf{y}_i)LS​(w)≜n1​∑i=1n​l(w,xi​,yi​),以及总体损失 LD(w)≜E(x,y)∼D[l(w,x,y)]L_\mathscr{D}(\mathbf{w}) \triangleq \mathbb{E}_{(\mathbf{x}, \mathbf{y}) \sim D} [l(\mathbf{w}, \mathbf{x}, \mathbf{y})]LD​(w)≜E(x,y)∼D​[l(w,x,y)]。在只观察到 S\mathcal{S}S 的情况下,模型训练的目标是选出总体损失 LD(w)L_\mathscr{D}(\mathbf{w})LD​(w) 较低的参数 w\mathbf{w}w。

Utilizing LS(w)L_\mathcal{S}(\mathbf{w})LS​(w) as an estimate of LD(w)L_\mathscr{D}(\mathbf{w})LD​(w) motivates the standard approach of selecting parameters w\mathbf{w}w by solving min⁡wLS(w)\min_{\mathbf{w}} L_\mathcal{S}(\mathbf{w})minw​LS​(w) (possibly in conjunction with a regularizer on w\mathbf{w}w) using an optimization procedure such as SGD or Adam. Unfortunately, however, for modern overparameterized models such as deep neural networks, typical optimization approaches can easily result in suboptimal performance at test time. In particular, for modern models, LS(w)L_\mathcal{S}(\mathbf{w})LS​(w) is typically non-convex in w\mathbf{w}w, with multiple local and even global minima that may yield similar values of LS(w)L_\mathcal{S}(\mathbf{w})LS​(w) while having significantly different generalization performance (i.e., significantly different values of LD(w)L_\mathscr{D}(\mathbf{w})LD​(w)).

把 LS(w)L_\mathcal{S}(\mathbf{w})LS​(w) 当作 LD(w)L_\mathscr{D}(\mathbf{w})LD​(w) 的估计,会导出通常的做法:用 SGD 或 Adam 这类优化程序去求解 min⁡wLS(w)\min_{\mathbf{w}} L_\mathcal{S}(\mathbf{w})minw​LS​(w)(也可能再加上对 w\mathbf{w}w 的正则)。然而,对深度网络这类现代过参数化模型,常见优化方法在测试时很容易得到次优表现。特别是,对现代模型而言,LS(w)L_\mathcal{S}(\mathbf{w})LS​(w) 对 w\mathbf{w}w 通常是非凸的,存在多个局部甚至全局最小点,它们的 LS(w)L_\mathcal{S}(\mathbf{w})LS​(w) 可以很接近,泛化表现(也就是 LD(w)L_\mathscr{D}(\mathbf{w})LD​(w))却可能相差很大。

Motivated by the connection between sharpness of the loss landscape and generalization, we propose a different approach: rather than seeking out parameter values w\mathbf{w}w that simply have low training loss value LS(w)L_{\mathcal{S}}(\mathbf{w})LS​(w), we seek out parameter values whose entire neighborhoods have uniformly low training loss value (equivalently, neighborhoods having both low loss and low curvature). The following theorem illustrates the motivation for this approach by bounding generalization ability in terms of neighborhood-wise training loss (full theorem statement and proof in Appendix A): \begin{inftheorem} For any ρ>0\rho>0ρ>0, with high probability over training set S\mathcal{S}S generated from distribution D\mathscr{D}D, LD(w)≤max⁡∥ϵ∥2≤ρLS(w+ϵ)+h(∥w∥22/ρ2),L_\mathscr{D}(\mathbf{w}) \leq \max_{\|\mathbf{\epsilon}\|_2 \leq \rho} L_\mathcal{S}(\mathbf{w}+\mathbf{\epsilon}) + h(\|\mathbf{w}\|_2^2/\rho^2),LD​(w)≤∥ϵ∥2​≤ρmax​LS​(w+ϵ)+h(∥w∥22​/ρ2), where h:R+→R+h: \mathbb{R}_{+}\rightarrow \mathbb{R}_{+}h:R+​→R+​ is a strictly increasing function (under some technical conditions on LD(w)L_\mathscr{D}(\mathbf{w})LD​(w)). \end{inftheorem} To make explicit our sharpness term, we can rewrite the right hand side of the inequality above as [max⁡∥ϵ∥2≤ρLS(w+\epsilonilon)−LS(w)]+LS(w)+h(∥w∥22/ρ2).[\max_{\|\mathbf{\epsilon}\|_2\leq \rho }L_\mathcal{S}(\mathbf{w}+\mathbf{\epsilonilon}) - L_\mathcal{S}(\mathbf{w})] + L_\mathcal{S}(\mathbf{w}) + h(\|\mathbf{w}\|_2^2/\rho^2).[∥ϵ∥2​≤ρmax​LS​(w+\epsilonilon)−LS​(w)]+LS​(w)+h(∥w∥22​/ρ2). The term in square brackets captures the sharpness of LSL_\mathcal{S}LS​ at w\mathbf{w}w by measuring how quickly the training loss can be increased by moving from w\mathbf{w}w to a nearby parameter value; this sharpness term is then summed with the training loss value itself and a regularizer on the magnitude of w\mathbf{w}w. Given that the specific function hhh is heavily influenced by the details of the proof, we substitute the second term with λ∣∣w∣∣22\lambda ||w||_2^2λ∣∣w∣∣22​ for a hyperparameter λ\lambdaλ, yielding a standard L2 regularization term. Thus, inspired by the terms from the bound, we propose to select parameter values by solving the following Sharpness-Aware Minimization (SAM) problem:

受损失面锐度与泛化之间联系的启发,我们提出另一种做法:不是只去寻找训练损失 LS(w)L_{\mathcal{S}}(\mathbf{w})LS​(w) 本身较低的参数 w\mathbf{w}w,而是寻找整个邻域内训练损失都均匀较低的参数(等价地说,既低损失、又低曲率的邻域)。下面的定理用邻域训练损失来约束泛化能力,从而说明这一做法的动机(完整定理陈述与证明见附录 A):

对任意 ρ>0\rho>0ρ>0,在由分布 D\mathscr{D}D 生成的训练集 S\mathcal{S}S 上,以高概率有

LD(w)≤max⁡∥ϵ∥2≤ρLS(w+ϵ)+h(∥w∥22/ρ2),L_\mathscr{D}(\mathbf{w}) \leq \max_{\|\mathbf{\epsilon}\|_2 \leq \rho} L_\mathcal{S}(\mathbf{w}+\mathbf{\epsilon}) + h(\|\mathbf{w}\|_2^2/\rho^2),LD​(w)≤∥ϵ∥2​≤ρmax​LS​(w+ϵ)+h(∥w∥22​/ρ2),

其中 h:R+→R+h: \mathbb{R}_{+}\rightarrow \mathbb{R}_{+}h:R+​→R+​ 是一个严格递增函数(在对 LD(w)L_\mathscr{D}(\mathbf{w})LD​(w) 的若干技术条件下)。

为了把锐度项明确写出来,可以把上述不等式的右边改写成

[max⁡∥ϵ∥2≤ρLS(w+ϵ)−LS(w)]+LS(w)+h(∥w∥22/ρ2).[\max_{\|\mathbf{\epsilon}\|_2\leq \rho }L_\mathcal{S}(\mathbf{w}+\mathbf{\epsilon}) - L_\mathcal{S}(\mathbf{w})] + L_\mathcal{S}(\mathbf{w}) + h(\|\mathbf{w}\|_2^2/\rho^2).[∥ϵ∥2​≤ρmax​LS​(w+ϵ)−LS​(w)]+LS​(w)+h(∥w∥22​/ρ2).

方括号中的项通过度量从 w\mathbf{w}w 走到邻近参数时训练损失能升高多快,来刻画 LSL_\mathcal{S}LS​ 在 w\mathbf{w}w 处的锐度;这一锐度项再与训练损失本身以及对 w\mathbf{w}w 大小的正则相加。由于具体的函数 hhh 很大程度上取决于证明细节,我们把第二项换成超参数 λ\lambdaλ 下的 λ∣∣w∣∣22\lambda ||w||_2^2λ∣∣w∣∣22​,从而得到标准的 ℓ2\ell_2ℓ2​ 正则。于是,受该上界各项的启发,我们提议通过求解如下锐度感知最小化(SAM)问题来选择参数:

min⁡wLSSAM(w)+λ∣∣w∣∣22      where      LSSAM(w)≜max⁡∣∣\epsilonilon∣∣p≤ρLS(w+\epsilonilon),(1)\min_{\mathbf{w}} L^{SAM}_\mathcal{S}(\mathbf{w}) + \lambda ||\mathbf{w}||_2^2 \text{~~~~~~where~~~~~~} L^{SAM}_\mathcal{S}(\mathbf{w}) \triangleq \max_{||\mathbf{\epsilonilon}||_p\leq \rho} L_S(\mathbf{w}+\mathbf{\epsilonilon}), \tag{1}wmin​LSSAM​(w)+λ∣∣w∣∣22​      where      LSSAM​(w)≜∣∣\epsilonilon∣∣p​≤ρmax​LS​(w+\epsilonilon),(1)

where ρ≥0\rho \geq 0ρ≥0 is a hyperparameter and p∈[1,∞]p \in [1, \infty]p∈[1,∞] (we have generalized slightly from an L2-norm to a ppp-norm in the maximization over \epsilonilon\mathbf{\epsilonilon}\epsilonilon, though we show empirically in appendix C.5 that p=2p=2p=2 is typically optimal). Figure 1 shows ¹ the loss landscape for a model that converged to minima found by minimizing either LS(w)L_\mathcal{S}(\mathbf{w})LS​(w) or LSSAM(w)L^{SAM}_\mathcal{S}(\mathbf{w})LSSAM​(w), illustrating that the sharpness-aware loss prevents the model from converging to a sharp minimum.

其中 ρ≥0\rho \geq 0ρ≥0 是超参数,p∈[1,∞]p \in [1, \infty]p∈[1,∞](我们把对 ϵ\mathbf{\epsilon}ϵ 的最大化从 ℓ2\ell_2ℓ2​ 范数略加推广到 ppp-范数,不过附录 C.5 的经验结果说明 p=2p=2p=2 通常是最好的)。图 1 展示了¹分别通过最小化 LS(w)L_\mathcal{S}(\mathbf{w})LS​(w) 或 LSSAM(w)L^{SAM}_\mathcal{S}(\mathbf{w})LSSAM​(w) 而收敛到最小点的模型损失面,说明锐度感知损失能避免模型落入尖锐最小点。

¹ Figure 1 was generated following (Li et al., 2017) with the provided ResNet56 (no residual connections) checkpoint, and training the same model with SAM.

¹ 图 1 按照 Li et al.(2017)的方法生成,使用了所提供的 ResNet56(无残差连接)检查点,并用 SAM 训练了同一模型。

In order to minimize LSSAM(w)L^{SAM}_\mathcal{S}(\mathbf{w})LSSAM​(w), we derive an efficient and effective approximation to ∇wLSSAM(w)\nabla_{\mathbf{w}} L^{SAM}_\mathcal{S}(\mathbf{w})∇w​LSSAM​(w) by differentiating through the inner maximization, which in turn enables us to apply stochastic gradient descent directly to the SAM objective. Proceeding down this path, we first approximate the inner maximization problem via a first-order Taylor expansion of LS(w+\epsilonilon)L_\mathcal{S}(\mathbf{w}+\mathbf{\epsilonilon})LS​(w+\epsilonilon) w.r.t. \epsilonilon\mathbf{\epsilonilon}\epsilonilon around 0\mathbf{0}0, obtaining \epsilonilon∗(w)≜arg max⁡∥\epsilonilon∥p≤ρLS(w+\epsilonilon)≈arg max⁡∥\epsilonilon∥p≤ρLS(w)+\epsilonilonT∇wLS(w)=arg max⁡∥\epsilonilon∥p≤ρ\epsilonilonT∇wLS(w).{\mathbf{\epsilonilon}^*}(\mathbf{w}) \triangleq \argmax_{\|\mathbf{\epsilonilon}\|_p \leq \rho} L_\mathcal{S}(\mathbf{w}+\mathbf{\epsilonilon}) \approx \argmax_{\|\mathbf{\epsilonilon}\|_p \leq \rho} L_\mathcal{S}(\mathbf{w}) + \mathbf{\epsilonilon}^T \nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w}) = \argmax_{\|\mathbf{\epsilonilon}\|_p \leq \rho} \mathbf{\epsilonilon}^T \nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w}).\epsilonilon∗(w)≜∥\epsilonilon∥p​≤ρargmax​LS​(w+\epsilonilon)≈∥\epsilonilon∥p​≤ρargmax​LS​(w)+\epsilonilonT∇w​LS​(w)=∥\epsilonilon∥p​≤ρargmax​\epsilonilonT∇w​LS​(w). In turn, the value \epsilonilon^(w)\hat{\mathbf{\epsilonilon}}(\mathbf{w})\epsilonilon^​(w) that solves this approximation is given by the solution to a classical dual norm problem (∣⋅∣q−1|\cdot |^{q-1}∣⋅∣q−1 denotes elementwise absolute value and power) ² :

为了最小化 LSSAM(w)L^{SAM}_\mathcal{S}(\mathbf{w})LSSAM​(w),我们对内层最大化做微分,从而得到 ∇wLSSAM(w)\nabla_{\mathbf{w}} L^{SAM}_\mathcal{S}(\mathbf{w})∇w​LSSAM​(w) 的一个高效且有效的近似,这样就可以把随机梯度下降直接用在 SAM 目标上。沿着这条路,我们先把 LS(w+ϵ)L_\mathcal{S}(\mathbf{w}+\mathbf{\epsilon})LS​(w+ϵ) 对 ϵ\mathbf{\epsilon}ϵ 在 0\mathbf{0}0 附近做一阶泰勒展开,来近似内层最大化,得到

ϵ∗(w)≜arg max⁡∥ϵ∥p≤ρLS(w+ϵ)≈arg max⁡∥ϵ∥p≤ρLS(w)+ϵT∇wLS(w)=arg max⁡∥ϵ∥p≤ρϵT∇wLS(w).{\mathbf{\epsilon}^*}(\mathbf{w}) \triangleq \argmax_{\|\mathbf{\epsilon}\|_p \leq \rho} L_\mathcal{S}(\mathbf{w}+\mathbf{\epsilon}) \approx \argmax_{\|\mathbf{\epsilon}\|_p \leq \rho} L_\mathcal{S}(\mathbf{w}) + \mathbf{\epsilon}^T \nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w}) = \argmax_{\|\mathbf{\epsilon}\|_p \leq \rho} \mathbf{\epsilon}^T \nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w}).ϵ∗(w)≜∥ϵ∥p​≤ρargmax​LS​(w+ϵ)≈∥ϵ∥p​≤ρargmax​LS​(w)+ϵT∇w​LS​(w)=∥ϵ∥p​≤ρargmax​ϵT∇w​LS​(w).

于是,求解这一近似的 ϵ^(w)\hat{\mathbf{\epsilon}}(\mathbf{w})ϵ^(w) 由经典的对偶范数问题给出(∣⋅∣q−1|\cdot |^{q-1}∣⋅∣q−1 表示逐元素取绝对值再乘方)²:

² In the case of interest p=2p=2p=2, this boils down to simply rescaling the gradient such that its norm is ρ\rhoρ.

² 在我们所关心的 p=2p=2p=2 情形中,这不过是把梯度重新缩放,使其范数为 ρ\rhoρ。

\epsilonilon^(w)=ρ\mboxsign(∇wLS(w))∣∇wLS(w)∣q−1/(∥∇wLS(w)∥qq)1/p(2)\hat{\mathbf{\epsilonilon}}(\mathbf{w}) = \rho \mbox{ sign}\left(\nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w})\right)\left|\nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w})\right|^{q-1} / \bigg(\|\nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w})\|_q^q\bigg)^{1/p} \tag{2}\epsilonilon^​(w)=ρ\mboxsign(∇w​LS​(w))∣∇w​LS​(w)∣q−1/(∥∇w​LS​(w)∥qq​)1/p(2)

where 1/p+1/q=11/p + 1/q = 11/p+1/q=1. Substituting back into equation (1) and differentiating, we then have

其中 1/p+1/q=11/p + 1/q = 11/p+1/q=1。把它代回式 (1) 再求导,便得到

$$\begin{split}
\nabla_{\mathbf{w}} L^{SAM}\mathcal{S}(\mathbf{w}) & \approx \nabla{\mathbf{w}} L_\mathcal{S}(\mathbf{w} + \hat{\mathbf{\epsilonilon}}(\mathbf{w}))
= \frac{d (\mathbf{w} + {\hat{\mathbf{\epsilonilon}}(\mathbf{w})})}{d\mathbf{w}}\nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w})|{\mathbf{w}+\hat{\mathbf{\epsilonilon}}(w)} \
& = {\nabla_w L
\mathcal{S}(\mathbf{w})|{\mathbf{w}+\hat{\mathbf{\epsilonilon}}(\mathbf{w})}} + {\frac{d \hat{\mathbf{\epsilonilon}}(\mathbf{w})}{d \mathbf{w}}\nabla{\mathbf{w}} L_\mathcal{S}(\mathbf{w})|_{\mathbf{w}+\hat{\mathbf{\epsilonilon}}(\mathbf{w})}}.
\end{split}$$

This approximation to ∇wLSSAM(w)\nabla_{\mathbf{w}} L^{SAM}_\mathcal{S}(\mathbf{w})∇w​LSSAM​(w) can be straightforwardly computed via automatic differentiation, as implemented in common libraries such as JAX, TensorFlow, and PyTorch. Though this computation implicitly depends on the Hessian of LS(w)L_\mathcal{S}(\mathbf{w})LS​(w) because \epsilonilon^(w)\hat{\mathbf{\epsilonilon}}(\mathbf{w})\epsilonilon^​(w) is itself a function of ∇wLS(w)\nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w})∇w​LS​(w), the Hessian enters only via Hessian-vector products, which can be computed tractably without materializing the Hessian matrix. Nonetheless, to further accelerate the computation, we drop the second-order terms. obtaining our final gradient approximation:

这一对 ∇wLSSAM(w)\nabla_{\mathbf{w}} L^{SAM}_\mathcal{S}(\mathbf{w})∇w​LSSAM​(w) 的近似,可以用 JAX、TensorFlow 和 PyTorch 等常用库中的自动微分直接计算。尽管该计算隐含地依赖于 LS(w)L_\mathcal{S}(\mathbf{w})LS​(w) 的 Hessian——因为 ϵ^(w)\hat{\mathbf{\epsilon}}(\mathbf{w})ϵ^(w) 本身是 ∇wLS(w)\nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w})∇w​LS​(w) 的函数——但 Hessian 只通过 Hessian-向量积进入,可以在不必显式构造 Hessian 矩阵的情况下可行地计算。不过,为了进一步加快计算,我们丢掉二阶项,得到最终的梯度近似:

∇wLSSAM(w)≈∇wLS(w)∣w+\epsilonilon^(w).(3)\nabla_{\mathbf{w}} L^{SAM}_\mathcal{S}(\mathbf{w}) \approx {\nabla_{\mathbf{w}} L_\mathcal{S}(w)|_{\mathbf{w}+\hat{\mathbf{\epsilonilon}}(\mathbf{w})}}. \tag{3}∇w​LSSAM​(w)≈∇w​LS​(w)∣w+\epsilonilon^​(w)​.(3)

As shown by the results in Section 3, this approximation (without the second-order terms) yields an effective algorithm. In Appendix C.4, we additionally investigate the effect of instead including the second-order terms; in that initial experiment, including them surprisingly degrades performance, and further investigating these terms' effect should be a priority in future work.

第 3 节的结果表明,这一不含二阶项的近似已经能给出有效的算法。在附录 C.4 中,我们还另外考察了保留二阶项的效果;在那次初步实验里,加上这些项反而损害了性能,这些项的作用值得作为后续工作优先研究。

We obtain the final SAM algorithm by applying a standard numerical optimizer such as stochastic gradient descent (SGD) to the SAM objective LSSAM(w)L^{SAM}_\mathcal{S}(\mathbf{w})LSSAM​(w), using equation (3) to compute the requisite objective function gradients. Algorithm 1 gives pseudo-code for the full SAM algorithm, using SGD as the base optimizer, and Figure 2 schematically illustrates a single SAM parameter update.

我们把随机梯度下降(SGD)这类标准数值优化器作用在 SAM 目标 LSSAM(w)L^{SAM}_\mathcal{S}(\mathbf{w})LSSAM​(w) 上,并用式 (3) 计算所需的目标函数梯度,便得到最终的 SAM 算法。算法 1 给出了以 SGD 为基本优化器的完整 SAM 伪代码,图 2 则示意了一次 SAM 参数更新。

Algorithm 1: SAM algorithm

Input: Training set S≜∪i=1n{(xi,yi)}\mathcal{S} \triangleq \cup_{i=1}^n\{(\mathbf{x}_i, \mathbf{y}_i)\}S≜∪i=1n​{(xi​,yi​)}, Loss function l:W×X×Y→R+l:\mathcal{W} \times \mathcal{X} \times \mathcal{Y} \rightarrow \mathbb{R}_+l:W×X×Y→R+​, Batch size bbb, Step size η>0\eta>0η>0, Neighborhood size ρ>0\rho>0ρ>0.
Output: Model trained with SAM
Initialize weights w0\mathbf{w}_0w0​, t=0t=0t=0;
while not converged do
Sample batch B={(x1,y1),…,(xb,yb)}\mathcal{B} = \{(\mathbf{x}_1, \mathbf{y}_1), \ldots, (\mathbf{x}_b, \mathbf{y}_b)\}B={(x1​,y1​),…,(xb​,yb​)};
Compute gradient ∇wLB(w)\nabla_{\mathbf{w}} L_\mathcal{B}(\mathbf{w})∇w​LB​(w) of the batch's training loss;
Compute ϵ^(w)\hat{\mathbf{\epsilon}}(\mathbf{w})ϵ^(w) per equation (2);
Compute gradient approximation for the SAM objective (equation (3)): g=∇wLB(w)∣w+ϵ^(w)\mathbf{g} = \nabla_w L_\mathcal{B}(\mathbf{w})|_{\mathbf{w}+\hat{\mathbf{\epsilon}}(\mathbf{w})}g=∇w​LB​(w)∣w+ϵ^(w)​;
Update weights: wt+1=wt−ηg\mathbf{w}_{t+1} = \mathbf{w}_t - \eta \mathbf{g}wt+1​=wt​−ηg;
t=t+1t = t+1t=t+1;
end
return wt\mathbf{w}_twt​

算法 1:SAM 算法

Input: Training set S≜∪i=1n{(xi,yi)}\mathcal{S} \triangleq \cup_{i=1}^n\{(\mathbf{x}_i, \mathbf{y}_i)\}S≜∪i=1n​{(xi​,yi​)}, Loss function l:W×X×Y→R+l:\mathcal{W} \times \mathcal{X} \times \mathcal{Y} \rightarrow \mathbb{R}_+l:W×X×Y→R+​, Batch size bbb, Step size η>0\eta>0η>0, Neighborhood size ρ>0\rho>0ρ>0.
Output: Model trained with SAM
Initialize weights w0\mathbf{w}_0w0​, t=0t=0t=0;
while not converged do
Sample batch B={(x1,y1),…,(xb,yb)}\mathcal{B} = \{(\mathbf{x}_1, \mathbf{y}_1), \ldots, (\mathbf{x}_b, \mathbf{y}_b)\}B={(x1​,y1​),…,(xb​,yb​)};
Compute gradient ∇wLB(w)\nabla_{\mathbf{w}} L_\mathcal{B}(\mathbf{w})∇w​LB​(w) of the batch's training loss;
Compute ϵ^(w)\hat{\mathbf{\epsilon}}(\mathbf{w})ϵ^(w) per equation (2);
Compute gradient approximation for the SAM objective (equation (3)): g=∇wLB(w)∣w+ϵ^(w)\mathbf{g} = \nabla_w L_\mathcal{B}(\mathbf{w})|_{\mathbf{w}+\hat{\mathbf{\epsilon}}(\mathbf{w})}g=∇w​LB​(w)∣w+ϵ^(w)​;
Update weights: wt+1=wt−ηg\mathbf{w}_{t+1} = \mathbf{w}_t - \eta \mathbf{g}wt+1​=wt​−ηg;
t=t+1t = t+1t=t+1;
end
return wt\mathbf{w}_twt​

Schematic of a single SAM parameter update from the current weights through an adversarial perturbation

Figure 2: Schematic of the SAM parameter update.

图 2:SAM 参数更新的示意。

Empirical Evaluation

3 实验评估

In order to assess SAM's efficacy, we apply it to a range of different tasks, including image classification from scratch (including on CIFAR-10, CIFAR-100, and ImageNet), finetuning pretrained models, and learning with noisy labels. In all cases, we measure the benefit of using SAM by simply replacing the optimization procedure used to train existing models with SAM, and computing the resulting effect on model generalization. As seen below, SAM materially improves generalization performance in the vast majority of these cases.

为了评估 SAM 的效果,我们把它用到一系列任务上,包括从头训练的图像分类(含 CIFAR-10、CIFAR-100 和 ImageNet)、微调预训练模型,以及带噪标签学习。在所有情形中,我们衡量 SAM 收益的方式很直接:只把训练已有模型所用的优化程序换成 SAM,再计算对模型泛化的影响。如下所示,在绝大多数设定里,SAM 都实质性地提升了泛化表现。

Image Classification From Scratch

3.1 从头训练的图像分类

We first evaluate SAM's impact on generalization for today's state-of-the-art models on CIFAR-10 and CIFAR-100 (without pretraining): WideResNets with ShakeShake regularization (Zagoruyko & Komodakis, 2016; Gastaldi, 2017) and PyramidNet with ShakeDrop regularization (Han et al., 2016; Yamada et al., 2018). Note that some of these models have already been heavily tuned in prior work and include carefully chosen regularization schemes to prevent overfitting; therefore, significantly improving their generalization is quite non-trivial. We have ensured that our implementations' generalization performance in the absence of SAM matches or exceeds that reported in prior work (Cubuk et al., 2018; Lim et al., 2019)

我们首先在不做预训练的情况下,评估 SAM 对当今 CIFAR-10 和 CIFAR-100 上当时最佳模型泛化的影响:带 ShakeShake 正则的 WideResNet(Zagoruyko & Komodakis, 2016;Gastaldi, 2017),以及带 ShakeDrop 正则的 PyramidNet(Han et al., 2016;Yamada et al., 2018)。需要说明的是,其中一些模型在先前工作中已经过充分调参,并包含精心选择的正则方案以防止过拟合,因此再显著提升它们的泛化并不容易。我们确保在不加 SAM 时,实现的泛化表现达到或超过先前工作所报告的水平(Cubuk et al., 2018;Lim et al., 2019)。

All results use basic data augmentations (horizontal flip, padding by four pixels, and random crop). We also evaluate in the setting of more advanced data augmentation methods such as cutout regularization (Devries & Taylor, 2017) and AutoAugment (Cubuk et al., 2018), which are utilized by prior work to achieve state-of-the-art results.

所有结果都使用基础数据增强(水平翻转、四周各填 4 个像素,以及随机裁剪)。我们也在更高级的数据增强设定下做了评估,例如 cutout 正则(Devries & Taylor, 2017)和 AutoAugment(Cubuk et al., 2018),这些方法曾被先前工作用来取得当时最佳结果。

SAM has a single hyperparameter ρ\rhoρ (the neighborhood size), which we tune via a grid search over {0.01,0.02,0.05,0.1,0.2,0.5}\{0.01, 0.02, 0.05, 0.1, 0.2, 0.5\}{0.01,0.02,0.05,0.1,0.2,0.5} using 10% of the training set as a validation set ³ . Please see appendix C.1 for the values of all hyperparameters and additional training details. As each SAM weight update requires two backpropagation operations (one to compute \epsilonilon^(w)\hat{\mathbf{\epsilonilon}}(\mathbf{w})\epsilonilon^​(w) and another to compute the final gradient), we allow each non-SAM training run to execute twice as many epochs as each SAM training run, and we report the best score achieved by each non-SAM training run across either the standard epoch count or the doubled epoch count ⁴ . We run five independent replicas of each experimental condition for which we report results (each with independent weight initialization and data shuffling), reporting the resulting mean error (or accuracy) on the test set, and the associated 95% confidence interval. Our implementations utilize JAX (Bradbury et al., 2018), and we train all models on a single host having 8 NVidia V100 GPUs ⁵ . To compute the SAM update when parallelizing across multiple accelerators, we divide each data batch evenly among the accelerators, independently compute the SAM gradient on each accelerator, and average the resulting sub-batch SAM gradients to obtain the final SAM update.

SAM 只有一个超参数 ρ\rhoρ(邻域大小),我们用训练集的 10% 作为验证集,在 {0.01,0.02,0.05,0.1,0.2,0.5}\{0.01, 0.02, 0.05, 0.1, 0.2, 0.5\}{0.01,0.02,0.05,0.1,0.2,0.5} 上做网格搜索来选取³。全部超参数取值和更多训练细节见附录 C.1。由于每次 SAM 权重更新需要两次反向传播(一次计算 ϵ^(w)\hat{\mathbf{\epsilon}}(\mathbf{w})ϵ^(w),另一次计算最终梯度),我们允许每个非 SAM 训练运行执行相当于 SAM 训练两倍的 epoch,并在标准 epoch 数与加倍 epoch 数中报告非 SAM 运行取得的最好成绩⁴。对每个报告结果的实验条件,我们独立重复五次(独立的权重初始化和数据洗牌),报告测试集上的平均错误率(或准确率)以及相应的 95% 置信区间。实现基于 JAX(Bradbury et al., 2018),所有模型都在一台配有 8 块 NVIDIA V100 GPU 的主机上训练⁵。在多加速器上并行计算 SAM 更新时,我们把每个数据批次均匀分给各加速器,在每个加速器上独立计算 SAM 梯度,再把这些子批次 SAM 梯度平均,得到最终的 SAM 更新。

³ We found ρ=0.05\rho=0.05ρ=0.05 to be a solid default value, and we report in appendix C.3 the scores for all our experiments, obtained with ρ=0.05\rho=0.05ρ=0.05 without further tuning.

³ 我们发现 ρ=0.05\rho=0.05ρ=0.05 是一个相当稳妥的默认值,并在附录 C.3 中报告了所有实验在不做进一步调节、一律取 ρ=0.05\rho=0.05ρ=0.05 时的成绩。

⁴ Training for longer generally did not improve accuracy significantly, except for the models previously trained for only 200 epochs and for the largest, most regularized model (PyramidNet + ShakeDrop).

⁴ 加长训练通常并不能显著提高准确率,例外是那些原先只训练 200 个 epoch 的模型,以及最大、正则也最强的模型(PyramidNet + ShakeDrop)。

⁵ Because SAM's performance is amplified by not syncing the perturbations, data parallelism is highly recommended to leverage SAM's full potential (see Section 4 for more details).

⁵ 由于不同步这些扰动时 SAM 的效果会被放大,为了充分发挥 SAM 的潜力,强烈建议使用数据并行(更多细节见第 4 节)。

As seen in Table 1, SAM improves generalization across all settings evaluated for CIFAR-10 and CIFAR-100. For example, SAM enables a simple WideResNet to attain 1.6% test error, versus 2.2% error without SAM. Such gains have previously been attainable only by using more complex model architectures (e.g., PyramidNet) and regularization schemes (e.g., Shake-Shake, ShakeDrop); SAM provides an easily-implemented, model-independent alternative. Furthermore, SAM delivers improvements even when applied atop complex architectures that already use sophisticated regularization: for instance, applying SAM to a PyramidNet with ShakeDrop regularization yields 10.3% error on CIFAR-100, which is, to our knowledge, a new state-of-the-art on this dataset without the use of additional data.

如表 1 所示,在所评估的全部 CIFAR-10 和 CIFAR-100 设定上,SAM 都提升了泛化。例如,SAM 能让一个简单的 WideResNet 达到 1.6% 的测试错误率,而不用 SAM 时是 2.2%。此前这类提升通常只有依靠更复杂的模型结构(例如 PyramidNet)和正则方案(例如 Shake-Shake、ShakeDrop)才能得到;SAM 提供了一种实现简单、且不依赖特定模型的替代办法。此外,即使加在已经使用复杂正则的架构上,SAM 仍然能带来改进:例如,把 SAM 用在带 ShakeDrop 正则的 PyramidNet 上,CIFAR-100 错误率为 10.3%,就我们所知,这是在不使用额外数据时该数据集上新的当时最佳结果。

Table 1: Results for SAM on state-of-the-art models on CIFAR-{10, 100} (WRN = WideResNet; AA = AutoAugment; SGD is the standard non-SAM procedure used to train these models).

Model Augmentation CIFAR-10 SAM CIFAR-10 SGD CIFAR-100 SAM CIFAR-100 SGD
WRN-28-10 (200 epochs) Basic 2.7±0.1\textbf{2.7}_{\pm 0.1}2.7±0.1​ 3.5±0.13.5_{\pm 0.1}3.5±0.1​ 16.5±0.2\textbf{16.5}_{\pm 0.2}16.5±0.2​ 18.8±0.218.8_{\pm 0.2}18.8±0.2​
WRN-28-10 (200 epochs) Cutout 2.3±0.1\textbf{2.3}_{\pm 0.1}2.3±0.1​ 2.6±0.12.6_{\pm 0.1}2.6±0.1​ 14.9±0.2\textbf{14.9}_{\pm 0.2}14.9±0.2​ 16.9±0.116.9_{\pm 0.1}16.9±0.1​
WRN-28-10 (200 epochs) AA 2.1±<0.1\textbf{2.1}_{\pm <0.1}2.1±<0.1​ 2.3±0.12.3_{\pm 0.1}2.3±0.1​ 13.6±0.2\textbf{13.6}_{\pm 0.2}13.6±0.2​ 15.8±0.215.8_{\pm 0.2}15.8±0.2​
WRN-28-10 (1800 epochs) Basic 2.4±0.1\textbf{2.4}_{\pm 0.1}2.4±0.1​ 3.5±0.13.5_{\pm 0.1}3.5±0.1​ 16.3±0.2\textbf{16.3}_{\pm 0.2}16.3±0.2​ 19.1±0.119.1_{\pm 0.1}19.1±0.1​
WRN-28-10 (1800 epochs) Cutout 2.1±0.1\textbf{2.1}_{\pm 0.1}2.1±0.1​ 2.7±0.12.7_{\pm 0.1}2.7±0.1​ 14.0±0.1\textbf{14.0}_{\pm 0.1}14.0±0.1​ 17.4±0.117.4_{\pm 0.1}17.4±0.1​
WRN-28-10 (1800 epochs) AA 1.6±0.1\textbf{1.6}_{\pm 0.1}1.6±0.1​ 2.2±<0.1\textbf{2.2}_{\pm <0.1}2.2±<0.1​ 12.8±0.2\textbf{12.8}_{\pm 0.2}12.8±0.2​ 16.1±0.216.1_{\pm 0.2}16.1±0.2​
Shake-Shake (26 2x96d) Basic 2.3±<0.1\textbf{2.3}_{\pm <0.1}2.3±<0.1​ 2.7±0.12.7_{\pm 0.1}2.7±0.1​ 15.1±0.1\textbf{15.1}_{\pm 0.1}15.1±0.1​ 17.0±0.117.0_{\pm 0.1}17.0±0.1​
Shake-Shake (26 2x96d) Cutout 2.0±<0.1\textbf{2.0}_{\pm <0.1}2.0±<0.1​ 2.3±0.12.3_{\pm 0.1}2.3±0.1​ 14.2±0.2\textbf{14.2}_{\pm 0.2}14.2±0.2​ 15.7±0.215.7_{\pm 0.2}15.7±0.2​
Shake-Shake (26 2x96d) AA 1.6±<0.1\textbf{1.6}_{\pm <0.1}1.6±<0.1​ 1.9±0.11.9_{\pm 0.1}1.9±0.1​ 12.8±0.1\textbf{12.8}_{\pm 0.1}12.8±0.1​ 14.1±0.214.1_{\pm 0.2}14.1±0.2​
PyramidNet Basic 2.7±0.1\textbf{2.7}_{\pm 0.1}2.7±0.1​ 4.0±0.14.0_{\pm 0.1}4.0±0.1​ 14.6±0.4\textbf{14.6}_{\pm 0.4}14.6±0.4​ 19.7±0.319.7_{\pm 0.3}19.7±0.3​
PyramidNet Cutout 1.9±0.1\textbf{1.9}_{\pm 0.1}1.9±0.1​ 2.5±0.12.5_{\pm 0.1}2.5±0.1​ 12.6±0.2\textbf{12.6}_{\pm 0.2}12.6±0.2​ 16.4±0.116.4_{\pm 0.1}16.4±0.1​
PyramidNet AA 1.6±0.1\textbf{1.6}_{\pm 0.1}1.6±0.1​ 1.9±0.11.9_{\pm 0.1}1.9±0.1​ 11.6±0.1\textbf{11.6}_{\pm 0.1}11.6±0.1​ 14.6±0.114.6_{\pm 0.1}14.6±0.1​
PyramidNet+ShakeDrop Basic 2.1±0.1\textbf{2.1}_{\pm 0.1}2.1±0.1​ 2.5±0.12.5_{\pm 0.1}2.5±0.1​ 13.3±0.2\textbf{13.3}_{\pm 0.2}13.3±0.2​ 14.5±0.114.5_{\pm 0.1}14.5±0.1​
PyramidNet+ShakeDrop Cutout 1.6±<0.1\textbf{1.6}_{\pm<0.1}1.6±<0.1​ 1.9±0.11.9_{\pm 0.1}1.9±0.1​ 11.3±0.1\textbf{11.3}_{\pm 0.1}11.3±0.1​ 11.8±0.211.8_{\pm 0.2}11.8±0.2​
PyramidNet+ShakeDrop AA 1.4±<0.1\textbf{1.4}_{\pm<0.1}1.4±<0.1​ 1.6±<0.1\textbf{1.6}_{\pm <0.1}1.6±<0.1​ 10.3±0.1\textbf{10.3}_{\pm 0.1}10.3±0.1​ 10.6±0.110.6_{\pm 0.1}10.6±0.1​

表 1:SAM 在 CIFAR-{10, 100} 上当时最佳模型中的结果(WRN = WideResNet;AA = AutoAugment;SGD 是训练这些模型的标准非 SAM 程序)。

Model Augmentation CIFAR-10 SAM CIFAR-10 SGD CIFAR-100 SAM CIFAR-100 SGD
WRN-28-10 (200 epochs) Basic 2.7±0.1\textbf{2.7}_{\pm 0.1}2.7±0.1​ 3.5±0.13.5_{\pm 0.1}3.5±0.1​ 16.5±0.2\textbf{16.5}_{\pm 0.2}16.5±0.2​ 18.8±0.218.8_{\pm 0.2}18.8±0.2​
WRN-28-10 (200 epochs) Cutout 2.3±0.1\textbf{2.3}_{\pm 0.1}2.3±0.1​ 2.6±0.12.6_{\pm 0.1}2.6±0.1​ 14.9±0.2\textbf{14.9}_{\pm 0.2}14.9±0.2​ 16.9±0.116.9_{\pm 0.1}16.9±0.1​
WRN-28-10 (200 epochs) AA 2.1±<0.1\textbf{2.1}_{\pm <0.1}2.1±<0.1​ 2.3±0.12.3_{\pm 0.1}2.3±0.1​ 13.6±0.2\textbf{13.6}_{\pm 0.2}13.6±0.2​ 15.8±0.215.8_{\pm 0.2}15.8±0.2​
WRN-28-10 (1800 epochs) Basic 2.4±0.1\textbf{2.4}_{\pm 0.1}2.4±0.1​ 3.5±0.13.5_{\pm 0.1}3.5±0.1​ 16.3±0.2\textbf{16.3}_{\pm 0.2}16.3±0.2​ 19.1±0.119.1_{\pm 0.1}19.1±0.1​
WRN-28-10 (1800 epochs) Cutout 2.1±0.1\textbf{2.1}_{\pm 0.1}2.1±0.1​ 2.7±0.12.7_{\pm 0.1}2.7±0.1​ 14.0±0.1\textbf{14.0}_{\pm 0.1}14.0±0.1​ 17.4±0.117.4_{\pm 0.1}17.4±0.1​
WRN-28-10 (1800 epochs) AA 1.6±0.1\textbf{1.6}_{\pm 0.1}1.6±0.1​ 2.2±<0.1\textbf{2.2}_{\pm <0.1}2.2±<0.1​ 12.8±0.2\textbf{12.8}_{\pm 0.2}12.8±0.2​ 16.1±0.216.1_{\pm 0.2}16.1±0.2​
Shake-Shake (26 2x96d) Basic 2.3±<0.1\textbf{2.3}_{\pm <0.1}2.3±<0.1​ 2.7±0.12.7_{\pm 0.1}2.7±0.1​ 15.1±0.1\textbf{15.1}_{\pm 0.1}15.1±0.1​ 17.0±0.117.0_{\pm 0.1}17.0±0.1​
Shake-Shake (26 2x96d) Cutout 2.0±<0.1\textbf{2.0}_{\pm <0.1}2.0±<0.1​ 2.3±0.12.3_{\pm 0.1}2.3±0.1​ 14.2±0.2\textbf{14.2}_{\pm 0.2}14.2±0.2​ 15.7±0.215.7_{\pm 0.2}15.7±0.2​
Shake-Shake (26 2x96d) AA 1.6±<0.1\textbf{1.6}_{\pm <0.1}1.6±<0.1​ 1.9±0.11.9_{\pm 0.1}1.9±0.1​ 12.8±0.1\textbf{12.8}_{\pm 0.1}12.8±0.1​ 14.1±0.214.1_{\pm 0.2}14.1±0.2​
PyramidNet Basic 2.7±0.1\textbf{2.7}_{\pm 0.1}2.7±0.1​ 4.0±0.14.0_{\pm 0.1}4.0±0.1​ 14.6±0.4\textbf{14.6}_{\pm 0.4}14.6±0.4​ 19.7±0.319.7_{\pm 0.3}19.7±0.3​
PyramidNet Cutout 1.9±0.1\textbf{1.9}_{\pm 0.1}1.9±0.1​ 2.5±0.12.5_{\pm 0.1}2.5±0.1​ 12.6±0.2\textbf{12.6}_{\pm 0.2}12.6±0.2​ 16.4±0.116.4_{\pm 0.1}16.4±0.1​
PyramidNet AA 1.6±0.1\textbf{1.6}_{\pm 0.1}1.6±0.1​ 1.9±0.11.9_{\pm 0.1}1.9±0.1​ 11.6±0.1\textbf{11.6}_{\pm 0.1}11.6±0.1​ 14.6±0.114.6_{\pm 0.1}14.6±0.1​
PyramidNet+ShakeDrop Basic 2.1±0.1\textbf{2.1}_{\pm 0.1}2.1±0.1​ 2.5±0.12.5_{\pm 0.1}2.5±0.1​ 13.3±0.2\textbf{13.3}_{\pm 0.2}13.3±0.2​ 14.5±0.114.5_{\pm 0.1}14.5±0.1​
PyramidNet+ShakeDrop Cutout 1.6±<0.1\textbf{1.6}_{\pm<0.1}1.6±<0.1​ 1.9±0.11.9_{\pm 0.1}1.9±0.1​ 11.3±0.1\textbf{11.3}_{\pm 0.1}11.3±0.1​ 11.8±0.211.8_{\pm 0.2}11.8±0.2​
PyramidNet+ShakeDrop AA 1.4±<0.1\textbf{1.4}_{\pm<0.1}1.4±<0.1​ 1.6±<0.1\textbf{1.6}_{\pm <0.1}1.6±<0.1​ 10.3±0.1\textbf{10.3}_{\pm 0.1}10.3±0.1​ 10.6±0.110.6_{\pm 0.1}10.6±0.1​

Beyond CIFAR-{10, 100}, we have also evaluated SAM on the SVHN (Netzer et al., 2011) and Fashion-MNIST datasets (Xiao et al., 2017). Once again, SAM enables a simple WideResNet to achieve accuracy at or above the state-of-the-art for these datasets: 0.99% error for SVHN, and 3.59% for Fashion-MNIST. Details are available in appendix B.1.

在 CIFAR-{10, 100} 之外,我们也在 SVHN(Netzer et al., 2011)和 Fashion-MNIST(Xiao et al., 2017)上评估了 SAM。同样,SAM 能让一个简单的 WideResNet 达到或超过这些数据集上的当时最佳水平:SVHN 错误率 0.99%,Fashion-MNIST 错误率 3.59%。细节见附录 B.1。

To assess SAM's performance at larger scale, we apply it to ResNets (He et al., 2015) of different depths (50, 101, 152) trained on ImageNet (Deng et al., 2009). In this setting, following prior work (He et al., 2015; Szegedy et al., 2015), we resize and crop images to 224-pixel resolution, normalize them, and use batch size 4096, initial learning rate 1.0, cosine learning rate schedule, SGD optimizer with momentum 0.9, label smoothing of 0.1, and weight decay 0.0001. When applying SAM, we use ρ=0.05\rho = 0.05ρ=0.05 (determined via a grid search on ResNet-50 trained for 100 epochs). We train all models on ImageNet for up to 400 epochs using a Google Cloud TPUv3 and report top-1 and top-5 test error rates for each experimental condition (mean and 95% confidence interval across 5 independent runs).

为了在更大规模上评估 SAM,我们把它用到在 ImageNet(Deng et al., 2009)上训练、深度分别为 50、101、152 的 ResNet(He et al., 2015)上。在这一设定中,我们沿用先前工作(He et al., 2015;Szegedy et al., 2015),把图像缩放并裁剪到 224 像素分辨率后做归一化,批大小为 4096,初始学习率 1.0,采用余弦学习率计划,优化器为动量 0.9 的 SGD,标签平滑 0.1,权重衰减 0.0001。使用 SAM 时取 ρ=0.05\rho = 0.05ρ=0.05(由在 ResNet-50 上训练 100 个 epoch 的网格搜索确定)。所有模型都在 Google Cloud TPUv3 上最多训练 400 个 epoch,并报告每种实验条件的 top-1 和 top-5 测试错误率(5 次独立运行的均值和 95% 置信区间)。

As seen in Table 2, SAM again consistently improves performance, for example improving the ImageNet top-1 error rate of ResNet-152 from 20.3% to 18.4%. Furthermore, note that SAM enables increasing the number of training epochs while continuing to improve accuracy without overfitting. In contrast, the standard training procedure (without SAM) generally significantly overfits as training extends from 200 to 400 epochs.

如表 2 所示,SAM 再次一致地提升了表现,例如把 ResNet-152 的 ImageNet top-1 错误率从 20.3% 降到 18.4%。此外还可以看到,加上 SAM 后,增加训练 epoch 仍能继续提高准确率而不过拟合。相比之下,标准训练(不加 SAM)在从 200 个 epoch 延长到 400 个 epoch 时,通常会明显过拟合。

Table 2: Test error rates for ResNets trained on ImageNet, with and without SAM.

Model Epoch SAM Top-1 SAM Top-5 Standard Training (No SAM) Top-1 Standard Training (No SAM) Top-5
ResNet-50 100 22.5±0.1\textbf{22.5}_{\pm 0.1}22.5±0.1​ 6.28±0.086.28_{\pm 0.08}6.28±0.08​ 22.9±0.122.9_{\pm 0.1}22.9±0.1​ 6.62±0.116.62_{\pm 0.11}6.62±0.11​
200 21.4±0.1\textbf{21.4}_{\pm 0.1}21.4±0.1​ 5.82±0.035.82_{\pm 0.03}5.82±0.03​ 22.3±0.122.3_{\pm 0.1}22.3±0.1​ 6.37±0.046.37_{\pm 0.04}6.37±0.04​
400 20.9±0.1\textbf{20.9}_{\pm 0.1}20.9±0.1​ 5.51±0.035.51_{\pm 0.03}5.51±0.03​ 22.3±0.122.3_{\pm 0.1}22.3±0.1​ 6.40±0.066.40_{\pm 0.06}6.40±0.06​
ResNet-101 100 20.2±0.1\textbf{20.2}_{\pm 0.1}20.2±0.1​ 5.12±0.035.12_{\pm 0.03}5.12±0.03​ 21.2±0.121.2_{\pm 0.1}21.2±0.1​ 5.66±0.055.66_{\pm 0.05}5.66±0.05​
200 19.4±0.1\textbf{19.4}_{\pm 0.1}19.4±0.1​ 4.76±0.034.76_{\pm 0.03}4.76±0.03​ 20.9±0.120.9_{\pm 0.1}20.9±0.1​ 5.66±0.045.66_{\pm 0.04}5.66±0.04​
400 19.0±<0.01\textbf{19.0}_{\pm <0.01}19.0±<0.01​ 4.65±0.054.65_{\pm 0.05}4.65±0.05​ 22.3±0.122.3_{\pm 0.1}22.3±0.1​ 6.41±0.066.41_{\pm 0.06}6.41±0.06​
ResNet-152 100 19.2±<0.01\textbf{19.2}_{\pm <0.01}19.2±<0.01​ 4.69±0.044.69_{\pm 0.04}4.69±0.04​ 20.4±<0.020.4_{\pm <0.0}20.4±<0.0​ 5.39±0.065.39_{\pm 0.06}5.39±0.06​
200 18.5±0.1\textbf{18.5}_{\pm 0.1}18.5±0.1​ 4.37±0.034.37_{\pm 0.03}4.37±0.03​ 20.3±0.220.3_{\pm 0.2}20.3±0.2​ 5.39±0.075.39_{\pm 0.07}5.39±0.07​
400 18.4±<0.01\textbf{18.4}_{\pm <0.01}18.4±<0.01​ 4.35±0.044.35_{\pm 0.04}4.35±0.04​ 20.9±<0.020.9_{\pm <0.0}20.9±<0.0​ 5.84±0.075.84_{\pm 0.07}5.84±0.07​

表 2:在 ImageNet 上训练的 ResNet 测试错误率,对比使用和不使用 SAM。

Model Epoch SAM Top-1 SAM Top-5 Standard Training (No SAM) Top-1 Standard Training (No SAM) Top-5
ResNet-50 100 22.5±0.1\textbf{22.5}_{\pm 0.1}22.5±0.1​ 6.28±0.086.28_{\pm 0.08}6.28±0.08​ 22.9±0.122.9_{\pm 0.1}22.9±0.1​ 6.62±0.116.62_{\pm 0.11}6.62±0.11​
200 21.4±0.1\textbf{21.4}_{\pm 0.1}21.4±0.1​ 5.82±0.035.82_{\pm 0.03}5.82±0.03​ 22.3±0.122.3_{\pm 0.1}22.3±0.1​ 6.37±0.046.37_{\pm 0.04}6.37±0.04​
400 20.9±0.1\textbf{20.9}_{\pm 0.1}20.9±0.1​ 5.51±0.035.51_{\pm 0.03}5.51±0.03​ 22.3±0.122.3_{\pm 0.1}22.3±0.1​ 6.40±0.066.40_{\pm 0.06}6.40±0.06​
ResNet-101 100 20.2±0.1\textbf{20.2}_{\pm 0.1}20.2±0.1​ 5.12±0.035.12_{\pm 0.03}5.12±0.03​ 21.2±0.121.2_{\pm 0.1}21.2±0.1​ 5.66±0.055.66_{\pm 0.05}5.66±0.05​
200 19.4±0.1\textbf{19.4}_{\pm 0.1}19.4±0.1​ 4.76±0.034.76_{\pm 0.03}4.76±0.03​ 20.9±0.120.9_{\pm 0.1}20.9±0.1​ 5.66±0.045.66_{\pm 0.04}5.66±0.04​
400 19.0±<0.01\textbf{19.0}_{\pm <0.01}19.0±<0.01​ 4.65±0.054.65_{\pm 0.05}4.65±0.05​ 22.3±0.122.3_{\pm 0.1}22.3±0.1​ 6.41±0.066.41_{\pm 0.06}6.41±0.06​
ResNet-152 100 19.2±<0.01\textbf{19.2}_{\pm <0.01}19.2±<0.01​ 4.69±0.044.69_{\pm 0.04}4.69±0.04​ 20.4±<0.020.4_{\pm <0.0}20.4±<0.0​ 5.39±0.065.39_{\pm 0.06}5.39±0.06​
200 18.5±0.1\textbf{18.5}_{\pm 0.1}18.5±0.1​ 4.37±0.034.37_{\pm 0.03}4.37±0.03​ 20.3±0.220.3_{\pm 0.2}20.3±0.2​ 5.39±0.075.39_{\pm 0.07}5.39±0.07​
400 18.4±<0.01\textbf{18.4}_{\pm <0.01}18.4±<0.01​ 4.35±0.044.35_{\pm 0.04}4.35±0.04​ 20.9±<0.020.9_{\pm <0.0}20.9±<0.0​ 5.84±0.075.84_{\pm 0.07}5.84±0.07​

Finetuning

3.2 微调

Transfer learning by pretraining a model on a large related dataset and then finetuning on a smaller target dataset of interest has emerged as a powerful and widely used technique for producing high-quality models for a variety of different tasks. We show here that SAM once again offers considerable benefits in this setting, even when finetuning extremely large, state-of-the-art, already high-performing models.

先在一个较大的相关数据集上预训练,再在较小的目标数据集上微调,已经成为为多种任务得到高质量模型的常用做法。我们在此说明,即使是在微调已经非常大、表现已经很高的当时最佳模型时,SAM 同样能带来可观收益。

In particular, we apply SAM to finetuning EfficientNet-b7 (pretrained on ImageNet) and EfficientNet-L2 (pretrained on ImageNet plus unlabeled JFT; input resolution 475) (Tan & Le, 2019; Kornblith et al., 2018; Huang et al., 2018). We initialize these models to publicly available checkpoints ⁶ trained with RandAugment (84.7% accuracy on ImageNet) and NoisyStudent (88.2% accuracy on ImageNet), respectively. We finetune these models on each of several target datasets by training each model starting from the aforementioned checkpoint; please see the appendix for details of the hyperparameters used. We report the mean and 95% confidence interval of top-1 test error over 5 independent runs for each dataset.

具体而言,我们把 SAM 用在微调 EfficientNet-b7(在 ImageNet 上预训练)和 EfficientNet-L2(在 ImageNet 加上未标注的 JFT 上预训练;输入分辨率为 475)上(Tan & Le, 2019;Kornblith et al., 2018;Huang et al., 2018)。这两个模型分别初始化为公开的检查点⁶,前者用 RandAugment 训练(ImageNet 准确率 84.7%),后者用 NoisyStudent 训练(ImageNet 准确率 88.2%)。我们从上述检查点出发,在若干目标数据集上分别训练以完成微调;所用超参数细节见附录。对每个数据集,我们报告 5 次独立运行的 top-1 测试错误率均值及 95% 置信区间。

⁶ https://github.com/tensorflow/tpu/tree/master/models/official/efficientnet

As seen in Table 3, SAM uniformly improves performance relative to finetuning without SAM. Furthermore, in many cases, SAM yields novel state-of-the-art performance, including 0.30% error on CIFAR-10, 3.92% error on CIFAR-100, and 11.39% error on ImageNet.

如表 3 所示,相对不加 SAM 的微调,SAM 一律提升了表现。而且在许多情形中,SAM 达到了新的当时最佳水平,包括 CIFAR-10 上 0.30% 的错误率、CIFAR-100 上 3.92%,以及 ImageNet 上 11.39%。

Table 3: Top-1 error rates for finetuning EfficientNet-b7 (left; ImageNet pretraining only) and EfficientNet-L2 (right; pretraining on ImageNet plus additional data, such as JFT) on various downstream tasks. Previous state-of-the-art (SOTA) includes EfficientNet (EffNet) (Tan & Le, 2019), Gpipe (Huang et al., 2018), DAT (Ngiam et al., 2018), BiT-M/L (Kolesnikov et al., 2020), KDforAA (Wei et al., 2020), TBMSL-Net (Zhang et al., 2020), and ViT (Dosovitskiy et al., 2020).

Dataset EffNet-b7 + SAM EffNet-b7 Prev. SOTA (ImageNet only) EffNet-L2 + SAM EffNet-L2 Prev. SOTA
FGVC_Aircraft 6.80±0.066.80_{\pm 0.06}6.80±0.06​ 8.15±0.088.15_{\pm 0.08}8.15±0.08​ 5.3 (TBMSL-Net) 4.82±0.08\textbf{4.82}_{\pm 0.08}4.82±0.08​ 5.80±0.15.80_{\pm 0.1}5.80±0.1​ 5.3 (TBMSL-Net)
Flowers 0.63±0.02\textbf{0.63}_{\pm 0.02}0.63±0.02​ 1.16±0.051.16_{\pm 0.05}1.16±0.05​ 0.7 (BiT-M) 0.35±0.01\textbf{0.35}_{\pm 0.01}0.35±0.01​ 0.40±0.020.40_{\pm 0.02}0.40±0.02​ 0.37 (EffNet)
Oxford_IIIT_Pets 3.97±0.04\textbf{3.97}_{\pm 0.04}3.97±0.04​ 4.24±0.094.24_{\pm 0.09}4.24±0.09​ 4.1 (Gpipe) 2.90±0.04\textbf{2.90}_{\pm 0.04}2.90±0.04​ 3.08±0.043.08_{\pm 0.04}3.08±0.04​ 4.1 (Gpipe)
Stanford_Cars 5.18±0.025.18_{\pm 0.02}5.18±0.02​ 5.94±0.065.94_{\pm 0.06}5.94±0.06​ 5.0 (TBMSL-Net) 4.04±0.034.04_{\pm 0.03}4.04±0.03​ 4.93±0.044.93_{\pm 0.04}4.93±0.04​ 3.8 (DAT)
CIFAR-10 0.88±0.02\textbf{0.88}_{\pm 0.02}0.88±0.02​ 0.95±0.030.95_{\pm 0.03}0.95±0.03​ 1 (Gpipe) 0.30±0.01\textbf{0.30}_{\pm 0.01}0.30±0.01​ 0.34±0.020.34_{\pm 0.02}0.34±0.02​ 0.63 (BiT-L)
CIFAR-100 7.44±0.06\textbf{7.44}_{\pm 0.06}7.44±0.06​ 7.68±0.067.68_{\pm 0.06}7.68±0.06​ 7.83 (BiT-M) 3.92±0.06\textbf{3.92}_{\pm 0.06}3.92±0.06​ 4.07±0.084.07_{\pm 0.08}4.07±0.08​ 6.49 (BiT-L)
Birdsnap 13.64±0.15\textbf{13.64}_{\pm 0.15}13.64±0.15​ 14.30±0.1814.30_{\pm 0.18}14.30±0.18​ 15.7 (EffNet) 9.93±0.15\textbf{9.93}_{\pm 0.15}9.93±0.15​ 10.31±0.1510.31_{\pm 0.15}10.31±0.15​ 14.5 (DAT)
Food101 7.02±0.027.02_{\pm 0.02}7.02±0.02​ 7.17±0.037.17_{\pm 0.03}7.17±0.03​ 7.0 (Gpipe) 3.82±0.01\textbf{3.82}_{\pm 0.01}3.82±0.01​ 3.97±0.033.97_{\pm 0.03}3.97±0.03​ 4.7 (DAT)
ImageNet 15.14±0.0315.14_{\pm 0.03}15.14±0.03​ 15.315.315.3 14.2 (KDforAA) 11.39±0.02\textbf{11.39}_{\pm 0.02}11.39±0.02​ 11.811.811.8 11.4511.4511.45 (ViT)

表 3:在若干下游任务上微调 EfficientNet-b7(左;仅 ImageNet 预训练)和 EfficientNet-L2(右;在 ImageNet 及 JFT 等额外数据上预训练)的 top-1 错误率。先前的当时最佳(SOTA)包括 EfficientNet(EffNet)(Tan & Le, 2019)、Gpipe(Huang et al., 2018)、DAT(Ngiam et al., 2018)、BiT-M/L(Kolesnikov et al., 2020)、KDforAA(Wei et al., 2020)、TBMSL-Net(Zhang et al., 2020)以及 ViT(Dosovitskiy et al., 2020)。

Dataset EffNet-b7 + SAM EffNet-b7 Prev. SOTA (ImageNet only) EffNet-L2 + SAM EffNet-L2 Prev. SOTA
FGVC_Aircraft 6.80±0.066.80_{\pm 0.06}6.80±0.06​ 8.15±0.088.15_{\pm 0.08}8.15±0.08​ 5.3 (TBMSL-Net) 4.82±0.08\textbf{4.82}_{\pm 0.08}4.82±0.08​ 5.80±0.15.80_{\pm 0.1}5.80±0.1​ 5.3 (TBMSL-Net)
Flowers 0.63±0.02\textbf{0.63}_{\pm 0.02}0.63±0.02​ 1.16±0.051.16_{\pm 0.05}1.16±0.05​ 0.7 (BiT-M) 0.35±0.01\textbf{0.35}_{\pm 0.01}0.35±0.01​ 0.40±0.020.40_{\pm 0.02}0.40±0.02​ 0.37 (EffNet)
Oxford_IIIT_Pets 3.97±0.04\textbf{3.97}_{\pm 0.04}3.97±0.04​ 4.24±0.094.24_{\pm 0.09}4.24±0.09​ 4.1 (Gpipe) 2.90±0.04\textbf{2.90}_{\pm 0.04}2.90±0.04​ 3.08±0.043.08_{\pm 0.04}3.08±0.04​ 4.1 (Gpipe)
Stanford_Cars 5.18±0.025.18_{\pm 0.02}5.18±0.02​ 5.94±0.065.94_{\pm 0.06}5.94±0.06​ 5.0 (TBMSL-Net) 4.04±0.034.04_{\pm 0.03}4.04±0.03​ 4.93±0.044.93_{\pm 0.04}4.93±0.04​ 3.8 (DAT)
CIFAR-10 0.88±0.02\textbf{0.88}_{\pm 0.02}0.88±0.02​ 0.95±0.030.95_{\pm 0.03}0.95±0.03​ 1 (Gpipe) 0.30±0.01\textbf{0.30}_{\pm 0.01}0.30±0.01​ 0.34±0.020.34_{\pm 0.02}0.34±0.02​ 0.63 (BiT-L)
CIFAR-100 7.44±0.06\textbf{7.44}_{\pm 0.06}7.44±0.06​ 7.68±0.067.68_{\pm 0.06}7.68±0.06​ 7.83 (BiT-M) 3.92±0.06\textbf{3.92}_{\pm 0.06}3.92±0.06​ 4.07±0.084.07_{\pm 0.08}4.07±0.08​ 6.49 (BiT-L)
Birdsnap 13.64±0.15\textbf{13.64}_{\pm 0.15}13.64±0.15​ 14.30±0.1814.30_{\pm 0.18}14.30±0.18​ 15.7 (EffNet) 9.93±0.15\textbf{9.93}_{\pm 0.15}9.93±0.15​ 10.31±0.1510.31_{\pm 0.15}10.31±0.15​ 14.5 (DAT)
Food101 7.02±0.027.02_{\pm 0.02}7.02±0.02​ 7.17±0.037.17_{\pm 0.03}7.17±0.03​ 7.0 (Gpipe) 3.82±0.01\textbf{3.82}_{\pm 0.01}3.82±0.01​ 3.97±0.033.97_{\pm 0.03}3.97±0.03​ 4.7 (DAT)
ImageNet 15.14±0.0315.14_{\pm 0.03}15.14±0.03​ 15.315.315.3 14.2 (KDforAA) 11.39±0.02\textbf{11.39}_{\pm 0.02}11.39±0.02​ 11.811.811.8 11.4511.4511.45 (ViT)

Robustness to Label Noise

3.3 对标签噪声的稳健性

Table 4: Test accuracy on the clean test set for models trained on CIFAR-10 with noisy labels. Lower block is our implementation, upper block gives scores from the literature, per Jiang et al. (2019).

Method 20% 40% 60% 80%
Sanchez et al. (2019) 94.0 92.8 90.3 74.1
Zhang & Sabuncu (2018) 89.7 87.6 82.7 67.9
Lee et al. (2019) 87.1 81.8 75.4 -
Chen et al. (2019) 89.7 - - 52.3
Huang et al. (2019) 92.6 90.3 43.4 -
MentorNet (Jiang et al., 2017) 92.0 91.2 74.2 60.0
Mixup (Zhang et al., 2017) 94.0 91.5 86.8 76.9
MentorMix (Jiang et al., 2019) 95.6 94.2 91.3 81.0
SGD 84.8 68.8 48.2 26.2
Mixup 93.0 90.0 83.8 70.2
Bootstrap + Mixup 93.3 92.0 87.6 72.0
SAM 95.1 93.4 90.5 77.9
Bootstrap + SAM 95.4 94.2 91.8 79.9

表 4:在带噪标签的 CIFAR-10 上训练的模型,于干净测试集上的测试准确率。下半部分是我们的实现,上半部分是文献中的成绩,引自 Jiang et al.(2019)。

Method 20% 40% 60% 80%
Sanchez et al. (2019) 94.0 92.8 90.3 74.1
Zhang & Sabuncu (2018) 89.7 87.6 82.7 67.9
Lee et al. (2019) 87.1 81.8 75.4 -
Chen et al. (2019) 89.7 - - 52.3
Huang et al. (2019) 92.6 90.3 43.4 -
MentorNet (Jiang et al., 2017) 92.0 91.2 74.2 60.0
Mixup (Zhang et al., 2017) 94.0 91.5 86.8 76.9
MentorMix (Jiang et al., 2019) 95.6 94.2 91.3 81.0
SGD 84.8 68.8 48.2 26.2
Mixup 93.0 90.0 83.8 70.2
Bootstrap + Mixup 93.3 92.0 87.6 72.0
SAM 95.1 93.4 90.5 77.9
Bootstrap + SAM 95.4 94.2 91.8 79.9

The fact that SAM seeks out model parameters that are robust to perturbations suggests SAM's potential to provide robustness to noise in the training set (which would perturb the training loss landscape). Thus, we assess here the degree of robustness that SAM provides to label noise.

SAM 寻找对扰动稳健的模型参数,这暗示它也可能对训练集中的噪声(这会扰动训练损失面)具有稳健性。因此,我们在此评估 SAM 对标签噪声能提供怎样的稳健程度。

In particular, we measure the effect of applying SAM in the classical noisy-label setting for CIFAR-10, in which a fraction of the training set's labels are randomly flipped; the test set remains unmodified (i.e., clean). To ensure valid comparison to prior work, which often utilizes architectures specialized to the noisy-label setting, we train a simple model of similar size (ResNet-32) for 200 epochs, following (Jiang et al., 2019). We evaluate five variants of model training: standard SGD, SGD with Mixup (Zhang et al., 2017), SAM, and "bootstrapped" variants of SGD with Mixup and SAM (wherein the model is first trained as usual and then retrained from scratch on the labels predicted by the initially trained model). When applying SAM, we use ρ=0.1\rho=0.1ρ=0.1 for all noise levels except 80%, for which we use ρ=0.05\rho=0.05ρ=0.05 for more stable convergence. For the Mixup baselines, we tried all values of α∈{1,8,16,32}\alpha \in \{1, 8, 16, 32\}α∈{1,8,16,32} and conservatively report the best score for each noise level.

具体而言,我们在 CIFAR-10 的经典带噪标签设定中测量使用 SAM 的效果:训练集中有一定比例的标签被随机翻转,测试集保持不变(即干净)。为了与先前工作做有效比较——这些工作常常使用专门面向带噪标签设定的结构——我们训练一个规模相近的简单模型(ResNet-32),训练 200 个 epoch,设定遵循 Jiang et al.(2019)。我们评估五种训练变体:标准 SGD、带 Mixup 的 SGD(Zhang et al., 2017)、SAM,以及带 Mixup 的 SGD 与 SAM 的“自举”变体(先按常规训练模型,再用该模型预测的标签从头重新训练)。使用 SAM 时,除 80% 噪声水平取 ρ=0.05\rho=0.05ρ=0.05 以获得更稳定的收敛外,其余噪声水平均用 ρ=0.1\rho=0.1ρ=0.1。对 Mixup 基线,我们尝试了 α∈{1,8,16,32}\alpha \in \{1, 8, 16, 32\}α∈{1,8,16,32} 的全部取值,并保守地报告每个噪声水平下的最好成绩。

As seen in Table 4, SAM provides a high degree of robustness to label noise, on par with that provided by state-of-the art procedures that specifically target learning with noisy labels. Indeed, simply training a model with SAM outperforms all prior methods specifically targeting label noise robustness, with the exception of MentorMix (Jiang et al., 2019). However, simply bootstrapping SAM yields performance comparable to that of MentorMix (which is substantially more complex).

如表 4 所示,SAM 对标签噪声具有很高的稳健性,可以与专门针对带噪标签学习的当时最佳方法相当。事实上,只用 SAM 训练的模型已经超过了几乎所有专门针对标签噪声稳健性的先前方法,唯一的例外是 MentorMix(Jiang et al., 2019)。不过,只需对 SAM 做自举,就能达到与 MentorMix(其结构要复杂得多)相当的表现。

Sharpness and Generalization Through the Lens of SAM

4 从 SAM 看锐度与泛化

mmm-sharpness

4.1 mmm-锐度

Though our derivation of SAM defines the SAM objective over the entire training set, when utilizing SAM in practice, we compute the SAM update per-batch (as described in Algorithm 1) or even by averaging SAM updates computed independently per-accelerator (where each accelerator receives a subset of size mmm of a batch, as described in Section 3). This latter setting is equivalent to modifying the SAM objective (equation (1)) to sum over a set of independent \epsilonilon\epsilonilon\epsilonilon maximizations, each performed on a sum of per-data-point losses on a disjoint subset of mmm data points, rather than performing the \epsilonilon\epsilonilon\epsilonilon maximization over a global sum over the training set (which would be equivalent to setting mmm to the total training set size). We term the associated measure of sharpness of the loss landscape mmm-sharpness.

尽管我们推导 SAM 时,是把目标定义在整个训练集上,但实际使用时,我们按批次计算 SAM 更新(如算法 1 所述),甚至把在各个加速器上独立算出的 SAM 更新再平均(每个加速器拿到大小为 mmm 的批次子集,如第 3 节所述)。后一种设定等价于把 SAM 目标(式 (1))改成对一组独立的 ϵ\epsilonϵ 最大化求和,每次最大化都作用在 mmm 个数据点的逐点损失之和上,而这些子集互不相交;而不是在整个训练集的全局求和上做 ϵ\epsilonϵ 最大化(那相当于把 mmm 设为整个训练集大小)。我们把与之相应的损失面锐度度量称为 mmm-锐度。

To better understand the effect of mmm on SAM, we train a small ResNet on CIFAR-10 using SAM with a range of values of mmm. As seen in Figure 3 (middle), smaller values of mmm tend to yield models having better generalization ability. This relationship fortuitously aligns with the need to parallelize across multiple accelerators in order to scale training for many of today's models.

为了更好地理解 mmm 对 SAM 的影响,我们用一系列不同的 mmm 值,在 CIFAR-10 上用 SAM 训练一个小型 ResNet。如图 3(中)所示,较小的 mmm 往往得到泛化更好的模型。这一关系恰好与许多当今模型为了扩大训练规模而需要在多个加速器上并行相一致。

Intriguingly, the mmm-sharpness measure described above furthermore exhibits better correlation with models' actual generalization gaps as mmm decreases, as demonstrated by Figure 3 (right) ⁷ . In particular, this implies that mmm-sharpness with m<nm < nm<n yields a better predictor of generalization than the full-training-set measure suggested by Theorem 1 in Section 2 above, suggesting an interesting new avenue of future work for understanding generalization.

有意思的是,如上所述的 mmm-锐度度量,随着 mmm 减小,与模型真实泛化间隙的相关性也更好,如图 3(右)所示⁷。特别是,这意味着 m<nm < nm<n 时的 mmm-锐度,比第 2 节定理 1 所提示的那种在整个训练集上计算的度量,更能预测泛化,这为理解泛化提供了一个有意思的新方向。

⁷ We follow the rigorous framework of (Jiang et al., 2019), reporting the mutual information between the mmm-sharpness measure and generalization on the two publicly available tasks from the Predicting generalization in deep learning NeurIPS2020 competition. https://competitions.codalab.org/competitions/25301

⁷ 我们遵循 Jiang et al.(2019)的严格框架,报告 mmm-锐度度量与泛化之间的互信息,所用的是 NeurIPS 2020 竞赛 Predicting generalization in deep learning 中两个公开任务。https://competitions.codalab.org/competitions/25301

Hessian spectra during SGD versus SAM training, test error versus rho for different m, and predictive power of m-sharpness

Figure 3: (left) Evolution of the spectrum of the Hessian during training of a model with standard SGD (lefthand column) or SAM (righthand column). (middle) Test error as a function of ρ\rhoρ for different values of mmm. (right) Predictive power of mmm-sharpness for the generalization gap, for different values of mmm (higher means the sharpness measure is more correlated with actual generalization gap).

图 3:(左)在用标准 SGD(左列)或 SAM(右列)训练模型的过程中,Hessian 谱的变化。(中)不同 mmm 值下测试错误率随 ρ\rhoρ 的变化。(右)mmm-锐度对泛化间隙的预测能力,对应不同的 mmm(越高表示该锐度度量与真实泛化间隙的相关性越强)。

Hessian Spectra

4.2 Hessian 谱

Motivated by the connection between geometry of the loss landscape and generalization, we constructed SAM to seek out minima of the training loss landscape having both low loss value and low curvature (i.e., low sharpness). To further confirm that SAM does in fact find minima having low curvature, we compute the spectrum of the Hessian for a WideResNet40-10 trained on CIFAR-10 for 300 steps both with and without SAM (without batch norm, which tends to obscure interpretation of the Hessian), at different epochs during training. Due to the parameter space's dimensionality, we approximate the Hessian spectrum using the Lanczos algorithm of (Ghorbani et al., 2019).

受损失面几何与泛化之联系的启发,我们设计 SAM 去寻找训练损失面上一既低损失、又低曲率(也就是低锐度)的最小点。为了进一步确认 SAM 确实找到了低曲率的最小点,我们计算了在 CIFAR-10 上训练 300 步的 WideResNet40-10 的 Hessian 谱,分别对应使用和不使用 SAM 的情形(去掉批归一化,因为它往往会干扰对 Hessian 的解释),并在训练过程中的不同 epoch 取值。由于参数空间维数很高,我们用 Ghorbani et al.(2019)的 Lanczos 算法来近似 Hessian 谱。

Figure 3 (left) reports the resulting Hessian spectra. As expected, the models trained with SAM converge to minima having lower curvature, as seen in the overall distribution of eigenvalues, the maximum eigenvalue (λmax⁡\lambda_{\max}λmax​) at convergence (approximately 24 without SAM, 1.0 with SAM), and the bulk of the spectrum (the ratio λmax⁡/λ5\lambda_{\max} / \lambda_5λmax​/λ5​, commonly used as a proxy for sharpness (Jastrzebski et al., 2020); up to 11.4 without SAM, and 2.6 with SAM).

图 3(左)给出了得到的 Hessian 谱。正如所预期的,用 SAM 训练的模型收敛到曲率更低的最小点,这可以从特征值的整体分布、收敛时的最大特征值(λmax⁡\lambda_{\max}λmax​,不用 SAM 时约为 24,用 SAM 时为 1.0),以及谱的主体部分(常用 λmax⁡/λ5\lambda_{\max} / \lambda_5λmax​/λ5​ 作为锐度的代理(Jastrzebski et al., 2020);不用 SAM 时可达 11.4,用 SAM 时为 2.6)中看出。

Related Work

5 相关工作

The idea of searching for "flat" minima can be traced back to (Hochreiter & Schmidhuber, 1995), and its connection to generalization has seen significant study (Shirish Keskar et al., 2016; Dziugaite & Roy, 2017; Neyshabur et al., 2017; Dinh et al., 2017). In a recent large scale empirical study, (Jiang et al., 2019) studied 40 complexity measures and showed that a sharpness-based measure has highest correlation with generalization, which motivates penalizing sharpness. (Hochreiter & Schmidhuber, 1997) was perhaps the first paper on penalizing the sharpness, regularizing a notion related to Minimum Description Length (MDL). Other ideas which also penalize sharp minima include operating on diffused loss landscape (Mobahi, 2016) and regularizing local entropy (Chaudhari et al., 2016). Another direction is to not penalize the sharpness explicitly, but rather average weights during training; (Izmailov et al., 2018) showed that doing so can yield flatter minima that can also generalize better. However, the measures of sharpness proposed previously are difficult to compute and differentiate through. In contrast, SAM is highly scalable as it only needs two gradient computations per iteration. The concurrent work of (Sun et al., 2020) focuses on resilience to random and adversarial corruption to expose a model's vulnerabilities; this work is perhaps closest to ours. Our work has a different basis: we develop SAM motivated by a principled starting point in generalization, clearly demonstrate SAM's efficacy via rigorous large-scale empirical evaluation, and surface important practical and theoretical facets of the procedure (e.g., mmm-sharpness). The notion of all-layer margin introduced by (Wei & Ma, 2020) is closely related to this work; one is adversarial perturbation over the activations of a network and the other over its weights, and there is some coupling between these two quantities.

寻找“平坦”最小点的想法可以追溯到 Hochreiter & Schmidhuber(1995),它与泛化的联系也已有大量研究(Shirish Keskar et al., 2016;Dziugaite & Roy, 2017;Neyshabur et al., 2017;Dinh et al., 2017)。在一项近期的大规模实证研究中,Jiang et al.(2019)考察了 40 种复杂度度量,并表明基于锐度的度量与泛化的相关性最高,这为惩罚锐度提供了动机。Hochreiter & Schmidhuber(1997)或许是最早惩罚锐度的工作,它正则化了一种与最小描述长度(MDL)相关的量。其他同样惩罚尖锐最小点的想法包括在扩散后的损失面上操作(Mobahi, 2016),以及正则化局部熵(Chaudhari et al., 2016)。另一条路线并不显式惩罚锐度,而是在训练中对权重做平均;Izmailov et al.(2018)表明这样做可以得到更平坦、泛化也可能更好的最小点。不过,先前提出的锐度度量既难计算,也难对其求导。相比之下,SAM 每次迭代只需两次梯度计算,因而具有很好的可扩展性。Sun et al.(2020)的并行工作关注模型对随机与对抗性破坏的承受力,以暴露模型的薄弱之处;这项工作或许与我们最接近。我们的出发点不同:SAM 的发展始于对泛化的原则性考虑,我们通过严格的大规模经验评估清楚地展示了它的效果,并揭示了该方法在实践和理论上的若干重要侧面(例如 mmm-锐度)。Wei & Ma(2020)提出的全层间隔与本文关系密切:一个是对网络激活做对抗扰动,一个是对权重做对抗扰动,这两者之间存在一定耦合。

Discussion and Future Work

6 讨论与未来工作

In this work, we have introduced SAM, a novel algorithm that improves generalization by simultaneously minimizing loss value and loss sharpness; we have demonstrated SAM's efficacy through a rigorous large-scale empirical evaluation. We have surfaced a number of interesting avenues for future work. On the theoretical side, the notion of per-data-point sharpness yielded by mmm-sharpness (in contrast to global sharpness computed over the entire training set, as has typically been studied in the past) suggests an interesting new lens through which to study generalization. Methodologically, our results suggest that SAM could potentially be used in place of Mixup in robust or semi-supervised methods that currently rely on Mixup (giving, for instance, MentorSAM). We leave to future work a more in-depth investigation of these possibilities.

本文提出了 SAM 这一新算法,通过同时最小化损失值与损失锐度来提升泛化;我们用严格的大规模经验评估展示了它的效果。我们也提出了若干值得继续研究的方向。在理论方面,mmm-锐度给出的是逐数据点的锐度概念(而不是过去通常研究的、在整个训练集上计算的全局锐度),这为研究泛化提供了一个有意思的新视角。在方法方面,我们的结果提示,在目前依赖 Mixup 的稳健或半监督方法中,或许可以用 SAM 替代 Mixup(例如得到 MentorSAM)。对这些可能性的更深入考察,我们留待后续工作。

Acknowledgments

致谢

We thank our colleagues at Google — Atish Agarwala, Xavier Garcia, Dustin Tran, Yiding Jiang, Basil Mustafa, Samy Bengio — for their feedback and insightful discussions. We also thank the JAX and FLAX teams for going above and beyond to support our implementation. We are grateful to Sven Gowal for his help in replicating EfficientNet using JAX, and Justin Gilmer for his implementation of the Lanczos algorithm ⁸ used to generate the Hessian spectra. We thank Niru Maheswaranathan for his matplotlib mastery. We also thank David Samuel for providing a PyTorch implementation of SAM ⁹ .

我们感谢 Google 的同事 Atish Agarwala、Xavier Garcia、Dustin Tran、Yiding Jiang、Basil Mustafa、Samy Bengio 给予的反馈和有启发的讨论。我们也感谢 JAX 和 FLAX 团队为我们的实现提供了超出常规的支持。感谢 Sven Gowal 帮助用 JAX 复现 EfficientNet,以及 Justin Gilmer 提供用于生成 Hessian 谱的 Lanczos 算法实现⁸。感谢 Niru Maheswaranathan 在 matplotlib 上的帮助。我们也感谢 David Samuel 提供了 SAM 的 PyTorch 实现⁹。

⁸ https://github.com/google/spectral-density

⁹ https://github.com/davda54/sam

Appendix

A 附录

PAC Bayesian Generalization Bound

A.1 PAC-Bayesian 泛化界

Below, we state a generalization bound based on sharpness.

下面给出一个基于锐度的泛化界。

Theorem 1

定理 1

For any ρ>0\rho>0ρ>0 and any distribution D\mathscr{D}D, with probability 1−δ1-\delta1−δ over the choice of the training set S∼D\mathcal{S}\sim \mathscr{D}S∼D, \begin{equation}
L_\mathscrD(\mathbf{w}) \leq \max_{|\mathbf{\epsilonilon}|2 \leq \rho} L\mathcalS(\mathbf{w} + \mathbf{\epsilonilon}) +\sqrt{\frac{k\log\left(1+\frac{|\mathbf{w}|2^2}{\rho^2}\left(1+\sqrt{\frac{\log(n)}{k}}\right)^2\right) + 4\log\frac{n}{\delta} + \tildeO(1)}{n-1}}
\end{equation} where n=∣S∣n=|\mathcal{S}|n=∣S∣, kkk is the number of parameters and we assumed $L
\mathscr{D}(\mathbf{w}) \leq \mathbb{E}{\epsilonilon_i \sim \mathcal{N}(0,\rho)}[L\mathscr{D}(\mathbf{w}+\mathbf{\epsilonilon})]$.

对任意 ρ>0\rho>0ρ>0 和任意分布 D\mathscr{D}D,在训练集 S∼D\mathcal{S}\sim \mathscr{D}S∼D 的选择上,以概率 1−δ1-\delta1−δ 有

LD(w)≤max⁡∥ϵ∥2≤ρLS(w+ϵ)+klog⁡(1+∥w∥22ρ2(1+log⁡(n)k)2)+4log⁡nδ+O~(1)n−1L_\mathscr{D}(\mathbf{w}) \leq \max_{\|\mathbf{\epsilon}\|_2 \leq \rho} L_\mathcal{S}(\mathbf{w} + \mathbf{\epsilon}) +\sqrt{\frac{k\log\left(1+\frac{\|\mathbf{w}\|_2^2}{\rho^2}\left(1+\sqrt{\frac{\log(n)}{k}}\right)^2\right) + 4\log\frac{n}{\delta} + \tilde{O}(1)}{n-1}}LD​(w)≤∥ϵ∥2​≤ρmax​LS​(w+ϵ)+n−1klog(1+ρ2∥w∥22​​(1+klog(n)​​)2)+4logδn​+O~(1)​​

其中 n=∣S∣n=|\mathcal{S}|n=∣S∣,kkk 是参数个数,并且我们假定 LD(w)≤Eϵi∼N(0,ρ)[LD(w+ϵ)]L_\mathscr{D}(\mathbf{w}) \leq \mathbb{E}_{\epsilon_i \sim \mathcal{N}(0,\rho)}[L_\mathscr{D}(\mathbf{w}+\mathbf{\epsilon})]LD​(w)≤Eϵi​∼N(0,ρ)​[LD​(w+ϵ)]。

The condition LD(w)≤E\epsiloniloni∼N(0,ρ)[LD(w+\epsilonilon)]L_\mathscr{D}(\mathbf{w}) \leq \mathbb{E}_{\epsilonilon_i \sim \mathcal{N}(0,\rho)}[L_\mathscr{D}(\mathbf{w}+\mathbf{\epsilonilon})]LD​(w)≤E\epsiloniloni​∼N(0,ρ)​[LD​(w+\epsilonilon)] means that adding Gaussian perturbation should not decrease the test error. This is expected to hold in practice for the final solution but does not necessarily hold for any w\mathbf{w}w.

条件 LD(w)≤Eϵi∼N(0,ρ)[LD(w+ϵ)]L_\mathscr{D}(\mathbf{w}) \leq \mathbb{E}_{\epsilon_i \sim \mathcal{N}(0,\rho)}[L_\mathscr{D}(\mathbf{w}+\mathbf{\epsilon})]LD​(w)≤Eϵi​∼N(0,ρ)​[LD​(w+ϵ)] 意味着加上高斯扰动不应降低测试误差。对最终得到的解,这在实践中有望成立,但对任意 w\mathbf{w}w 并不必然成立。

Proof

证明

First, note that the right hand side of the bound in the theorem statement is lower bounded by klog⁡(1+∥w∥22/ρ2)/(4n)\sqrt{k\log(1+\|\mathbf{w}\|_2^2/\rho^2)/(4n)}klog(1+∥w∥22​/ρ2)/(4n)​ which is greater than 1 when ∥w∥22>ρ2(exp⁡(4n/k)−1)\|\mathbf{w}\|_2^2 >\rho^2(\exp(4n/k)-1)∥w∥22​>ρ2(exp(4n/k)−1). In that case, the right hand side becomes greater than 1 in which case the inequality holds trivially. Therefore, in the rest of the proof, we only consider the case when ∥w∥22≤ρ2(exp⁡(4n/k)−1)\|\mathbf{w}\|_2^2 \leq \rho^2(\exp(4n/k)-1)∥w∥22​≤ρ2(exp(4n/k)−1). The proof technique we use here is inspired from (Chatterji et al., 2020). Using PAC-Bayesian generalization bound (McAllester, 1999) and following (Dziugaite & Roy, 2017), the following generalization bound holds for any prior P\mathscr{P}P over parameters with probability 1−δ1-\delta1−δ over the choice of the training set S\mathcal{S}S, for any posterior Q\mathscr{Q}Q over parameters: \begin{equation}
\mathbbE_{\mathbf{w}\sim \mathscrQ}[L_\mathscrD(\mathbf{w})] \leq \mathbbE_{\mathbf{w}\sim \mathscrQ}[L_\mathcalS(\mathbf{w})] +\sqrt{\frac{KL(\mathscrQ||\mathscrP) + \log \frac{n}{\delta}}{2(n-1)}}
\end{equation} Moreover, if P=N(μP,σP2I)\mathscr{P}=\mathcal{N}(\mathbf{\mu}_P,\sigma_P^2 \mathbf{I})P=N(μP​,σP2​I) and Q=N(μQ,σQ2I)\mathscr{Q}=\mathcal{N}(\mathbf{\mu}_Q,\sigma_Q^2 \mathbf{I})Q=N(μQ​,σQ2​I), then the KL divergence can be written as follows: \begin{equation}
KL(\mathscrP||\mathscrQ) = \frac{1}{2}\bigg[\frac{k\sigma_Q^2+|\mathbf{\mu}_P-\mathbf{\mu}_Q|_2^2}{\sigma_P^2}- k + k\log\left(\frac{\sigma_P^2}{\sigma_Q^2}\right)\bigg]
\end{equation} Given a posterior standard deviation σQ\sigma_QσQ​, one could choose a prior standard deviation σP\sigma_PσP​ to minimize the above KL divergence and hence the generalization bound by taking the derivative¹ of the above KL with respect to σP\sigma_PσP​ and setting it to zero. We would then have σP∗2=σQ2+∥μP−μQ∥22/k{\sigma^*_P}^2=\sigma_Q^2+\|\mathbf{\mu}_P-\mathbf{\mu}_Q\|_2^2/kσP∗​2=σQ2​+∥μP​−μQ​∥22​/k. However, since σP\sigma_PσP​ should be chosen before observing the training data S\mathcal{S}S and μQ\mathbf{\mu}_QμQ​,σQ\sigma_QσQ​ could depend on S\mathcal{S}S, we are not allowed to optimize σP\sigma_PσP​ in this way. Instead, one can have a set of predefined values for σP\sigma_PσP​ and pick the best one in that set. See (Langford & Caruana, 2002) for the discussion around this technique. Given fixed a,b>0a,b>0a,b>0, let T={cexp⁡((1−j)/k)∣j∈N}T=\{c\exp((1-j)/k)| j\in \mathbb{N}\}T={cexp((1−j)/k)∣j∈N} be that predefined set of values for σP2\sigma_P^2σP2​. If for any j∈Nj\in \mathbb{N}j∈N, the above PAC-Bayesian bound holds for σP2=cexp⁡((1−j)/k)\sigma_P^2=c\exp((1-j)/k)σP2​=cexp((1−j)/k) with probability 1−δj1-\delta_j1−δj​ with δj=6δπ2j2\delta_j=\frac{6\delta}{\pi^2j^2}δj​=π2j26δ​, then by the union bound, all above bounds hold simultaneously with probability at least 1−∑j=1∞6δπ2j2=1−δ1-\sum_{j=1}^\infty\frac{6\delta}{\pi^2j^2} =1-\delta1−∑j=1∞​π2j26δ​=1−δ. Let σQ=ρ\sigma_Q=\rhoσQ​=ρ, μQ=w\mathbf{\mu}_Q=\mathbf{w}μQ​=w and μP=0\mathbf{\mu}_P=\mathbf{0}μP​=0. Therefore, we have: \begin{equation}\label{eq:weight_upper}
\sigma_Q^2+|\mathbf{\mu}_P-\mathbf{\mu}_Q|_2^2/k \leq \rho^2 + |\mathbf{w}|_2^2/k \leq \rho^2(1+\exp(4n/k))
\end{equation} We now consider the bound that corresponds to j=⌊1−klog⁡((ρ2+∥w∥22/k)/c)⌋j=\lfloor 1 - k\log((\rho^2 + \|\mathbf{w}\|_2^2/k)/c)\rfloorj=⌊1−klog((ρ2+∥w∥22​/k)/c)⌋. We can ensure that j∈Nj\in \mathbb{N}j∈N using inequality (4) and by setting c=ρ2(1+exp⁡(4n/k))c=\rho^2(1+\exp(4n/k))c=ρ2(1+exp(4n/k)). Furthermore, for σP2=cexp⁡((1−j)/k)\sigma_P^2=c\exp((1-j)/k)σP2​=cexp((1−j)/k), we have: \begin{equation}
\rho^2 + |\mathbf{w}|_2^2/k \leq \sigma_P^2 \leq \exp(1/k) \left(\rho^2 + |\mathbf{w}|_2^2/k\right)
\end{equation} Therefore, using the above value for σP\sigma_PσP​, KL divergence can be bounded as follows: \begin{align}
KL(\mathscrP||\mathscrQ) &=\frac{1}{2}\bigg[\frac{k\sigma_Q^2+|\mathbf{\mu}_P-\mathbf{\mu}_Q|_2^2}{\sigma_P^2}- k + k\log\left(\frac{\sigma_P^2}{\sigma_Q^2}\right)\bigg]\
&\leq \frac{1}{2}\bigg[\frac{k(\rho^2 + |\mathbf{w}|_2^2/k)}{\rho^2 + |\mathbf{w}|_2^2/k}- k + k\log\left(\frac{\exp(1/k) \left(\rho^2 + |\mathbf{w}|2^2/k\right)}{\rho^2}\right)\bigg]\
&=\frac{1}{2}\bigg[k\log\left(\frac{\exp(1/k) \left(\rho^2 + |\mathbf{w}|2^2/k\right)}{\rho^2}\right)\bigg]\
&= \frac{1}{2}\bigg[1+k\log\left(1+\frac{|\mathbf{w}|2^2}{k\sigma_Q^2}\right)\bigg]
\end{align} Given the bound that corresponds to jjj holds with probability 1−δj1-\delta_j1−δj​ for δj=6δπ2j2\delta_j=\frac{6\delta}{\pi^2j^2}δj​=π2j26δ​, the log term in the bound can be written as: \begin{align*}
\log\frac{n}{\delta_j} &= \log\frac{n}{\delta} + \log\frac{\pi^2j^2}{6}\
&\leq \log\frac{n}{\delta} + \log\frac{\pi^2k^2\log^2(c/(\rho^2 + |\mathbf{w}|2^2/k))}{6}\
&\leq \log\frac{n}{\delta} + \log\frac{\pi^2k^2\log^2(c/\rho^2)}{6}\
&\leq \log\frac{n}{\delta} + \log\frac{\pi^2k^2\log^2(1+\exp(4n/k))}{6}\
&\leq \log\frac{n}{\delta} + \log\frac{\pi^2k^2(2 +4n/k)^2}{6}\
&\leq \log \frac{n}{\delta} + 2 \log\left(6n + 3 k\right)
\end{align*} Therefore, the generalization bound can be written as follows: \begin{equation}\label{eq:almost_theorem}
\mathbbE
{\epsilonilon_i \sim \mathcalN(0,\sigma)}[L
\mathscrD(\mathbf{w}+\mathbf{\epsilonilon})] \leq \mathbbE
{\epsilonilon_i \sim \mathcalN(0,\sigma)}[L
\mathcalS(\mathbf{w}+\mathbf{\epsilonilon})] +\sqrt{\frac{\frac{1}{4}k\log\left(1+\frac{|\mathbf{w}|_2^2}{k\sigma^2}\right) + \frac{1}{4}+\log \frac{n}{\delta} + 2\log\left(6n + 3k\right)}{n-1}}
\end{equation} In the above bound, we have \epsiloniloni∼N(0,σ)\epsilonilon_i \sim \mathcal{N}(0,\sigma)\epsiloniloni​∼N(0,σ). Therefore, ∥\epsilonilon∥22\|\mathbf{\epsilonilon}\|_2^2∥\epsilonilon∥22​ has chi-square distribution and by Lemma 1 in (Laurent & Massart, 2000), we have that for any positive ttt: \begin{equation}
P(|\mathbf{\epsilonilon}|2^2 - k\sigma^2 \geq 2\sigma^2\sqrt{kt} + 2t\sigma^2) \leq \exp(-t)
\end{equation} Therefore, with probability 1−1/n1-1/\sqrt{n}1−1/n​ we have that: ∥\epsilonilon∥22≤σ2(2ln⁡(n)+k+2kln⁡(n))≤σ2k(1+ln⁡(n)k)2≤ρ2\|\mathbf{\epsilonilon}\|_2^2\leq \sigma^2(2\ln(\sqrt{n})+k + 2\sqrt{k\ln(\sqrt{n})}) \leq \sigma^2k\left(1+\sqrt{\frac{\ln(n)}{k}}\right)^2\leq \rho^2∥\epsilonilon∥22​≤σ2(2ln(n​)+k+2kln(n​)​)≤σ2k(1+kln(n)​​)2≤ρ2 Substituting the above value for σ\sigmaσ back to the inequality and using theorem's assumption gives us following inequality: \begin{align*}
L_\mathscrD(\mathbf{w}) &\leq (1-1/\sqrt{n})\max
{|\mathbf{\epsilonilon}|2 \leq \rho} L\mathcalS(\mathbf{w} + \mathbf{\epsilonilon}) + 1/\sqrt{n}\
&+\sqrt{\frac{\frac{1}{4}k\log\left(1+\frac{|\mathbf{w}|2^2}{\rho^2}\left(1+\sqrt{\frac{\log(n)}{k}}\right)^2\right) + \log\frac{n}{\delta} + 2\log\left(6n + 3k\right)}{n-1}}\
&\leq \max
{|\mathbf{\epsilonilon}|2 \leq \rho} L\mathcalS(\mathbf{w} + \mathbf{\epsilonilon}) + \
&+\sqrt{\frac{k\log\left(1+\frac{|\mathbf{w}|_2^2}{\rho^2}\left(1+\sqrt{\frac{\log(n)}{k}}\right)^2\right) + 4\log\frac{n}{\delta} + 8\log\left(6n + 3k\right)}{n-1}}
\end{align*}

首先注意到,定理陈述中上界的右边有下界 klog⁡(1+∥w∥22/ρ2)/(4n)\sqrt{k\log(1+\|\mathbf{w}\|_2^2/\rho^2)/(4n)}klog(1+∥w∥22​/ρ2)/(4n)​,而当 ∥w∥22>ρ2(exp⁡(4n/k)−1)\|\mathbf{w}\|_2^2 >\rho^2(\exp(4n/k)-1)∥w∥22​>ρ2(exp(4n/k)−1) 时该下界大于 1。此时右边也大于 1,不等式平凡成立。因此,证明的其余部分只考虑 ∥w∥22≤ρ2(exp⁡(4n/k)−1)\|\mathbf{w}\|_2^2 \leq \rho^2(\exp(4n/k)-1)∥w∥22​≤ρ2(exp(4n/k)−1) 的情形。这里使用的证明技术受到 Chatterji et al.(2020)的启发。利用 PAC-Bayesian 泛化界(McAllester, 1999)并遵循 Dziugaite & Roy(2017),对参数上的任意先验 P\mathscr{P}P,在训练集 S\mathcal{S}S 的选择上以概率 1−δ1-\delta1−δ,对参数上的任意后验 Q\mathscr{Q}Q,下列泛化界成立:

Ew∼Q[LD(w)]≤Ew∼Q[LS(w)]+KL(Q∣∣P)+log⁡nδ2(n−1)\mathbb{E}_{\mathbf{w}\sim \mathscr{Q}}[L_\mathscr{D}(\mathbf{w})] \leq \mathbb{E}_{\mathbf{w}\sim \mathscr{Q}}[L_\mathcal{S}(\mathbf{w})] +\sqrt{\frac{KL(\mathscr{Q}||\mathscr{P}) + \log \frac{n}{\delta}}{2(n-1)}}Ew∼Q​[LD​(w)]≤Ew∼Q​[LS​(w)]+2(n−1)KL(Q∣∣P)+logδn​​​

此外,若 P=N(μP,σP2I)\mathscr{P}=\mathcal{N}(\mathbf{\mu}_P,\sigma_P^2 \mathbf{I})P=N(μP​,σP2​I) 且 Q=N(μQ,σQ2I)\mathscr{Q}=\mathcal{N}(\mathbf{\mu}_Q,\sigma_Q^2 \mathbf{I})Q=N(μQ​,σQ2​I),则 KL 散度可以写成:

KL(P∣∣Q)=12[kσQ2+∥μP−μQ∥22σP2−k+klog⁡(σP2σQ2)]KL(\mathscr{P}||\mathscr{Q}) = \frac{1}{2}\bigg[\frac{k\sigma_Q^2+\|\mathbf{\mu}_P-\mathbf{\mu}_Q\|_2^2}{\sigma_P^2}- k + k\log\left(\frac{\sigma_P^2}{\sigma_Q^2}\right)\bigg]KL(P∣∣Q)=21​[σP2​kσQ2​+∥μP​−μQ​∥22​​−k+klog(σQ2​σP2​​)]

给定后验标准差 σQ\sigma_QσQ​,本可以通过对上述 KL 关于 σP\sigma_PσP​ 求导并令其为零,来选择先验标准差 σP\sigma_PσP​,以最小化该 KL 散度从而最小化泛化界。¹ 于是会有 σP∗2=σQ2+∥μP−μQ∥22/k{\sigma^*_P}^2=\sigma_Q^2+\|\mathbf{\mu}_P-\mathbf{\mu}_Q\|_2^2/kσP∗​2=σQ2​+∥μP​−μQ​∥22​/k。然而,由于 σP\sigma_PσP​ 必须在观察到训练数据 S\mathcal{S}S 之前选定,而 μQ\mathbf{\mu}_QμQ​、σQ\sigma_QσQ​ 可能依赖于 S\mathcal{S}S,我们不能用这种方式优化 σP\sigma_PσP​。相反,可以为 σP\sigma_PσP​ 准备一组预先给定的取值,再从中挑选最好的一个。关于这一技术的讨论见 Langford & Caruana(2002)。给定固定的 a,b>0a,b>0a,b>0,令 T={cexp⁡((1−j)/k)∣j∈N}T=\{c\exp((1-j)/k)| j\in \mathbb{N}\}T={cexp((1−j)/k)∣j∈N} 作为 σP2\sigma_P^2σP2​ 的那组预先给定取值。如果对任意 j∈Nj\in \mathbb{N}j∈N,当 σP2=cexp⁡((1−j)/k)\sigma_P^2=c\exp((1-j)/k)σP2​=cexp((1−j)/k) 时上述 PAC-Bayesian 界以概率 1−δj1-\delta_j1−δj​ 成立,其中 δj=6δπ2j2\delta_j=\frac{6\delta}{\pi^2j^2}δj​=π2j26δ​,则由并界,所有这些界同时成立的概率至少为 1−∑j=1∞6δπ2j2=1−δ1-\sum_{j=1}^\infty\frac{6\delta}{\pi^2j^2} =1-\delta1−∑j=1∞​π2j26δ​=1−δ。令 σQ=ρ\sigma_Q=\rhoσQ​=ρ,μQ=w\mathbf{\mu}_Q=\mathbf{w}μQ​=w,μP=0\mathbf{\mu}_P=\mathbf{0}μP​=0。于是有:

σQ2+∥μP−μQ∥22/k≤ρ2+∥w∥22/k≤ρ2(1+exp⁡(4n/k))(4)\sigma_Q^2+\|\mathbf{\mu}_P-\mathbf{\mu}_Q\|_2^2/k \leq \rho^2 + \|\mathbf{w}\|_2^2/k \leq \rho^2(1+\exp(4n/k)) \tag{4}σQ2​+∥μP​−μQ​∥22​/k≤ρ2+∥w∥22​/k≤ρ2(1+exp(4n/k))(4)

我们现在考虑对应于 j=⌊1−klog⁡((ρ2+∥w∥22/k)/c)⌋j=\lfloor 1 - k\log((\rho^2 + \|\mathbf{w}\|_2^2/k)/c)\rfloorj=⌊1−klog((ρ2+∥w∥22​/k)/c)⌋ 的那个界。利用不等式 (4) 并取 c=ρ2(1+exp⁡(4n/k))c=\rho^2(1+\exp(4n/k))c=ρ2(1+exp(4n/k)),可以保证 j∈Nj\in \mathbb{N}j∈N。此外,对 σP2=cexp⁡((1−j)/k)\sigma_P^2=c\exp((1-j)/k)σP2​=cexp((1−j)/k),有:

ρ2+∥w∥22/k≤σP2≤exp⁡(1/k)(ρ2+∥w∥22/k)\rho^2 + \|\mathbf{w}\|_2^2/k \leq \sigma_P^2 \leq \exp(1/k) \left(\rho^2 + \|\mathbf{w}\|_2^2/k\right)ρ2+∥w∥22​/k≤σP2​≤exp(1/k)(ρ2+∥w∥22​/k)

因此,使用上述 σP\sigma_PσP​,可以把 KL 散度界定为:

\begin{align}
KL(\mathscr{P}||\mathscr{Q}) &=\frac{1}{2}\bigg[\frac{k\sigma_Q^2+|\mathbf{\mu}_P-\mathbf{\mu}_Q|_2^2}{\sigma_P^2}- k + k\log\left(\frac{\sigma_P^2}{\sigma_Q^2}\right)\bigg]\
&\leq \frac{1}{2}\bigg[\frac{k(\rho^2 + |\mathbf{w}|_2^2/k)}{\rho^2 + |\mathbf{w}|_2^2/k}- k + k\log\left(\frac{\exp(1/k) \left(\rho^2 + |\mathbf{w}|_2^2/k\right)}{\rho^2}\right)\bigg]\
&=\frac{1}{2}\bigg[k\log\left(\frac{\exp(1/k) \left(\rho^2 + |\mathbf{w}|_2^2/k\right)}{\rho^2}\right)\bigg]\
&= \frac{1}{2}\bigg[1+k\log\left(1+\frac{|\mathbf{w}|_2^2}{k\sigma_Q^2}\right)\bigg]
\end{align}

由于对应于 jjj 的界以概率 1−δj1-\delta_j1−δj​ 成立,其中 δj=6δπ2j2\delta_j=\frac{6\delta}{\pi^2j^2}δj​=π2j26δ​,界中的对数项可以写成:

\begin{align*}
\log\frac{n}{\delta_j} &= \log\frac{n}{\delta} + \log\frac{\pi^2j^2}{6}\
&\leq \log\frac{n}{\delta} + \log\frac{\pi^2k^2\log^2(c/(\rho^2 + |\mathbf{w}|_2^2/k))}{6}\
&\leq \log\frac{n}{\delta} + \log\frac{\pi^2k^2\log^2(c/\rho^2)}{6}\
&\leq \log\frac{n}{\delta} + \log\frac{\pi^2k^2\log^2(1+\exp(4n/k))}{6}\
&\leq \log\frac{n}{\delta} + \log\frac{\pi^2k^2(2 +4n/k)^2}{6}\
&\leq \log \frac{n}{\delta} + 2 \log\left(6n + 3 k\right)
\end{align*}

因此,泛化界可以写成:

Eϵi∼N(0,σ)[LD(w+ϵ)]≤Eϵi∼N(0,σ)[LS(w+ϵ)]+14klog⁡(1+∥w∥22kσ2)+14+log⁡nδ+2log⁡(6n+3k)n−1(5)\mathbb{E}_{\epsilon_i \sim \mathcal{N}(0,\sigma)}[L_\mathscr{D}(\mathbf{w}+\mathbf{\epsilon})] \leq \mathbb{E}_{\epsilon_i \sim \mathcal{N}(0,\sigma)}[L_\mathcal{S}(\mathbf{w}+\mathbf{\epsilon})] +\sqrt{\frac{\frac{1}{4}k\log\left(1+\frac{\|\mathbf{w}\|_2^2}{k\sigma^2}\right) + \frac{1}{4}+\log \frac{n}{\delta} + 2\log\left(6n + 3k\right)}{n-1}} \tag{5}Eϵi​∼N(0,σ)​[LD​(w+ϵ)]≤Eϵi​∼N(0,σ)​[LS​(w+ϵ)]+n−141​klog(1+kσ2∥w∥22​​)+41​+logδn​+2log(6n+3k)​​(5)

在上述界中,ϵi∼N(0,σ)\epsilon_i \sim \mathcal{N}(0,\sigma)ϵi​∼N(0,σ)。因此 ∥ϵ∥22\|\mathbf{\epsilon}\|_2^2∥ϵ∥22​ 服从卡方分布,并由 Laurent & Massart(2000)的引理 1,对任意正数 ttt 有:

P(∥ϵ∥22−kσ2≥2σ2kt+2tσ2)≤exp⁡(−t)P(\|\mathbf{\epsilon}\|_2^2 - k\sigma^2 \geq 2\sigma^2\sqrt{kt} + 2t\sigma^2) \leq \exp(-t)P(∥ϵ∥22​−kσ2≥2σ2kt​+2tσ2)≤exp(−t)

于是,以概率 1−1/n1-1/\sqrt{n}1−1/n​ 有:

∥ϵ∥22≤σ2(2ln⁡(n)+k+2kln⁡(n))≤σ2k(1+ln⁡(n)k)2≤ρ2\|\mathbf{\epsilon}\|_2^2\leq \sigma^2(2\ln(\sqrt{n})+k + 2\sqrt{k\ln(\sqrt{n})}) \leq \sigma^2k\left(1+\sqrt{\frac{\ln(n)}{k}}\right)^2\leq \rho^2∥ϵ∥22​≤σ2(2ln(n​)+k+2kln(n​)​)≤σ2k(1+kln(n)​​)2≤ρ2

把上述 σ\sigmaσ 代回不等式,并利用定理的假定,便得到:

\begin{align*}
L_\mathscr{D}(\mathbf{w}) &\leq (1-1/\sqrt{n})\max_{|\mathbf{\epsilon}|2 \leq \rho} L\mathcal{S}(\mathbf{w} + \mathbf{\epsilon}) + 1/\sqrt{n}\
&+\sqrt{\frac{\frac{1}{4}k\log\left(1+\frac{|\mathbf{w}|2^2}{\rho^2}\left(1+\sqrt{\frac{\log(n)}{k}}\right)^2\right) + \log\frac{n}{\delta} + 2\log\left(6n + 3k\right)}{n-1}}\
&\leq \max
{|\mathbf{\epsilon}|2 \leq \rho} L\mathcal{S}(\mathbf{w} + \mathbf{\epsilon}) + \
&+\sqrt{\frac{k\log\left(1+\frac{|\mathbf{w}|_2^2}{\rho^2}\left(1+\sqrt{\frac{\log(n)}{k}}\right)^2\right) + 4\log\frac{n}{\delta} + 8\log\left(6n + 3k\right)}{n-1}}
\end{align*}

¹ Despite the nonconvexity of the function here in σP2\sigma_P^2σP2​, it has a unique stationary point which happens to be its minimizer.

¹ 尽管这里的函数对 σP2\sigma_P^2σP2​ 是非凸的,它有唯一驻点,并且该驻点恰好是极小值点。

Additional Experimental Results

B 补充实验结果

SVHN and Fashion-MNIST

B.1 SVHN 与 Fashion-MNIST

We report in table 5 results obtained on SVHN and Fashion-MNIST datasets. On these datasets, SAM allows a simple WideResNet to reach or push state-of-the-art accuracy (0.99% error rate for SVHN, 3.59% for Fashion-MNIST).

我们在表 5 中报告 SVHN 和 Fashion-MNIST 上的结果。在这两个数据集上,SAM 能让一个简单的 WideResNet 达到或推进当时最佳准确率(SVHN 错误率 0.99%,Fashion-MNIST 错误率 3.59%)。

For SVHN, we used all the available data (73257 digits for training set + 531131 additional samples). For auto-augment, we use the best policy found on this dataset as described in (Cubuk et al., 2018) plus cutout (Devries & Taylor, 2017). For Fashion-MNIST, the auto-augmentation line correspond to cutout only.

对 SVHN,我们使用了全部可用数据(训练集 73257 个数字,外加 531131 个额外样本)。对 auto-augment,我们采用 Cubuk et al.(2018)在该数据集上找到的最佳策略,再加上 cutout(Devries & Taylor, 2017)。对 Fashion-MNIST,所谓 auto-augmentation 一行实际上只对应 cutout。

Table 5: Results on SVHN and Fashion-MNIST.

Model Augmentation SVHN SAM SVHN Baseline Fashion-MNIST SAM Fashion-MNIST Baseline
Wide-ResNet-28-10 Basic 1.42±0.021.42_{\pm 0.02}1.42±0.02​ 1.58±0.031.58_{\pm 0.03}1.58±0.03​ 3.98±0.053.98_{\pm 0.05}3.98±0.05​ 4.57±0.074.57_{\pm 0.07}4.57±0.07​
Wide-ResNet-28-10 Auto augment 0.99±0.010.99_{\pm 0.01}0.99±0.01​ 1.14±0.041.14_{\pm 0.04}1.14±0.04​ 3.61±0.063.61_{\pm 0.06}3.61±0.06​ 3.86±0.143.86_{\pm 0.14}3.86±0.14​
Shake-Shake (26 2x96d) Basic 1.44±0.021.44_{\pm 0.02}1.44±0.02​ 1.58±0.051.58_{\pm 0.05}1.58±0.05​ 3.97±0.093.97_{\pm 0.09}3.97±0.09​ 4.37±0.064.37_{\pm 0.06}4.37±0.06​
Shake-Shake (26 2x96d) Auto augment 1.07±0.021.07_{\pm 0.02}1.07±0.02​ 1.03±0.021.03_{\pm 0.02}1.03±0.02​ 3.59±0.013.59_{\pm 0.01}3.59±0.01​ 3.76±0.073.76_{\pm 0.07}3.76±0.07​

表 5:SVHN 与 Fashion-MNIST 上的结果。

Model Augmentation SVHN SAM SVHN Baseline Fashion-MNIST SAM Fashion-MNIST Baseline
Wide-ResNet-28-10 Basic 1.42±0.021.42_{\pm 0.02}1.42±0.02​ 1.58±0.031.58_{\pm 0.03}1.58±0.03​ 3.98±0.053.98_{\pm 0.05}3.98±0.05​ 4.57±0.074.57_{\pm 0.07}4.57±0.07​
Wide-ResNet-28-10 Auto augment 0.99±0.010.99_{\pm 0.01}0.99±0.01​ 1.14±0.041.14_{\pm 0.04}1.14±0.04​ 3.61±0.063.61_{\pm 0.06}3.61±0.06​ 3.86±0.143.86_{\pm 0.14}3.86±0.14​
Shake-Shake (26 2x96d) Basic 1.44±0.021.44_{\pm 0.02}1.44±0.02​ 1.58±0.051.58_{\pm 0.05}1.58±0.05​ 3.97±0.093.97_{\pm 0.09}3.97±0.09​ 4.37±0.064.37_{\pm 0.06}4.37±0.06​
Shake-Shake (26 2x96d) Auto augment 1.07±0.021.07_{\pm 0.02}1.07±0.02​ 1.03±0.021.03_{\pm 0.02}1.03±0.02​ 3.59±0.013.59_{\pm 0.01}3.59±0.01​ 3.76±0.073.76_{\pm 0.07}3.76±0.07​

Experiment Details

C 实验细节

Hyperparameters for Experiments

C.1 实验超参数

We report in table 6 the hyper-parameters selected by gridsearch for the CIFAR experiments, and the ones for SVHN and Fashion-MNIST in table 7. For CIFAR-10, CIFAR-100, SVHN and Fashion-MNIST, we use a batch size of 256 and determine the learning rate and weight decay used to train each model via a joint grid search prior to applying SAM; all other model hyperparameter values are identical to those used in prior work.

我们在表 6 中报告 CIFAR 实验经网格搜索选定的超参数,SVHN 和 Fashion-MNIST 的超参数见表 7。对 CIFAR-10、CIFAR-100、SVHN 和 Fashion-MNIST,我们使用批大小 256,并在应用 SAM 之前通过联合网格搜索确定每个模型的学习率和权重衰减;其余模型超参数与先前工作相同。

For the Imagenet results (ResNet models), the models are trained for 100, 200 or 400 epochs on Google Cloud TPUv3 32 cores with a batch size of 4096. The initial learning rate is set to 1.0 and decayed using a cosine schedule. Weight decay is set to 0.0001 with SGD optimizer and momentum = 0.9.

ImageNet 上的结果(ResNet 模型)是在 Google Cloud TPUv3 的 32 个核心上,用批大小 4096 分别训练 100、200 或 400 个 epoch 得到的。初始学习率设为 1.0,并按余弦计划衰减。权重衰减为 0.0001,优化器为动量 0.9 的 SGD。

Table 6: Hyper-parameter used to produce the CIFAR-{10,100} results

CIFAR Dataset LR WD ρ\rhoρ (CIFAR-10) ρ\rhoρ (CIFAR-100)
WRN 28-10 (200 epochs) 0.1 0.0005 0.05 0.1
WRN 28-10 (1800 epochs) 0.05 0.001 0.05 0.1
WRN 26-2x6 ShakeShake 0.02 0.0010 0.02 0.05
Pyramid vanilla 0.05 0.0005 0.05 0.2
Pyramid ShakeDrop (CIFAR-10) 0.02 0.0005 0.05 -
Pyramid ShakeDrop (CIFAR-100) 0.05 0.0005 - 0.05

表 6:用于得到 CIFAR-{10,100} 结果的超参数

CIFAR Dataset LR WD ρ\rhoρ (CIFAR-10) ρ\rhoρ (CIFAR-100)
WRN 28-10 (200 epochs) 0.1 0.0005 0.05 0.1
WRN 28-10 (1800 epochs) 0.05 0.001 0.05 0.1
WRN 26-2x6 ShakeShake 0.02 0.0010 0.02 0.05
Pyramid vanilla 0.05 0.0005 0.05 0.2
Pyramid ShakeDrop (CIFAR-10) 0.02 0.0005 0.05 -
Pyramid ShakeDrop (CIFAR-100) 0.05 0.0005 - 0.05

Table 7: Hyper-parameter used to produce the SVHN and Fashion-MNIST results

Dataset Model LR WD ρ\rhoρ
SVHN WRN 0.01 0.0005 0.01
ShakeShake 0.01 0.0005 0.01
Fashion WRN 0.1 0.0005 0.05
ShakeShake 0.1 0.0005 0.02

表 7:用于得到 SVHN 与 Fashion-MNIST 结果的超参数

Dataset Model LR WD ρ\rhoρ
SVHN WRN 0.01 0.0005 0.01
ShakeShake 0.01 0.0005 0.01
Fashion WRN 0.1 0.0005 0.05
ShakeShake 0.1 0.0005 0.02

Finally, for the noisy label experiments, we also found ρ\rhoρ by gridsearch, computing the accuracy on a (non-noisy) validation set composed of a random subset of 10% of the usual CIFAR training samples. We report the validation accuracy of the bootstrapped version of SAM for different levels of noise and different ρ\rhoρ in table 8.

最后,对带噪标签实验,我们也用网格搜索确定 ρ\rhoρ,在由通常 CIFAR 训练样本中随机抽出 10% 组成的(无噪声)验证集上计算准确率。表 8 报告了自举版 SAM 在不同噪声水平和不同 ρ\rhoρ 下的验证准确率。

Table 8: Validation accuracy of the bootstrapped-SAM for different levels of noise and different ρ\rhoρ

ρ\rhoρ 20% 40% 60% 80%
0 15.0% 31.2% 52.3% 73.5%
0.01 13.7% 28.7% 50.1% 72.9%
0.02 12.8% 27.8% 48.9% 73.1%
0.05 11.6% 25.6% 47.1% 21.0%
0.1 4.6% 6.0% 8.7% 56.1%
0.2 5.3% 7.4% 23.3% 77.1%
0.5 17.6% 40.9% 80.1% 89.9%

表 8:自举版 SAM 在不同噪声水平和不同 ρ\rhoρ 下的验证准确率

ρ\rhoρ 20% 40% 60% 80%
0 15.0% 31.2% 52.3% 73.5%
0.01 13.7% 28.7% 50.1% 72.9%
0.02 12.8% 27.8% 48.9% 73.1%
0.05 11.6% 25.6% 47.1% 21.0%
0.1 4.6% 6.0% 8.7% 56.1%
0.2 5.3% 7.4% 23.3% 77.1%
0.5 17.6% 40.9% 80.1% 89.9%

Finetuning Details

C.2 微调细节

Weights are initialized to the values provided by the publicly available checkpoints, except the last dense layer, which change size to accomodate the new number of classes, that is randomly initialized. We train all models with weight decay 1e−51e^{-5}1e−5 as suggested in (Tan & Le, 2019), but we reduce the learning rate to 0.016 as the models tend to diverge for higher values. We use a batch size of 1024 on Google Cloud TPUv3 64 cores and cosine learning rate decay. Because other works train with batch size of 256, we train for 5k steps instead of 20k. We freeze the batch norm statistics and use them for normalization, effectively using the batch norm as we would at test time ^(10) . We train the models using SGD with momentum 0.9 and cosine learning rate decay. For Efficientnet-L2, we use this time a batch size 512 to save memory and adjusted the number of training steps accordingly. For CIFAR, we use the same autoaugment policy as in the previous experiments. We do not use data augmentation for the other datasets, applying the same preprocessing as for the Imagenet experiments. We also scale down the learning rate to 0.008 as the batch size is now twice as small. We used Google Cloud TPUv3 128 cores. All other parameters stay the same. For Imagenet, we trained both models from checkpoint for 10 epochs using a learning rate of 0.1 and ρ=0.05\rho=0.05ρ=0.05. We do not randomly initialize the last layer as we did for the other datasets, but instead use the weights included in the checkpoint.

除最后一层稠密层因类别数变化而改为随机初始化外,权重都初始化为公开检查点中的取值。我们按 Tan & Le(2019)的建议,用权重衰减 1×10−51\times 10^{-5}1×10−5 训练所有模型,但把学习率降到 0.016,因为更大的值往往会使模型发散。我们在 Google Cloud TPUv3 的 64 个核心上使用批大小 1024,并采用余弦学习率衰减。由于其他工作常用批大小 256,我们训练 5k 步而不是 20k 步。我们冻结批归一化统计量并用它们做归一化,相当于按测试时的方式使用批归一化^(10)。模型用动量 0.9 的 SGD 训练,学习率按余弦衰减。对 EfficientNet-L2,为节省内存,这次使用批大小 512,并相应调整训练步数。对 CIFAR,我们使用与前面实验相同的 AutoAugment 策略。对其余数据集不使用数据增强,预处理与 ImageNet 实验相同。由于批大小变为原来的一半,我们也把学习率降到 0.008。这次使用了 Google Cloud TPUv3 的 128 个核心。其余参数保持不变。对 ImageNet,我们从检查点出发把两个模型都训练 10 个 epoch,学习率为 0.1,ρ=0.05\rho=0.05ρ=0.05。与其他数据集不同,我们不随机初始化最后一层,而是使用检查点中已有的权重。

^(10) We found anecdotal evidence that this makes the finetuning more robust to overtraining.

^(10) 我们有一些零星证据表明,这样做能让微调对过训练更稳健。

Experimental results with ρ=0.05\rho=0.05ρ=0.05

C.3 全部使用 ρ=0.05\rho=0.05ρ=0.05 的实验结果

A big sensitivity to the choice of hyper-parameters would make a method less easy to use. To demonstrate that SAM performs even when ρ\rhoρ is not finely tuned, we compiled the table for the CIFAR and the finetuning experiments using ρ=0.05\rho=0.05ρ=0.05. Please note that we already used ρ=0.05\rho=0.05ρ=0.05 for all Imagenet experiments. We report those scores in table 9 and 10.

如果对超参数过于敏感,方法就会不那么好用。为了说明即使 ρ\rhoρ 没有精细调节,SAM 仍然有效,我们用 ρ=0.05\rho=0.05ρ=0.05 汇总了 CIFAR 和微调实验的表格。需要说明的是,所有 ImageNet 实验本来就已经使用 ρ=0.05\rho=0.05ρ=0.05。这些结果报告在表 9 和表 10 中。

Table 9: Results for the CIFAR-10/CIFAR-100 experiments, using ρ=0.05\rho=0.05ρ=0.05 for all models/datasets/augmentations

Model Augmentation CIFAR-10 ρ=0.05\rho=0.05ρ=0.05 CIFAR-10 SGD CIFAR-100 ρ=0.05\rho=0.05ρ=0.05 CIFAR-100 SGD
WRN-28-10 (200 epochs) Basic 2.7 3.5 16.5 18.8
WRN-28-10 (200 epochs) Cutout 2.3 2.6 14.9 16.9
WRN-28-10 (200 epochs) AA 2.1 2.3 13.6 15.8
WRN-28-10 (1800 epochs) Basic 2.4 3.5 16.3 19.1
WRN-28-10 (1800 epochs) Cutout 2.1 2.7 14.0 17.4
WRN-28-10 (1800 epochs) AA 1.6 2.2 12.8 16.1
Shake-Shake (26 2x96d) Basic 2.4 2.7 15.1 17.0
Shake-Shake (26 2x96d) Cutout 2.0 2.3 14.2 15.7
Shake-Shake (26 2x96d) AA 1.7 1.9 12.8 14.1
PyramidNet Basic 2.1 4.0 15.4 19.7
PyramidNet Cutout 1.6 2.5 13.1 16.4
PyramidNet AA 1.4 1.9 12.1 14.6
PyramidNet+ShakeDrop Basic 2.1 2.5 13.3 14.5
PyramidNet+ShakeDrop Cutout 1.6 1.9 11.3 11.8
PyramidNet+ShakeDrop AA 1.4 1.6 10.3 10.6

表 9:CIFAR-10/CIFAR-100 实验结果,所有模型、数据集和增强都使用 ρ=0.05\rho=0.05ρ=0.05

Model Augmentation CIFAR-10 ρ=0.05\rho=0.05ρ=0.05 CIFAR-10 SGD CIFAR-100 ρ=0.05\rho=0.05ρ=0.05 CIFAR-100 SGD
WRN-28-10 (200 epochs) Basic 2.7 3.5 16.5 18.8
WRN-28-10 (200 epochs) Cutout 2.3 2.6 14.9 16.9
WRN-28-10 (200 epochs) AA 2.1 2.3 13.6 15.8
WRN-28-10 (1800 epochs) Basic 2.4 3.5 16.3 19.1
WRN-28-10 (1800 epochs) Cutout 2.1 2.7 14.0 17.4
WRN-28-10 (1800 epochs) AA 1.6 2.2 12.8 16.1
Shake-Shake (26 2x96d) Basic 2.4 2.7 15.1 17.0
Shake-Shake (26 2x96d) Cutout 2.0 2.3 14.2 15.7
Shake-Shake (26 2x96d) AA 1.7 1.9 12.8 14.1
PyramidNet Basic 2.1 4.0 15.4 19.7
PyramidNet Cutout 1.6 2.5 13.1 16.4
PyramidNet AA 1.4 1.9 12.1 14.6
PyramidNet+ShakeDrop Basic 2.1 2.5 13.3 14.5
PyramidNet+ShakeDrop Cutout 1.6 1.9 11.3 11.8
PyramidNet+ShakeDrop AA 1.4 1.6 10.3 10.6

Table 10: Results for the finetuning experiments, using ρ=0.05\rho=0.05ρ=0.05 for all datasets.

Dataset EfficientNet-b7 + SAM (optimal) EfficientNet-b7 + SAM (ρ=0.05\rho=0.05ρ=0.05) EfficientNet-b7
FGVC_Aircraft 6.80 7.06 8.15
Flowers 0.63 0.81 1.16
Oxford_IIIT_Pets 3.97 4.15 4.24
Stanford_Cars 5.18 5.57 5.94
CIFAR-10 0.88 0.88 0.95
CIFAR-100 7.44 7.56 7.68
Birdsnap 13.64 13.64 14.30
Food101 7.02 7.06 7.17

表 10:微调实验结果,所有数据集都使用 ρ=0.05\rho=0.05ρ=0.05。

Dataset EfficientNet-b7 + SAM (optimal) EfficientNet-b7 + SAM (ρ=0.05\rho=0.05ρ=0.05) EfficientNet-b7
FGVC_Aircraft 6.80 7.06 8.15
Flowers 0.63 0.81 1.16
Oxford_IIIT_Pets 3.97 4.15 4.24
Stanford_Cars 5.18 5.57 5.94
CIFAR-10 0.88 0.88 0.95
CIFAR-100 7.44 7.56 7.68
Birdsnap 13.64 13.64 14.30
Food101 7.02 7.06 7.17

Ablation of the Second Order Terms

C.4 二阶项消融

As described in section 2, computing the gradient of the sharpness aware objective yield some second order terms that are more expensive to compute. To analyze this ablation more in depth, we trained a WideResNet-40x2 on CIFAR-10 using SAM with and without discarding the second order terms during training. We report the cosine similarity of the two updates in figure 4, along the training trajectory of both experiments. We also report the training error rate (evaluated at w+\epsilonilon^(w)\mathbf{w}+\hat{\mathbf{\epsilonilon}}(\mathbf{w})w+\epsilonilon^​(w)) and the test error rate (evaluated at w\mathbf{w}w).

如第 2 节所述,计算锐度感知目标的梯度会得到一些计算更昂贵的二阶项。为了更仔细地分析这一消融,我们在 CIFAR-10 上用 WideResNet-40x2 训练 SAM,分别保留和丢掉训练中的二阶项。我们在图 5 中报告两种更新沿两条训练轨迹的余弦相似度,同时也报告训练错误率(在 w+ϵ^(w)\mathbf{w}+\hat{\mathbf{\epsilon}}(\mathbf{w})w+ϵ^(w) 处评估)和测试错误率(在 w\mathbf{w}w 处评估),见图 4。

We observe that during the first half of the training, discarding the second order terms does not impact the general direction of the training, as the cosine similarity between the first and second order updates are very close to 1. However, when the model nears convergence, the similarity between both types of updates becomes weaker. Fortunately, the model trained without the second order terms reaches a lower test error, showing that the most efficient method is also the one providing the best generalization on this example. The reason for this is quite unclear and should be analyzed in follow up work.

我们观察到,在训练的前半段,丢掉二阶项并不影响训练的总体方向,一阶与二阶更新的余弦相似度非常接近 1。不过,当模型接近收敛时,两类更新之间的相似性变弱。有利的是,丢掉二阶项训练出的模型测试错误率更低,说明在这个例子上,更高效的方法同时也给出了更好的泛化。其中原因还不清楚,应当在后续工作中分析。

Training and test error for the first-order and second-order versions of the SAM algorithm

Figure 4: Training and test error for the first and second order version of the algorithm.

图 4:算法一阶与二阶版本的训练和测试错误率。

Cosine similarity between the first-order and second-order SAM updates during training

Figure 5: Cosine similarity between the first and second order updates.

图 5:一阶更新与二阶更新之间的余弦相似度。

Choice of p-norm

C.5 ppp-范数的选择

Our theorem is derived for p=2p=2p=2, although generalizations can be considered for p∈[1,+∞]p \in [1, +\infty]p∈[1,+∞] (the expression of the bound becoming way more involved). Empirically, we validate that the choice p=2p=2p=2 is optimal by training a wide ResNet on CIFAR-10 with SAM for p=∞p=\inftyp=∞ (in which case we have \epsilonilon^(w)=ρ\sign(∇wLS(w))\hat{\mathbf{\epsilonilon}}(\mathbf{w}) = \rho \sign{(\nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w}))}\epsilonilon^​(w)=ρ\sign(∇w​LS​(w))) and p=2p=2p=2 (giving \epsilonilon^(w)=ρ∣∣∇wLS(w)∣∣22(∇wLS(w))\hat{\mathbf{\epsilonilon}}(\mathbf{w}) = \frac{\rho}{||\nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w})||_2^2} (\nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w}))\epsilonilon^​(w)=∣∣∇w​LS​(w)∣∣22​ρ​(∇w​LS​(w))). We do not consider the case p=1p=1p=1 which would give us a perturbation on a single weight. As an additional ablation study, we also use random weight perturbations of a fixed Euclidean norm: \epsilonilon^(w)=ρ∣∣z∣∣22z\hat{\mathbf{\epsilonilon}}(\mathbf{w}) = \frac{\rho}{||\mathbf{z}||_2^2} \mathbf{z}\epsilonilon^​(w)=∣∣z∣∣22​ρ​z with z∼N(0,Id)\mathbf{z} \sim \mathcal{N}(\mathbf{0},\mathbf{I}_d)z∼N(0,Id​). We report the test accuracy of the model in figure 5.

我们的定理是对 p=2p=2p=2 推导的,不过也可以考虑 p∈[1,+∞]p \in [1, +\infty]p∈[1,+∞] 的推广(此时上界的表达式会复杂得多)。经验上,我们通过在 CIFAR-10 上用 SAM 训练一个宽 ResNet 来验证 p=2p=2p=2 是更好的选择,其中 p=∞p=\inftyp=∞ 时有 ϵ^(w)=ρsign(∇wLS(w))\hat{\mathbf{\epsilon}}(\mathbf{w}) = \rho \mathrm{sign}{(\nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w}))}ϵ^(w)=ρsign(∇w​LS​(w)),p=2p=2p=2 时有 ϵ^(w)=ρ∣∣∇wLS(w)∣∣22(∇wLS(w))\hat{\mathbf{\epsilon}}(\mathbf{w}) = \frac{\rho}{||\nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w})||_2^2} (\nabla_{\mathbf{w}} L_\mathcal{S}(\mathbf{w}))ϵ^(w)=∣∣∇w​LS​(w)∣∣22​ρ​(∇w​LS​(w))。我们不考虑 p=1p=1p=1 的情形,因为它只会扰动单个权重。作为额外的消融,我们还使用固定欧几里得范数的随机权重扰动:ϵ^(w)=ρ∣∣z∣∣22z\hat{\mathbf{\epsilon}}(\mathbf{w}) = \frac{\rho}{||\mathbf{z}||_2^2} \mathbf{z}ϵ^(w)=∣∣z∣∣22​ρ​z,其中 z∼N(0,Id)\mathbf{z} \sim \mathcal{N}(\mathbf{0},\mathbf{I}_d)z∼N(0,Id​)。模型的测试准确率见图 6。

Test accuracy of a WideResNet trained on CIFAR-10 with SAM under different perturbation norms

Figure 6: Test accuracy for a WideResNet trained on CIFAR-10 with SAM, for different perturbation norms.

图 6:在 CIFAR-10 上用 SAM 训练 WideResNet 时,不同扰动范数下的测试准确率。

We observe that adversarial perturbations outperform random perturbations, and that using p=2p=2p=2 yield superior accuracy on this example.

我们观察到,对抗扰动优于随机扰动,并且在这个例子上 p=2p=2p=2 给出了更高的准确率。

Several Iterations in the Inner Maximization

C.6 内层最大化的多次迭代

To empirically verify that the linearization of the inner problem is sensible, we trained a WideResNet on the CIFAR datasets using a variant of SAM that performs several iterations of projected gradient ascent to estimate max⁡\epsilonilonL(w+\epsilonilon)\max_{\mathbf{\epsilonilon}} L(\mathbf{w}+\mathbf{\epsilonilon})max\epsilonilon​L(w+\epsilonilon). We report the evolution of max⁡\epsilonilonL(w+\epsilonilon)−L(w)\max_{\mathbf{\epsilonilon}} L(\mathbf{w}+\mathbf{\epsilonilon}) - L(\mathbf{w})max\epsilonilon​L(w+\epsilonilon)−L(w) during training (where LLL stands for the training error rate computed on the current batch) in Figure 6, along with the test accuracy and the estimated sharpness (max⁡\epsilonilonL(w+\epsilonilon)−L(w)\max_{\mathbf{\epsilonilon}} L(\mathbf{w}+\mathbf{\epsilonilon}) - L(\mathbf{w})max\epsilonilon​L(w+\epsilonilon)−L(w)) at the end of training in Table 11; we report means and standard deviations across 20 runs.

为了从经验上验证对内层问题做线性化是合理的,我们在 CIFAR 数据集上用一种 SAM 变体训练 WideResNet:该变体用若干步投影梯度上升来估计 max⁡ϵL(w+ϵ)\max_{\mathbf{\epsilon}} L(\mathbf{w}+\mathbf{\epsilon})maxϵ​L(w+ϵ)。我们在图 7 中报告训练过程中 max⁡ϵL(w+ϵ)−L(w)\max_{\mathbf{\epsilon}} L(\mathbf{w}+\mathbf{\epsilon}) - L(\mathbf{w})maxϵ​L(w+ϵ)−L(w) 的变化(这里的 LLL 表示在当前批次上计算的训练错误率),并在表 11 中报告训练结束时的测试准确率与估计锐度(max⁡ϵL(w+ϵ)−L(w)\max_{\mathbf{\epsilon}} L(\mathbf{w}+\mathbf{\epsilon}) - L(\mathbf{w})maxϵ​L(w+ϵ)−L(w));均值和标准差来自 20 次运行。

For most of the training, one projected gradient step (as used in standard SAM) is sufficient to obtain a good approximation of the \epsilonilon\mathbf{\epsilonilon}\epsilonilon found with multiple inner maximization steps. We however observe that this approximation becomes weaker near convergence, where doing several iterations of projected gradient ascent yields a better \epsilonilon\mathbf{\epsilonilon}\epsilonilon (for example, on CIFAR-10, the maximum loss found on each batch is about 3% more when doing 5 steps of inner maximization, compared to when doing a single step). That said, as seen in Table 11, the test accuracy is not strongly affected by the number of inner maximization iterations, though on CIFAR-100 it does seem that several steps outperform a single step in a statistically significant way.

在训练的大部分时间里,一步投影梯度(也就是标准 SAM 所用的做法)已经足以很好近似由多次内层最大化得到的 ϵ\mathbf{\epsilon}ϵ。不过我们观察到,在接近收敛时,这一近似会变弱,此时多做几步投影梯度上升能得到更好的 ϵ\mathbf{\epsilon}ϵ(例如在 CIFAR-10 上,做 5 步内层最大化时,每个批次上找到的最大损失大约比只做 1 步高 3%)。尽管如此,如表 11 所示,测试准确率并不强烈依赖于内层最大化的迭代次数,不过在 CIFAR-100 上,多步看起来确实以统计显著的方式优于单步。

Evolution of estimated sharpness versus training step for different numbers of inner projected gradient steps

Figure 7: Evolution of max⁡\epsilonilonL(w+\epsilonilon)−L(w)\max_{\mathbf{\epsilonilon}} L(\mathbf{w}+\mathbf{\epsilonilon}) - L(\mathbf{w})max\epsilonilon​L(w+\epsilonilon)−L(w) vs. training step, for different numbers of inner projected gradient steps.

图 7:不同内层投影梯度步数下,max⁡ϵL(w+ϵ)−L(w)\max_{\mathbf{\epsilon}} L(\mathbf{w}+\mathbf{\epsilon}) - L(\mathbf{w})maxϵ​L(w+ϵ)−L(w) 随训练步数的变化。

Table 11: Test error rate and estimated sharpness (max⁡ϵL(w+ϵ)−L(w)\max_\epsilon L(w+\epsilon) - L(w)maxϵ​L(w+ϵ)−L(w)) at the end of the training.

Number of projected gradient steps CIFAR-10 Test error CIFAR-10 Estimated sharpness CIFAR-100 Test error CIFAR-100 Estimated sharpness
1 2.77±0.032.77_{\pm 0.03}2.77±0.03​ 0.17±0.030.17_{\pm 0.03}0.17±0.03​ 16.72±0.0816.72_{\pm 0.08}16.72±0.08​ 0.82±0.050.82_{\pm 0.05}0.82±0.05​
2 2.76±0.032.76_{\pm 0.03}2.76±0.03​ 0.82±0.030.82_{\pm 0.03}0.82±0.03​ 16.59±0.0816.59_{\pm 0.08}16.59±0.08​ 1.83±0.051.83_{\pm 0.05}1.83±0.05​
3 2.73±0.042.73_{\pm 0.04}2.73±0.04​ 1.49±0.051.49_{\pm 0.05}1.49±0.05​ 16.62±0.0916.62_{\pm 0.09}16.62±0.09​ 2.36±0.032.36_{\pm 0.03}2.36±0.03​
5 2.77±0.032.77_{\pm 0.03}2.77±0.03​ 2.26±0.052.26_{\pm 0.05}2.26±0.05​ 16.60±0.0616.60_{\pm 0.06}16.60±0.06​ 2.82±0.042.82_{\pm 0.04}2.82±0.04​

表 11:训练结束时的测试错误率与估计锐度(max⁡ϵL(w+ϵ)−L(w)\max_\epsilon L(w+\epsilon) - L(w)maxϵ​L(w+ϵ)−L(w))。

Number of projected gradient steps CIFAR-10 Test error CIFAR-10 Estimated sharpness CIFAR-100 Test error CIFAR-100 Estimated sharpness
1 2.77±0.032.77_{\pm 0.03}2.77±0.03​ 0.17±0.030.17_{\pm 0.03}0.17±0.03​ 16.72±0.0816.72_{\pm 0.08}16.72±0.08​ 0.82±0.050.82_{\pm 0.05}0.82±0.05​
2 2.76±0.032.76_{\pm 0.03}2.76±0.03​ 0.82±0.030.82_{\pm 0.03}0.82±0.03​ 16.59±0.0816.59_{\pm 0.08}16.59±0.08​ 1.83±0.051.83_{\pm 0.05}1.83±0.05​
3 2.73±0.042.73_{\pm 0.04}2.73±0.04​ 1.49±0.051.49_{\pm 0.05}1.49±0.05​ 16.62±0.0916.62_{\pm 0.09}16.62±0.09​ 2.36±0.032.36_{\pm 0.03}2.36±0.03​
5 2.77±0.032.77_{\pm 0.03}2.77±0.03​ 2.26±0.052.26_{\pm 0.05}2.26±0.05​ 16.60±0.0616.60_{\pm 0.06}16.60±0.06​ 2.82±0.042.82_{\pm 0.04}2.82±0.04​

References

参考文献

Naman Agarwal, Rohan Anil, Elad Hazan, Tomer Koren, and Cyril Zhang. Revisiting the generalization of adaptive gradient methods, 2020. URL https://openreview.net/forum?id=BJl6t64tvr.

James Bradbury, Roy Frostig, Peter Hawkins, Matthew James Johnson, Chris Leary, Dougal Maclaurin, and Skye Wanderman-Milne. JAX: composable transformations of Python+NumPy programs, 2018. URL http://github.com/google/jax.

Niladri S Chatterji, Behnam Neyshabur, and Hanie Sedghi. The intriguing role of module criticality in the generalization of deep networks. In International Conference on Learning Representations, 2020.

Pratik Chaudhari, Anna Choromanska, Stefano Soatto, Yann LeCun, Carlo Baldassi, Christian Borgs, Jennifer Chayes, Levent Sagun, and Riccardo Zecchina. Entropy-SGD: Biasing Gradient Descent Into Wide Valleys. arXiv e-prints, art. arXiv:1611.01838, November 2016.

Pengfei Chen, Benben Liao, Guangyong Chen, and Shengyu Zhang. Understanding and utilizing deep neural networks trained with noisy labels. CoRR, abs/1905.05040, 2019. URL http://arxiv.org/abs/1905.05040.

Ekin Dogus Cubuk, Barret Zoph, Dandelion Man{'e}, Vijay Vasudevan, and Quoc V. Le. Autoaugment: Learning augmentation policies from data. CoRR, abs/1805.09501, 2018. URL http://arxiv.org/abs/1805.09501.

J. Deng, W. Dong, R. Socher, L.-J. Li, K. Li, and L. Fei-Fei. ImageNet: A Large-Scale Hierarchical Image Database. In CVPR09, 2009.

Terrance Devries and Graham W. Taylor. Improved regularization of convolutional neural networks with cutout. CoRR, abs/1708.04552, 2017. URL http://arxiv.org/abs/1708.04552.

Laurent Dinh, Razvan Pascanu, Samy Bengio, and Yoshua Bengio. Sharp minima can generalize for deep nets. arXiv preprint arXiv:1703.04933, 2017.

Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, Jakob Uszkoreit, and Neil Houlsby. An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale. arXiv e-prints, art. arXiv:2010.11929, October 2020.

Timothy Dozat. Incorporating nesterov momentum into adam. 2016.

John Duchi, Elad Hazan, and Yoram Singer. Adaptive subgradient methods for online learning and stochastic optimization. Journal of machine learning research, 12(7), 2011.

Gintare Karolina Dziugaite and Daniel M Roy. Computing nonvacuous generalization bounds for deep (stochastic) neural networks with many more parameters than training data. arXiv preprint arXiv:1703.11008, 2017.

Xavier Gastaldi. Shake-shake regularization. CoRR, abs/1705.07485, 2017. URL http://arxiv.org/abs/1705.07485.

Behrooz Ghorbani, Shankar Krishnan, and Ying Xiao. An Investigation into Neural Net Optimization via Hessian Eigenvalue Density. arXiv e-prints, art. arXiv:1901.10159, January 2019.

Dongyoon Han, Jiwhan Kim, and Junmo Kim. Deep pyramidal residual networks. CoRR, abs/1610.02915, 2016. URL http://arxiv.org/abs/1610.02915.

Ethan Harris, Antonia Marcu, Matthew Painter, Mahesan Niranjan, Adam {Pr"ugel-Bennett}, and Jonathon Hare. FMix: Enhancing Mixed Sample Data Augmentation. arXiv e-prints, art. arXiv:2002.12047, February 2020.

Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. CoRR, abs/1512.03385, 2015. URL http://arxiv.org/abs/1512.03385.

Geoffrey Hinton, Nitish Srivastava, and Kevin Swersky. Neural networks for machine learning lecture 6a overview of mini-batch gradient descent.

Sepp Hochreiter and J"urgen Schmidhuber. Simplifying neural nets by discovering flat minima. In Advances in neural information processing systems, pp.\ 529--536, 1995.

Sepp Hochreiter and J"urgen Schmidhuber. Flat minima. Neural Computation, 9(1):1--42, 1997.

Gao Huang, Yu Sun, Zhuang Liu, Daniel Sedra, and Kilian Weinberger. Deep Networks with Stochastic Depth. arXiv e-prints, art. arXiv:1603.09382, March 2016.

J. Huang, L. Qu, R. Jia, and B. Zhao. O2u-net: A simple noisy label detection approach for deep neural networks. In 2019 IEEE/CVF International Conference on Computer Vision (ICCV), pp.\ 3325--3333, 2019.

Yanping Huang, Youlong Cheng, Ankur Bapna, Orhan Firat, Mia Xu Chen, Dehao Chen, HyoukJoong Lee, Jiquan Ngiam, Quoc V. Le, Yonghui Wu, and Zhifeng Chen. GPipe: Efficient Training of Giant Neural Networks using Pipeline Parallelism. arXiv e-prints, art. arXiv:1811.06965, November 2018.

Sergey Ioffe and Christian Szegedy. Batch normalization: Accelerating deep network training by reducing internal covariate shift. arXiv preprint arXiv:1502.03167, 2015.

Pavel Izmailov, Dmitrii Podoprikhin, Timur Garipov, Dmitry Vetrov, and Andrew Gordon Wilson. Averaging Weights Leads to Wider Optima and Better Generalization. arXiv e-prints, art. arXiv:1803.05407, March 2018.

Arthur Jacot, Franck Gabriel, and Cl{'e}ment Hongler. Neural tangent kernel: Convergence and generalization in neural networks. CoRR, abs/1806.07572, 2018. URL http://arxiv.org/abs/1806.07572.

Stanislaw Jastrzebski, Maciej Szymczak, Stanislav Fort, Devansh Arpit, Jacek Tabor, Kyunghyun Cho, and Krzysztof Geras. The Break-Even Point on Optimization Trajectories of Deep Neural Networks. arXiv e-prints, art. arXiv:2002.09572, February 2020.

Lu Jiang, Zhengyuan Zhou, Thomas Leung, Li-Jia Li, and Li Fei-Fei. Mentornet: Regularizing very deep neural networks on corrupted labels. CoRR, abs/1712.05055, 2017. URL http://arxiv.org/abs/1712.05055.

Lu Jiang, Di Huang, Mason Liu, and Weilong Yang. Beyond Synthetic Noise: Deep Learning on Controlled Noisy Labels. arXiv e-prints, art. arXiv:1911.09781, November 2019.

Yiding Jiang, Behnam Neyshabur, Hossein Mobahi, Dilip Krishnan, and Samy Bengio. Fantastic generalization measures and where to find them. arXiv preprint arXiv:1912.02178, 2019.

Diederik P. Kingma and Jimmy Ba. Adam: A Method for Stochastic Optimization. arXiv e-prints, art. arXiv:1412.6980, December 2014.

Alexander Kolesnikov, Lucas Beyer, Xiaohua Zhai, Joan Puigcerver, Jessica Yung, Sylvain Gelly, and Neil Houlsby. Big transfer (bit): General visual representation learning, 2020.

Simon Kornblith, Jonathon Shlens, and Quoc V. Le. Do Better ImageNet Models Transfer Better? arXiv e-prints, art. arXiv:1805.08974, May 2018.

John Langford and Rich Caruana. (not) bounding the true error. In Advances in Neural Information Processing Systems, pp.\ 809--816, 2002.

Beatrice Laurent and Pascal Massart. Adaptive estimation of a quadratic functional by model selection. Annals of Statistics, pp.\ 1302--1338, 2000.

Kimin Lee, Sukmin Yun, Kibok Lee, Honglak Lee, Bo Li, and Jinwoo Shin. Robust inference via generative classifiers for handling noisy labels, 2019.

Hao Li, Zheng Xu, Gavin Taylor, and Tom Goldstein. Visualizing the loss landscape of neural nets. CoRR, abs/1712.09913, 2017. URL http://arxiv.org/abs/1712.09913.

Sungbin Lim, Ildoo Kim, Taesup Kim, Chiheon Kim, and Sungwoong Kim. Fast autoaugment. CoRR, abs/1905.00397, 2019. URL http://arxiv.org/abs/1905.00397.

James Martens and Roger Grosse. Optimizing Neural Networks with Kronecker-factored Approximate Curvature. arXiv e-prints, art. arXiv:1503.05671, March 2015.

David A McAllester. Pac-bayesian model averaging. In Proceedings of the twelfth annual conference on Computational learning theory, pp.\ 164--170, 1999.

Hossein Mobahi. Training recurrent neural networks by diffusion. CoRR, abs/1601.04114, 2016. URL http://arxiv.org/abs/1601.04114.

Y. E. Nesterov. A method for solving the convex programming problem with convergence rate o(1/k2)o(1/k^2)o(1/k2). Dokl. Akad. Nauk SSSR, 269:543--547, 1983. URL https://ci.nii.ac.jp/naid/10029946121/en/.

Yuval Netzer, Tao Wang, Adam Coates, Alessandro Bissacco, Bo Wu, and Andrew Y Ng. Reading digits in natural images with unsupervised feature learning. 2011.

Behnam Neyshabur, Srinadh Bhojanapalli, David McAllester, and Nati Srebro. Exploring generalization in deep learning. In Advances in neural information processing systems, pp.\ 5947--5956, 2017.

Jiquan Ngiam, Daiyi Peng, Vijay Vasudevan, Simon Kornblith, Quoc V. Le, and Ruoming Pang. Domain adaptive transfer learning with specialist models. CoRR, abs/1811.07056, 2018. URL http://arxiv.org/abs/1811.07056.

Eric Arazo Sanchez, Diego Ortego, Paul Albert, Noel E. O'Connor, and Kevin McGuinness. Unsupervised label noise modeling and loss correction. CoRR, abs/1904.11238, 2019. URL http://arxiv.org/abs/1904.11238.

Nitish Shirish Keskar and Richard Socher. Improving Generalization Performance by Switching from Adam to SGD. arXiv e-prints, art. arXiv:1712.07628, December 2017.

Nitish Shirish Keskar, Dheevatsa Mudigere, Jorge Nocedal, Mikhail Smelyanskiy, and Ping Tak Peter Tang. On Large-Batch Training for Deep Learning: Generalization Gap and Sharp Minima. arXiv e-prints, art. arXiv:1609.04836, September 2016.

Nitish Srivastava, Geoffrey Hinton, Alex Krizhevsky, Ilya Sutskever, and Ruslan Salakhutdinov. Dropout: a simple way to prevent neural networks from overfitting. The journal of machine learning research, 15(1):1929--1958, 2014.

Xu Sun, Zhiyuan Zhang, Xuancheng Ren, Ruixuan Luo, and Liangyou Li. Exploring the Vulnerability of Deep Neural Networks: A Study of Parameter Corruption. arXiv e-prints, art. arXiv:2006.05620, June 2020.

Christian Szegedy, Vincent Vanhoucke, Sergey Ioffe, Jonathon Shlens, and Zbigniew Wojna. Rethinking the inception architecture for computer vision, 2015.

Mingxing Tan and Quoc V. Le. EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks. arXiv e-prints, art. arXiv:1905.11946, May 2019.

Colin Wei and Tengyu Ma. Improved sample complexities for deep neural networks and robust classification via an all-layer margin. In International Conference on Learning Representations, 2020.

Longhui Wei, An Xiao, Lingxi Xie, Xin Chen, Xiaopeng Zhang, and Qi Tian. Circumventing Outliers of AutoAugment with Knowledge Distillation. arXiv e-prints, art. arXiv:2003.11342, March 2020.

Ashia C Wilson, Rebecca Roelofs, Mitchell Stern, Nati Srebro, and Benjamin Recht. The marginal value of adaptive gradient methods in machine learning. In Advances in neural information processing systems, pp.\ 4148--4158, 2017.

Han Xiao, Kashif Rasul, and Roland Vollgraf. Fashion-mnist: a novel image dataset for benchmarking machine learning algorithms. CoRR, abs/1708.07747, 2017. URL http://arxiv.org/abs/1708.07747.

Yoshihiro Yamada, Masakazu Iwamura, and Koichi Kise. Shakedrop regularization. CoRR, abs/1802.02375, 2018. URL http://arxiv.org/abs/1802.02375.

Sergey Zagoruyko and Nikos Komodakis. Wide residual networks. CoRR, abs/1605.07146, 2016. URL http://arxiv.org/abs/1605.07146.

Chiyuan Zhang, Samy Bengio, Moritz Hardt, Benjamin Recht, and Oriol Vinyals. Understanding deep learning requires rethinking generalization. CoRR, abs/1611.03530, 2016. URL http://arxiv.org/abs/1611.03530.

Fan Zhang, Meng Li, Guisheng Zhai, and Yizhao Liu. Multi-branch and multi-scale attention learning for fine-grained visual categorization, 2020.

Hongyi Zhang, Moustapha Cisse, Yann N Dauphin, and David Lopez-Paz. mixup: Beyond empirical risk minimization. arXiv preprint arXiv:1710.09412, 2017.

Zhilu Zhang and Mert R. Sabuncu. Generalized cross entropy loss for training deep neural networks with noisy labels. CoRR, abs/1805.07836, 2018. URL http://arxiv.org/abs/1805.07836.