At (1, 0.01) on our test function both gradient entries equal 1. Yet the distance to the minimum along x is a hundred times the distance along y. If we had access to how fast each slope changes, we could recover both distances. Sophia, proposed by Liu and colleagues in 2023, periodically estimates that information and limits the size of the resulting step. The previous sign-step example. 在本专题的二次函数上,点 (1, 0.01) 的两个梯度分量都等于 1。但沿 x 方向到极小点的距离,是沿 y 方向的一百倍。如果知道各坐标的斜率变化有多快,就能在这个例子中算出这两个距离。Liu 等人在 2023 年提出的 Sophia 定期估计曲率,再给算出的步长设定上限。回看上一期的符号步算例。

A quadratic model with a limited step 给二次近似加上位移上限

For a single coordinate, let m denote a smoothed slope and h a curvature estimate. Write , with positive γ and ε. The scale γ controls how much curvature affects the decision, and ε keeps a positive denominator even when the estimate is zero or negative. Minimize a quadratic in a normalized displacement u between −1 and 1. Setting its derivative to zero gives −m/a. If that point falls outside the interval, the nearer endpoint minimizes the quadratic. 单看一个坐标,用 m 表示平滑后的斜率,用 h 表示估计的曲率。令 ,其中 γ、ε 均为正数。γ 调节曲率在计算中占的分量;即使 h 为零或为负,ε 也能保证分母为正。用 u 表示归一化位移,允许它在 −1 到 1 之间变化。把下面二次式的导数设为零,得到 −m/a。若该点落在区间外,区间内的最小值就在离它较近的那个端点。

Here η is the learning rate and λ is decoupled weight decay. The slope estimate m is an exponential average of batch gradients. Every k steps a fresh curvature estimate is blended into h with another exponential average. Other steps reuse the last h. In the unsaturated region a doubled positive curvature halves the update if m is fixed and the ε floor is inactive. At saturation the gradient-driven displacement has magnitude η. Momentum lag and an inaccurate local quadratic can still cause a loss increase. Original update, equation 6. η 是学习率,λ 是解耦权重衰减系数。m 取各批梯度的指数移动平均。每隔 k 步,算法才算一次新的曲率估计,用另一组指数平均系数更新 h,其余各步沿用上次的 h。如果更新没有触及边界、分母也没有碰到 ε 下限,那么在 m 不变时,正曲率翻倍,位移减半。触及边界后,仅由梯度驱动的位移大小就是 η。动量可能滞后,局部二次近似也可能失准,因此这一步仍可能使真实损失上升。原论文公式 6。

Repeat the step with two equal slopes 再算一遍斜率相同的那一步

Use the exact gradient for m and the exact diagonal for h to isolate the update rule. These values bypass both running averages for this one-step calculation. Set γ = 0.5, η = 0.1 and λ = 0, with ε below 0.5. The first proposed coordinate hits the unit cap. The second uses its full curvature correction. 为了单独观察更新规则,这一步直接把真实梯度代入 m,把真实 Hessian 对角线代入 h,暂时略过两次移动平均。取 γ = 0.5、η = 0.1、λ = 0,并令 ε 小于 0.5。第一个坐标会碰到位移上限,第二个坐标则完整保留曲率修正。

The new point (0.9, 0.008) has loss 0.4082, down from 0.505. The sign step of the same coordinate limit gave 0.81. This isolates the value of exact axis-aligned curvature in this example. Rotate the surface by 45 degrees and both diagonal entries become 50.5, while the principal curvatures remain 1 and 100. The coupling between coordinates now carries the missing information. A diagonal preconditioner cannot recover the principal directions from those two equal entries. 新位置 (0.9, 0.008) 的损失是 0.4082,低于出发时的 0.505。上期用相同位移上限得到的符号步,损失升到了 0.81。这次差异来自已知的精确曲率,而且主轴恰好和坐标轴对齐。如果把曲面旋转 45 度,两个对角元素都会变成 50.5,两个主曲率却仍为 1 和 100。差别转移到了描述坐标耦合的非对角元素,仅凭两个相等的对角元素无法找回主轴方向。

What goes into the denominator? 分母中的曲率是怎样估出来的

Sophia-H. Draw a standard Gaussian vector z and compute a Hessian–vector product Hz on a batch. The i-th estimate is . In expectation the cross terms vanish and the diagonal term survives. This estimates the diagonal of the batch loss Hessian without forming the matrix. A single draw can be noisy, and a nonconvex loss can have negative curvature. Sophia-H。 抽一个标准高斯随机向量 z,在一个批次上计算 Hessian 与向量的乘积 Hz。第 i 个坐标的估计是 。取期望后,交叉项抵消,对角项留下来。这样可以估计批次损失的 Hessian 对角线,无需构造整张矩阵。一次抽样的估计可能有很大波动,非凸损失也可能有负曲率。

Sophia-G. For softmax cross-entropy, fix the inputs and draw a label from each model prediction. If p is the class-probability vector and e the one-hot sampled label, the logit gradient is p−e. It has zero mean and covariance S below. With J the Jacobian of logits with respect to parameters, pulling S back through J gives the generalized Gauss–Newton matrix G. Its diagonal is nonnegative. The full loss Hessian also has terms involving second derivatives of logits. Sophia-G。 对 softmax 交叉熵,固定输入,从模型给出的每个类别分布中抽一个标签。设概率向量为 p,抽得的标签独热向量为 e,那么损失对 logits 的梯度就是 p−e。它的均值为零,协方差为下面的 S。令 J 为 logits 对参数的雅可比矩阵,经 J 把 S 变换到参数空间,就得到广义 Gauss–Newton 矩阵 G。它的对角元素非负。完整的损失 Hessian 还包含 logits 对参数的二阶导数项。

For B conditionally independent sampled labels, let s̄ be their average parameter gradient. Expanding shows why the factor B is necessary. The cross terms have zero expectation, leaving the mean of the B individual second moments, exactly the mean Gauss–Newton diagonal entry. Reusing the gradient of the observed labels would change what is being estimated. In the authors’ code the Hessian buffer holds squared batch-mean gradients and the multiplier is applied in the denominator. SophiaG.update_hessian and parameter update · Estimator derivations. 对 B 个条件独立抽出的标签,令 s̄ 表示相应参数梯度的批次平均。展开 就能看出为何要乘 B:交叉项的期望为零,只留下 B 个单样本二阶矩的平均,恰好是平均 Gauss–Newton 矩阵的第 i 个对角元素。若直接复用真实标签算出的梯度,估计的量就变了。作者的实现把批次平均梯度的平方存入曲率缓冲区,计算更新的分母时再乘回批量因子。SophiaG 的曲率更新与参数更新 · 原论文估计量推导。

When does paying for curvature save training time? 多算曲率,什么时候能省下训练时间?

For the 770M model, Table 1 reports 3.25 seconds per AdamW step and 3.42 seconds per Sophia-G step. If a run actually matches the target validation loss in half as many steps, those average times imply a speed ratio of about 1.90. The reported step times already include the amortized curvature work. This calculation illustrates the authors’ measurements and is not a new timing run. Liu et al., Table 1. 论文表 1 报告,在 7.7 亿参数模型上,AdamW 平均每步用时 3.25 秒,Sophia-G 用时 3.42 秒。若达到同一验证损失所需的步数确实减半,用这两项平均耗时换算,总用时之比约为 1.90。表中的每步时间已包含摊销后的曲率估计开销。这是根据论文测量做的换算。Liu 等人论文表 1。

On another workload, fix the validation target and token budget, tune the schedule for each run length, then record elapsed time to the target, time per curvature refresh and the fraction of coordinates that hit the cap. If almost every coordinate saturates, most gradient-driven updates have become sign steps while curvature estimation still costs time. If a run misses the target, report the loss it reached within budget. Paper’s budget-matched evaluation protocol. 换到自己的训练任务,先固定验证损失目标和 token 预算,针对各自的训练步数调整学习率日程,再记录达到目标的总用时、刷新一次曲率的耗时,以及触及位移上限的坐标比例。假如几乎所有坐标都触及上限,大部分更新便退化成符号步,估计曲率的开销却仍要支付。若有方法用完预算也没达到目标,就报告预算内实际达到的损失。原论文的预算对齐评估方法。