Search

Search papers and lessons

Lion Optimizer

Level 4 · 12 min read

Lion trains a model with one momentum vector per parameter and moves each parameter by a fixed step in the direction of the sign of a momentum mix, a rule found by automated program search.

On this page

  • Colour = topic mix
  • Discrete math
  • Probability
  • Optimizers
  • Linear algebra
  • Calculus
  • Learning basics
  • ReadReady to readNot yet

TL;DR

Lion is an optimizer for training neural networks. It keeps a single momentum vector for each parameter, mixes the current gradient into that momentum, and moves every parameter by the same fixed size in the direction of the sign of the mix. It was not designed by hand: an automated search over small update programs found it, and its authors then simplified the result. Because it stores less state than the usual adaptive optimizers, it uses less memory, and on the paper's image benchmarks it matched or beat AdamW.

Builds on: Momentum, AdamW Optimizer · Leads to: the Lion paper

Where it's used

Training image models. Vision Transformers such as ViT-B/16, trained from scratch on ImageNet, are the main test case in the paper. Lion matched or improved on AdamW in its reported runs, for example about 0.65 points higher top-1 accuracy for ViT-B/16 trained from scratch on ImageNet, which made the optimizer a candidate for large image jobs.

Training very large models under a memory limit. A model with hundreds of millions of parameters keeps two optimizer vectors per parameter with Adam-style methods. Lion keeps one. The paper gives a concrete case: training ViT-B/16 with a batch of 4,096 needs at least 16 TPU v4 chips with AdamW and 8 with Lion, both using bfloat16 momentum.

Large-batch data parallel training. Teams that scale training by adding data-parallel workers use very large batches. The paper reports that Lion's advantage over AdamW grows as the batch size grows, which fits that setting.

How it works

Lion has one state vector per parameter, called the momentum mm. The learning rate η\eta is the step scale, and β1\beta_1 and β2\beta_2 are two decay factors between 0 and 1. The paper's defaults are β1=0.9\beta_1 = 0.9 and β2=0.99\beta_2 = 0.99.

Trace one parameter θ\theta with three gradients, using η=0.1\eta = 0.1, no weight decay, and m0=0m_0 = 0. The gradients are g1=4g_1 = 4, g2=−1g_2 = -1 and g3=1g_3 = 1.

  1. Start with θ0=2.0\theta_0 = 2.0 and m0=0m_0 = 0. The first gradient is g1=4g_1 = 4. Mix it with the old momentum: c1=0.9⋅0+0.1⋅4=0.4c_1 = 0.9 \cdot 0 + 0.1 \cdot 4 = 0.4. Check: the mix is positive, so its sign is +1+1.
  2. Step the parameter by the sign: θ1=2.0−0.1⋅(+1)=1.9\theta_1 = 2.0 - 0.1 \cdot (+1) = 1.9. Check: the step is 0.10.1 even though the gradient was 44. Only the sign was used.
  3. Update the momentum with a slower average: m1=0.99⋅0+0.01⋅4=0.04m_1 = 0.99 \cdot 0 + 0.01 \cdot 4 = 0.04. Check: the momentum has moved only a little, because β2\beta_2 is large.
  4. The second gradient is g2=−1g_2 = -1. Mix again: c2=0.9⋅0.04+0.1⋅(−1)=0.036−0.1=−0.064c_2 = 0.9 \cdot 0.04 + 0.1 \cdot (-1) = 0.036 - 0.1 = -0.064. Check: the old momentum pulls up, but the new gradient is larger in size, so the mix is negative and its sign is −1-1.
  5. Step the parameter: θ2=1.9−0.1⋅(−1)=2.0\theta_2 = 1.9 - 0.1 \cdot (-1) = 2.0. The parameter moved back. Check: the step was again exactly 0.10.1 in size.
  6. Update the momentum: m2=0.99⋅0.04+0.01⋅(−1)=0.0296m_2 = 0.99 \cdot 0.04 + 0.01 \cdot (-1) = 0.0296. Check: the momentum is still positive, so it remembers the first gradient.
  7. The third gradient is g3=1g_3 = 1, so c3=0.9⋅0.0296+0.1⋅1=0.1266c_3 = 0.9 \cdot 0.0296 + 0.1 \cdot 1 = 0.1266, sign +1+1, and θ3=2.0−0.1=1.9\theta_3 = 2.0 - 0.1 = 1.9.

The diagram shows the same loop for every step.

flowchart LR
  G["gradient g_t"] --> M["mix: c_t = β1 m_t-1 + (1 - β1) g_t"]
  M --> S["sign(c_t)"]
  S --> T["θ_t = θ_t-1 - η sign(c_t)"]
  G --> U["momentum: m_t = β2 m_t-1 + (1 - β2) g_t"]
  U -. "used at the next step" .-> M

Two things stand out. Every parameter moves by the same amount, η\eta, whatever its gradient was, so the scale of the gradient does not matter. And the momentum mm does two jobs: it is mixed into the direction, and it is updated with the gradient for the next step. The mix uses β1=0.9\beta_1 = 0.9, so the direction follows recent history closely, while the stored momentum uses β2=0.99\beta_2 = 0.99, so it remembers about a hundred steps.

The math

Definition: Lion update

At step tt, with gradient gtg_t of the loss ff at the parameters θt−1\theta_{t-1}, Lion computes a mixed direction ctc_t, takes its sign, and moves each parameter by ηt\eta_t times that sign plus a weight-decay term. Then it updates the momentum mtm_t. The rules are

ct=β1 mt−1+(1−β1) gtθt=θt−1−ηt(sign⁡(ct)+λ θt−1)mt=β2 mt−1+(1−β2) gt\begin{aligned} c_t &= \beta_1\, m_{t-1} + (1 - \beta_1)\, g_t \\ \theta_t &= \theta_{t-1} - \eta_t \bigl(\operatorname{sign}(c_t) + \lambda\, \theta_{t-1}\bigr) \\ m_t &= \beta_2\, m_{t-1} + (1 - \beta_2)\, g_t \end{aligned}

where λ\lambda is the decoupled weight decay coefficient and sign⁡(x)\operatorname{sign}(x) is +1+1 for positive xx, −1-1 for negative xx, and 00 for x=0x = 0.

Step 1 in symbols: the gradient

The gradient gt=∇θf(θt−1)g_t = \nabla_\theta f(\theta_{t-1}) is the vector of partial derivatives of the loss, taken element by element over the parameters. It is the same Gradient used in Stochastic Gradient Descent, computed here on a mini-batch.

Step 2 in symbols: the mixed direction

The mix ctc_t is an Exponential Moving Average style blend of the old momentum and the new gradient, with weights β1\beta_1 and 1−β11 - \beta_1 that add to one. With β1=0.9\beta_1 = 0.9, the old momentum has weight 0.90.9 and the new gradient 0.10.1. In the walkthrough, c1=0.1⋅4=0.4c_1 = 0.1 \cdot 4 = 0.4 because the momentum started at zero.

Step 3 in symbols: the sign step

Only the sign of ctc_t enters the step. For every coordinate ii, the update of θt,i\theta_{t,i} is ±ηt\pm \eta_t or 00. The sign operation is the only nonlinear part of the rule. It is why every parameter moves by about the same size, and it is also why Lion's update is larger in norm than an SGD step with the same learning rate. The paper notes that the update has a large norm and that a sign-based step adds a kind of noise that helps generalisation.

Step 4 in symbols: the momentum

The momentum uses a second decay factor β2\beta_2. Its update is an exponential average of the gradients with a long memory. The effective window is about 1/(1−β2)=1001 / (1 - \beta_2) = 100 steps for β2=0.99\beta_2 = 0.99, against about 10 for β1=0.9\beta_1 = 0.9. This is the reason the paper describes Lion as remembering a longer history for the momentum while putting more weight on the current gradient in the update.

Step 5 in symbols: no bias correction

Adam divides its averages by a correction factor at the start, because they begin at zero. Lion does not, and the paper argues this is safe. At t=1t = 1 the mix is c1=(1−β1) g1c_1 = (1 - \beta_1)\, g_1, which is a positive multiple of g1g_1, so its sign is the sign of the gradient. The correction would only rescale a quantity whose sign is what is used.

Step 6 in symbols: the weight decay term

Write the weight-decay part on its own: θt≈θt−1−ηtλ θt−1\theta_t \approx \theta_{t-1} - \eta_t \lambda\, \theta_{t-1} when the sign term is small. Each step shrinks a parameter by the fraction ηtλ\eta_t \lambda. This product, not λ\lambda alone, is the effective decay strength, which the next section uses.

Worked examples

Example
1. Two parameters with very different gradients (tiny)

Let θ=(1.0,1.0)\theta = (1.0, 1.0), η=0.01\eta = 0.01, λ=0\lambda = 0, β1=0.9\beta_1 = 0.9, m0=(0,0)m_0 = (0, 0). The first gradient is g1=(100,0.01)g_1 = (100, 0.01).

  1. Mix: c1=0.1⋅(100,0.01)=(10,0.001)c_1 = 0.1 \cdot (100, 0.01) = (10, 0.001).
  2. Signs: sign⁡(c1)=(+1,+1)\operatorname{sign}(c_1) = (+1, +1).
  3. Step: θ1=(1.0,1.0)−0.01⋅(+1,+1)=(0.99,0.99)\theta_1 = (1.0, 1.0) - 0.01 \cdot (+1, +1) = (0.99, 0.99).

Interpretation: the first parameter had a gradient ten thousand times larger than the second, and both moved by the same 0.010.01. Lion discards the scale of the gradient and keeps only its direction, so a parameter with a tiny gradient is not held back.

Example
2. Matching the effective weight decay (standard)

The paper reports that Lion needs a smaller learning rate than AdamW and a larger weight decay to compensate. Its ViT-B/16 settings are η=10−4\eta = 10^{-4} with λ=10.0\lambda = 10.0 for Lion, and η=10−3\eta = 10^{-3} with λ=1.0\lambda = 1.0 for AdamW.

  1. Lion's per-step decay: ηλ=10−4⋅10.0=10−3\eta \lambda = 10^{-4} \cdot 10.0 = 10^{-3}.
  2. AdamW's per-step decay: ηλ=10−3⋅1.0=10−3\eta \lambda = 10^{-3} \cdot 1.0 = 10^{-3}.
  3. The two products are equal, so each optimizer shrinks a weight by the same fraction per step from weight decay.
  4. Take a weight equal to 2.02.0. Each step removes 2.0⋅10−3=0.0022.0 \cdot 10^{-3} = 0.002 from it through decay in both optimizers.
  5. The difference lies in the gradient part. Lion adds a step of size 10−410^{-4} in each coordinate, and AdamW adds a step of size about 10−310^{-3} scaled by its own normalisation.

Interpretation: when moving from AdamW to Lion, changing the learning rate alone would change the decay too, so the two must be tuned together.

Example
3. Image classification on ImageNet (realistic)

Table 2 of the paper compares ViT-B/16 trained from scratch on ImageNet, using top-1 accuracy averaged over three runs. The values are AdamW 80.12 and Lion 80.77.

  1. Gap in accuracy: 80.77−80.12=0.6580.77 - 80.12 = 0.65 percentage points.
  2. Relative error: the error rate falls from 100−80.12=19.88100 - 80.12 = 19.88 to 100−80.77=19.23100 - 80.77 = 19.23 percent.
  3. Relative reduction in error: (19.88−19.23)/19.88=0.65/19.88=0.0327(19.88 - 19.23) / 19.88 = 0.65 / 19.88 = 0.0327, about 3.3 percent.
  4. Memory check from the same paper: for ViT-B/16 at batch size 4,096, AdamW needs at least 16 TPU v4 chips and Lion needs 8.
  5. Interpretation: in this setting Lion gives a small accuracy gain and halves the chips, so the trade is favourable. A gap of under one point is within the noise of many training runs, so the result is best read as "at least as good" rather than "clearly better".

Try it: the paper's ViT-S/16 row in the same table reports AdamW 78.89 and Lion 79.46. What is the gap in percentage points? Answer: 79.46−78.89=0.5779.46 - 78.89 = 0.57 percentage points.

Common mistakes and tradeoffs

It is tempting to think that Lion is a free upgrade over AdamW. In fact the paper's gains are small, a fraction of a point to a point or so in its image tasks, and they depend on tuning. Treat Lion as a strong option to test, not as a guaranteed win.

It is tempting to think that the learning rate can be copied from AdamW. In fact the sign update has a larger norm than AdamW's update, so the learning rate should be smaller, and the weight decay larger to keep the effective decay the same, as Example 2 showed.

It is tempting to think that a sign step means every parameter moves by one unit. In fact the step is the learning rate η\eta, not 1. The unit is set by η\eta, and that is why the size of η\eta matters so much.

It is tempting to think that Lion has no momentum because it has no second moment. In fact it has the momentum mm, and the step uses a mix of it with the current gradient. What it drops is the second vector vv that Adam keeps.

When to use it. Use Lion when memory is the limit, when batches are large, or when you want to test a sign-based method on image or language models, and tune η\eta and λ\lambda together.

When not to. Be careful with small batches. The paper reports that the advantage over AdamW grows with batch size, so with small batches AdamW may be as good, and it is the better-studied default.

Alternatives. AdamW Optimizer remains the usual default, with well-known settings. Plain Stochastic Gradient Descent with Momentum uses less memory than either and is strong for convolutional networks, but it needs careful tuning of the learning rate schedule, as explained in Cosine Annealing.

History

Adam appeared in 2014. In 2017 Ilya Loshchilov and Frank Hutter proposed AdamW, which applies weight decay directly to the weights rather than inside the gradient, and it became the common default. Sign-based methods are much older. Rprop, published by Martin Riedmiller and Heinrich Braun in 1993, used the sign of the gradient to adapt each weight's step size.

In 2023 Xiangning Chen and colleagues published "Symbolic Discovery of Optimization Algorithms". Their method searched over small programs that compute an update, scored each candidate by training cost and accuracy on proxy tasks, and kept the best. The program that won was simplified by hand into a short rule with a single sign operation, which they named Lion, for EvoLved Sign Momentum. The result caught on because the rule is short, stores less state than AdamW, and works on several large vision models.

Recap

  • Lion keeps one momentum vector per parameter and does not keep the second moment that Adam uses.
  • Each step mixes the momentum with the gradient using β1=0.9\beta_1 = 0.9, takes the sign, and moves every parameter by the learning rate.
  • Because the step has a fixed size, the learning rate is smaller than for AdamW (ten times smaller in the paper's ViT-B/16 settings), and the weight decay is larger.
  • The momentum update uses β2=0.99\beta_2 = 0.99, which gives it a long memory.
  • Read next: Symbolic Discovery of Optimization Algorithms, which gives the search, the full benchmarks and the tuning advice, and AdamW Optimizer, the baseline it is measured against.

Check yourself

QuestionLion's step for a parameter is plus or minus the learning rate, whatever the gradient size. Why does this make the learning rate so important?Show answer
Because the size of every step is set by the learning rate alone, the learning rate is the only scale in the update. A value that is too large makes every parameter jump by a large amount each step, and a value that is too small makes training crawl, so the choice cannot be left to the gradient to correct.
QuestionA parameter has weight 1.5. Lion uses learning rate 0.001 and weight decay 2.0, with the sign term ignored. How much does the decay remove in one step?Show answer
The per-step decay is ηλ=0.001⋅2.0=0.002\eta \lambda = 0.001 \cdot 2.0 = 0.002. The decay removes 1.5⋅0.002=0.0031.5 \cdot 0.002 = 0.003, so the weight becomes 1.497 from this term alone.
QuestionWhy does Lion not need bias correction at the first step, while Adam does?Show answer
Adam's averages start at zero and are divided by a correction factor, because their values are small in the first steps. At the first step Lion's mix is (1−β1)(1 - \beta_1) times the gradient, a positive multiple of the gradient. Its sign is therefore the sign of the gradient, and rescaling it would not change the update.
QuestionLion has β1=0.9\beta_1 = 0.9 and β2=0.99\beta_2 = 0.99. Roughly how many steps of gradient history does the momentum average remember, and how does that differ from the mix?Show answer
The momentum average with β2=0.99\beta_2 = 0.99 remembers about 1/(1−0.99)=1001 / (1 - 0.99) = 100 steps. The mix with β1=0.9\beta_1 = 0.9 uses about 1/(1−0.9)=101 / (1 - 0.9) = 10 steps, so the direction follows recent gradients more closely than the stored momentum does.

Sources