Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Only the sign matters
Lion looks at a blend of the recent average gradient and the current one, and moves every weight a fixed small amount in the direction that blend points. It ignores how big the gradient is. It was not designed by hand: Chen et al. (2023) ran an automated search over short optimiser programs, and this simple rule came out on top. It uses less memory than Adam because it stores one running average instead of two.
Optimiser state is a large share of training memory: Adam stores two extra numbers per weight. Lion stores one, which frees memory for bigger models or batches. Its fixed-size steps also behave predictably. The catch is that its learning rate and weight decay must be retuned: copying AdamW’s values makes it diverge.
- 1. Lion's update uses…
- 2. Lion was found by…
- 3. Compared with Adam, Lion stores…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Direction: c = β₁m + (1 − β₁)g, typically β₁ = 0.9.
- Update: w ← w − η(sign(c) + λw).
- Momentum: m ← β₂m + (1 − β₂)g, typically β₂ = 0.99. Two different β’s: the update uses a short-memory blend, the stored momentum a long one.
- Example: m = (1, −1, 0), g = (−20, 5, 3): c = (−1.1, −0.4, 0.3), so sign(c) = (−1, −1, +1). The huge gradient −20 counts the same as any other negative value.
- Step size: every coordinate moves by η, so the update’s norm is η√n: with n = 10⁴ and η = 10⁻⁴ it is 0.01.
- Settings rule of thumb: relative to AdamW, a learning rate 3–10× smaller and weight decay 3–10× larger, keeping their product similar (Chen et al.).
- 1. sign(0.9 × 1 + 0.1 × (−20)) is…
- 2. Lion's update norm for n parameters is…
- 3. Switching from AdamW, Lion's weight decay should be…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Lion in code
Exercise 1.
- A Lion step moved every coordinate by exactly η, whether gradients were of size 0.001, 1 or 1000.
- Adam’s normalised update m̂/√v̂ had RMS 0.995 per coordinate on consistent gradients but only 0.232 on pure-noise gradients. That is close to √((1 − β₁)/(1 + β₁)) = 0.229, the RMS of an exponential average of unit noise.
- So Adam automatically takes smaller steps when gradients are noisy; Lion does not. This is one reason Lion needs a smaller learning rate.
Practice.
- Default β₁ = 0.9, β₂ = 0.99. For noisy training some use β₂ = 0.98 for stability.
- Start from AdamW’s settings with η divided by 3–10 and λ multiplied by 3–10. Re-sweep η: exercise 2’s ratio was larger than that rule suggests.
- Lion is reported to gain most at larger batch sizes, where gradients are less noisy.
# pip install lion-pytorch: from lion_pytorch import Lion; Lion(params, lr=1e-4, weight_decay=1.0)- 1. Adam's normalised update under pure-noise gradients has RMS about…
- 2. Lion's per-coordinate step under noise is…
- 3. Lion's default β₂ is…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Sign methods. signSGD (Bernstein et al., 2018) updates by sign(g). It is a steepest-descent step in the ∞-norm: among steps with every coordinate at most η, the one that most decreases a linear model of the loss is −η·sign(g). Lion is signSGD applied to a momentum blend.
Relation to Adam. With β₁ = β₂ = 0 and ε = 0, Adam’s update m̂/√v̂ = g/|g| = sign(g): Adam reduces to signSGD. Adam softens the sign when gradients are noisy, because its numerator averages out while its denominator does not. Lion keeps the hard sign, so its effective step is larger, which is why it needs a smaller η.
Weight decay. With step η·sign(c), the decay term ηλw balances the update when |w| ≈ 1/λ. So λ sets the typical weight scale, and a larger λ keeps weights small. This is why Lion uses a larger λ with its smaller η.
Analysis. Chen et al. (2023b) showed Lion with decoupled decay solves a constrained problem: it minimises the loss subject to ‖w‖∞ ≤ 1/λ, a view that explains the role of λ.
- 1. −η·sign(g) is the steepest-descent step in the…
- 2. With β₁ = β₂ = 0, Adam reduces to…
- 3. Lion's weight decay effectively bounds…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.Lion versus AdamW on a small network
History.
- J. Bernstein et al. (2018) analysed signSGD for distributed training.
- X. Chen et al. (2023) found Lion by symbolic program search and reported gains on image classification, vision–language and diffusion models.
- L. Chen et al. (2023) analysed Lion as constrained optimisation.
Exercise 2. A 2–32–32–3 tanh network on three spirals, trained with mini-batches of 32 for 400 steps. Loss is the full-data loss averaged over the last 50 steps, for 2 seeds.
| η | AdamW loss | Lion loss |
|---|---|---|
| 0.001 | 0.457 | 0.166 |
| 0.003 | 0.076 | 0.0035 |
| 0.01 | 0.013 | 0.030 |
| 0.03 | 0.0021 | 0.342 |
| 0.1 | 0.0006 | 1.47 |
| 0.3 | 0.107 | 4.39 |
- Both fit the spirals well at their own best rate, AdamW slightly better here.
- Lion’s best rate (0.003) was about 33× smaller than AdamW’s (0.1), more than the paper’s 3–10×. At AdamW’s best rate Lion diverged.
- Part of the reason is exercise 1: with mini-batch noise Adam’s per-coordinate step is well below η, while Lion’s is always η.
- Lesson: Lion is a reasonable, memory-saving alternative, but its learning rate must be swept from scratch; the 3–10× rule is only a starting point.
Lion in AI, robotics and aerospace
- Large vision and diffusion models have been trained with Lion to save optimiser memory.
- Fine-tuning on memory-limited hardware, such as onboard or edge accelerators, benefits from one moment instead of two.
- Distributed training: sign updates compress to 1 bit per coordinate, cutting communication between nodes.
References
- X. Chen, C. Liang, D. Huang, E. Real, K. Wang, Y. Liu, H. Pham, X. Dong, T. Luong, C.-J. Hsieh, Y. Lu, Q. V. Le (2023). “Symbolic discovery of optimization algorithms.” Advances in NeurIPS.
- J. Bernstein, Y.-X. Wang, K. Azizzadenesheli, A. Anandkumar (2018). “signSGD: compressed optimisation for non-convex problems.” Proc. ICML.
- L. Chen, B. Liu, K. Liang, Q. Liu (2023). “Lion secretly solves constrained optimization: as Lyapunov predicts.” arXiv:2310.05898.