Suppose the two slopes at your current point are 1 and 100. Should the second coordinate move a hundred times farther? If each coordinate can move by at most 0.1, the largest decrease predicted by a linear model uses the full 0.1 on both. Lion makes this decision using a smoothed gradient. We can test it by restoring the curvature that the linear model leaves out. 假设当前位置沿两个坐标的斜率分别为 1 和 100,第二个坐标就该多走一百倍吗?如果每个坐标最多只能移动 0.1,要让局部线性模型的预测值降得最多,两个坐标都应走满 0.1。Lion 用平滑后的梯度判断方向。要知道这一步在真实损失上是否划算,还得把线性模型略去的曲率算回来。

The geometry of a sign step 逐个限制坐标,符号步怎样出现

Let c be the estimated slopes and d the displacement. Their inner product is the predicted change in loss. With a per-coordinate limit η the feasible set is a square in two dimensions and a box in higher dimensions. Each term of the sum can be minimized separately. 把估计的斜率记为向量 c,位移记为 d。两者的内积就是线性模型预测的损失变化。令各坐标的位移上限为 η,可行域在二维是一块正方形,在高维是一个盒子。目标中的每一项都能单独取到最小值。

For a positive slope, the left endpoint gives the lowest value. For a negative slope, the right endpoint does. At zero slope all feasible displacements tie on that coordinate and Lion chooses zero. This geometry depends on the chosen axes. Rotating them rotates the box and can change the physical direction of a step. 斜率为正时,沿这一坐标走到左端最划算;斜率为负时则应走到右端。斜率恰好为零时,任意可行位移对线性目标的贡献都相同,Lion 取零位移。这个结论依赖坐标系。旋转坐标轴,也就旋转了允许位移的盒子,原空间里的更新方向可能随之变化。

One stored vector, two mixtures 一份动量,两个混合系数

Chen and colleagues found Lion by searching over update programs in 2023. Let be the current batch gradient, the stored average entering this step, and λ the decoupled weight decay. Both mixtures read that same old buffer. The first picks today’s sign. The second becomes the history available to the next batch. Authors’ PyTorch implementation. Chen 等人在 2023 年通过搜索更新程序得到了 Lion。用 表示当前批次的梯度, 表示这一步开始前保存的动量,λ 表示解耦权重衰减系数。下面两次加权都读取同一份旧动量。第一次决定这一步往哪边走,第二次把信息存给下一批数据。作者的 PyTorch 实现。

With the reference values 0.9 and 0.99, a fresh gradient supplies 10% of the direction estimate and 1% of the new stored average. If the old scalar momentum is +1 and the new gradient is −12, the first mixture is −0.3 and the stored mixture is +0.87. The gradient-driven step moves the parameter up while the history remains positive. Lion stores one running tensor per parameter tensor, compared with two in ordinary AdamW. Activations, gradients and parameter copies count separately. 按参考实现中的 0.9 和 0.99,当前梯度在方向估计中占 10%,在新存入的动量中占 1%。例如,某一坐标的旧动量是 +1,新梯度是 −12,两次加权分别得到 −0.3 和 +0.87。单看梯度贡献,这一步会让参数增大,留给下一步的动量仍是正数。每组参数只需保存一组同形状的动量,常规 AdamW 则保存一阶矩和二阶矩两组。这里算的是优化器状态,训练还需要为激活值、梯度和参数副本留出空间。

When a downhill direction sends the loss uphill 为什么方向选对了,损失还会上升

On the series quadratic, start at (1, 0.01) with zero momentum. The gradient is (1, 1), although the second coordinate lies only 0.01 from the bottom. Set η = 0.1 and λ = 0. Both coordinates move down by 0.1. The Taylor expansion is exact on this quadratic, whose Hessian H has diagonal entries 1 and 100 and zero off-diagonals. 仍用本专题的二次函数,从 (1, 0.01) 出发,动量初始化为零。两个坐标的梯度都是 1,可第二个坐标离谷底只有 0.01。取 η = 0.1、λ = 0,符号步让两个坐标各减去 0.1。这个函数的 Hessian 矩阵 H 的对角元素为 1 和 100,非对角元素为零。二次函数的泰勒展开到二阶就给出了损失的实际变化。

Loss rises from 0.505 to 0.81. The initial slope is downhill, but the high-curvature coordinate crosses the bottom and climbs the opposite side. At this particular starting point the change is . Any positive step smaller than therefore lowers the loss on this iteration. The bound changes with the starting point. Near a smooth minimum a fixed sign step can keep crossing the minimum. 损失从 0.505 升到了 0.81。出发时确实是下坡,但曲率大的那个坐标越过谷底,又爬上了对面。从这个起点计算,损失变化为 ,所以这一步取小于 的正步长,损失就会下降。换一个起点,这个界限也会变。接近光滑极小点时,固定长度的符号步可能反复跨过极小点。

What changes with batch size? 批量大小为何值得单独看

Consider one coordinate with true slope g. If the smoothed sign is wrong with probability p and never ties, its expected first-order contribution to the loss change is . A sign correct only half the time makes zero average first-order progress. Larger batches may improve sign reliability under gradient noise. Momentum can stabilize signs too, with a lag when the underlying gradient changes direction. 设某一坐标的真实梯度为 g,平滑后的方向以概率 p 判错,且不会恰好取零。它对损失一阶变化的期望贡献是 。若方向只有一半机会判对,一阶收益就在平均意义上抵消了。梯度噪声大时,扩大批量可能使符号更可靠。动量也能稳定符号,但真实方向改变后,旧信息会带来滞后。

In the authors’ ImageNet batch-size sweep, ViT-B/16 trained for 300 epochs at batch size 32K reached 77.9% accuracy with Lion and 75.4% with AdamW. For a new task, match the example budget and tune each learning rate. With k active coordinates the Euclidean length of Lion’s gradient-driven step is . Copying AdamW’s rate does not control this length. Changing the rate also changes the per-step weight shrinkage ηλ. Batch-size sweep and tuning settings · Chen et al., experiments and limitations. 在作者的 ImageNet 批量扫描实验中,ViT-B/16 训练 300 个 epoch,批量取 32K 时,Lion 和 AdamW 的准确率分别为 77.9% 和 75.4%。换到新任务,应固定处理的样本总数,分别调学习率,再比较验证集表现。若有 k 个坐标的更新方向非零,Lion 的梯度项产生的位移长度就是 。沿用 AdamW 的学习率,并不能保证位移长度相当;学习率一变,每步权重按比例缩小的幅度 ηλ 也会改变。批量扫描与调参设置 · Chen 等人的原论文与实验局限。