Start at (1, 1) on the same quadratic as in part 1, . The gradient is (1, 100). Using a single learning rate gives a displacement ratio of 1 to 100. What information could set a different scale for each coordinate without computing any second derivatives?仍从 (1, 1) 出发,目标函数仍为 。起点处的梯度是 (1, 100),用同一个学习率乘这两个数,横、纵位移之比就是 1 比 100。如果不显式计算二阶导数,优化器能凭什么为每个坐标选择不同的尺度?

Make the cost of moving depend on direction让移动的代价随方向变化

At step t, evaluate the gradient at the current parameter . The linear approximation to the loss change is for displacement d. Charge a quadratic cost for moving too far. If a positive diagonal matrix penalizes a coordinate more heavily, that coordinate moves less for the same gradient.第 t 次更新时,在当前参数 处计算梯度 。位移为 d 时,一阶近似给出的损失变化为 。再加一项二次代价来限制单步移动的距离。正对角矩阵 决定每个坐标的移动代价;代价高的坐标,在相同梯度作用下就走得短。

Choosing and takes this quadratic to its minimum in one step. The Hessian is known in that calculation. Adaptive first-order methods instead build from the gradients observed so far. A large gradient can reflect high curvature, distance to the optimum or noise in the data.在本例中,若取 、 ,一步就能走到最低点。这次计算用上了已知的 Hessian。自适应一阶方法则根据已经观测到的梯度构造 。梯度分量大,可能因为曲率高,也可能因为离最优点远,或因为样本噪声大。

Which gradients stay in the denominator?分母记住了哪些梯度?

Diagonal AdaGrad sums squared gradients in each coordinate from the first update onward. A coordinate with a long history of large gradients consequently gets a smaller learning-rate multiplier than a rarely active one. The original paper derives this choice through adaptive proximal geometry. Duchi, Hazan & Singer, 2011对角 AdaGrad 从第一步起逐坐标累加梯度的平方。某个特征每活跃一次,对应坐标便多记一笔平方梯度。长期出现大梯度的坐标会获得较小的学习率乘子,偶尔才被更新的坐标则能保留较大的乘子。原论文从自适应近端几何推导了这类更新。 Duchi、Hazan 与 Singer,2011

With a constant nonzero gradient and , neglecting ε gives a displacement of magnitude . Each early spike stays in the cumulative sum. RMSProp replaces that sum with an exponential moving average. The squared gradient from k updates ago carries weight , so recent gradients have more influence as the training regime changes. Hinton et al., lecture 6e若某一坐标的梯度恒定且非零,令 ,忽略 ε 后,每步位移的大小便是 。早期一次异常大的梯度会一直留在累加项里。RMSProp 将累加改成指数移动平均。k 步以前的平方梯度权重为 。因此训练状态变化时,近期梯度更能影响步长。 Hinton 等,第 6e 讲

Here RMSProp starts at zero and uses an uncentered second moment without momentum or bias correction. Its effective memory is roughly steps. The small positive ε outside the square root protects division by zero. Its placement matters when the gradients are very small.这里采用 RMSProp 的基础形式,从零初始化,用未中心化的二阶原点矩,不加动量,也不做偏差修正。其有效记忆长度约为 步。根号外的正数 ε 用于避免除以零。当梯度极小时,把 ε 放在根号内外会给出不同的步长。

Adam smooths both direction and scaleAdam 同时平滑方向与尺度

Adam keeps the RMSProp-style average of squared gradients for scale, and adds an average of signed gradients for direction. Repeated signs reinforce one another in the numerator. Frequent reversals cancel there, while still contributing positively to the denominator. Kingma & Ba, Algorithm 1Adam 保留平方梯度的指数平均,用它决定尺度,同时再用一个平均量 记录带符号的梯度。某个坐标若连续同向,分子中的梯度会相互加强;若频繁变号,它们在分子中相互抵消,却仍以正数计入分母。 Kingma 与 Ba,算法 1

The superscript ⊙2 means squaring each component. From a zero initial state the weights in an exponential average sum to . Even a constant gradient g would give . Dividing by the sum removes the attenuation from zero initialization. With a changing gradient distribution, the corrected moments still reflect past steps.上标 ⊙2 表示逐元素平方。从零初始化时,指数平均在第 t 步的权重之和只有 。即使梯度始终等于 g,也只能得到 。除以权重之和,就消除了从零起步造成的缩小。若梯度分布一直在变,修正后的矩估计仍会受到过去若干步的影响。

On the first step from (1, 1), the corrected moments are (1, 100) and (1, 10,000). Dividing component by component after the square root gives (1, 1), up to ε. With the two coordinates remain equal under each of the three methods on this example. The gradients stay in the ratio 1 to 100, which cancels in the normalized update. The methods still move by different distances.从 (1, 1) 出发,第一步修正后的一阶矩为 (1, 100),二阶矩为 (1, 10,000)。对二阶矩开方,再逐项相除,忽略 ε 就得到 (1, 1)。在这个例子中令 ,三种算法各自迭代时,横、纵坐标都始终相等。两个梯度分量相差百倍,归一化恰好抵消了这百倍的差距。但三种方法每次走的距离各不相同。

Coordinate value after each update (x = y)每次更新后的坐标值(x = y)
Method方法t = 1t = 2t = 3
AdaGrad0.900000.833100.78046
RMSProp0.683770.498870.36918
Adam0.900000.800140.70055

Use , where applicable, and zero initial state. We use for these calculations because every denominator is positive. AdaGrad’s second x-gradient is 0.9, and its accumulated squared gradient is 1 + 0.9². RMSProp’s first denominator is only times the gradient magnitude. Its unusually long first step follows from its zero initialization.复算时统一取 ,涉及衰减系数时取 ,历史状态从零开始。表中各步的分母都非零,因此手算时取 。例如 AdaGrad 第二次看到的 x 向梯度是 0.9,累计平方梯度是 1 + 0.9²。RMSProp 第一步的分母只有梯度绝对值的 倍,这解释了它在表中格外长的第一步。

Where weight decay enters changes the result衰减项放在哪里,会改变更新结果

Add to the loss and the gradient gains a term. Under plain gradient descent this shrinks the old parameter by a factor . Passing to Adam also puts the penalty inside both moment estimates. AdamW calculates these moments from the data gradient g and applies uniform multiplicative shrinkage directly to the old parameter. Loshchilov & Hutter, ICLR 2019给损失加上 后,梯度便多出 。普通梯度下降将它乘以 η,恰好相当于先把旧参数缩小为原来的 倍。如果给 Adam 传入 ,惩罚项也会进入两个矩估计。AdamW 只用数据梯度 g 更新矩估计,再对旧参数直接施加相同的乘性衰减。 Loshchilov 与 Hutter,ICLR 2019

To isolate decay, turn off the data gradient, start a fresh optimizer at (1, 2), and set with small positive ε. Coupled Adam sees gradient (0.1, 0.2) and moves both coordinates by about 0.1, giving approximately (0.9, 1.9). AdamW sees zero moments and multiplies each coordinate by 0.99, giving (0.99, 1.98). One update distinguishes the rules.可以把数据梯度设为零,单独检查衰减。令全新的优化器从 (1, 2) 起步,取 ,ε 为很小的正数。把 L₂ 惩罚并入 Adam 时,它看到梯度 (0.1, 0.2),两个坐标各减少约 0.1,得到约 (0.9, 1.9)。AdamW 的两个矩都为零,直接把每个坐标乘以 0.99,得到 (0.99, 1.98)。一次更新就足以区分两条规则。

When a diagonal scale loses information对角缩放会遗漏什么

Rotate the narrow bowl by 45°. The two diagonal Hessian entries now both equal 50.5 and each off-diagonal entry has magnitude 49.5. The ratio of principal curvatures is still 100. Positive diagonal rescaling cannot cancel these cross terms. A full preconditioner can mix coordinates, at a cost in memory and arithmetic.把窄谷旋转 45°,Hessian 的两个对角元都会变成 50.5,非对角元的绝对值则是 49.5。两条主轴的曲率比依然是 100。沿现有坐标轴分别缩放,无法抵消这些交叉项。要让一次更新混合不同坐标的信息,可以使用矩阵预条件器,代价是更多的存储和计算。

Forgetting can lose relevant observations. Reddi and colleagues give a convex example where Adam fails to converge to the optimum. Their AMSGrad variant retains a running component-wise maximum of the second-moment estimate, preventing a large observation from disappearing from the denominator. The precise update rule matters when applying a convergence theorem. Reddi, Kale & Kumar, ICLR 2018遗忘也可能丢掉重要的观测。Reddi 等人构造了一个凸优化例子,其中 Adam 无法收敛到最优点。他们提出的 AMSGrad 逐坐标保留二阶矩估计迄今的最大值,使一次大梯度在分母中留下长期影响。要把某条收敛定理用于新任务,必须先确认它对应的更新规则和假设。 Reddi、Kale 与 Kumar,ICLR 2018