Search

Search papers and lessons

Symbolic Discovery of Optimization Algorithms

Xiangning Chen, Chen Liang, Da Huang et al. · 2023

This 2023 paper searches over small programs for a training rule and finds Lion, a memory-light optimizer whose update is a sign of a momentum mix, matching or beating AdamW on many image and language tasks.

On this page

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

TL;DR

The paper treats the design of an optimizer as a search problem. It writes candidate training rules as small programs, runs an evolutionary search over them on cheap proxy tasks, keeps the programs that still do well on larger tasks, and simplifies the winner by hand. The winner is Lion, which keeps only one momentum vector per parameter and updates each parameter by the sign of a momentum mix. On the paper's benchmarks Lion matched or beat AdamW on many image and language tasks, and it needed less memory.

Builds on: AdamW Optimizer, Symbolic Regression · Leads to: Lion Optimizer

Why it mattered

Most optimizers in deep learning are hand-designed variants of one idea. Adam, from 2014, and AdamW, from 2017, remained the default for most large models, including the Vision Transformers in ViT and the large language models that followed. The paper showed that a search could find a rule that competes with them. Its main training results are on Vision Transformers, on contrastive image-text training in the style of CLIP, on diffusion models, and on autoregressive language models.

The paper reports concrete savings. On JFT pre-training, Lion let a ViT-L/16 match a ViT-H/14 trained with AdamW at about 3 times less pre-training cost, and the abstract states up to 5 times savings. In the vision-language setting, replacing Adafactor with Lion in the BASIC system gave 88.3 percent zero-shot ImageNet accuracy and 91.1 percent after fine-tuning, which the paper reports as improvements of 2 and 0.1 points over the earlier best.

The problem

Before this paper, the question was how to find a better optimizer. Handcrafted optimizers each change one or two pieces of Adam: the momentum decay, the second moment, the bias correction, or the weight decay. Tuning these by hand is slow, and the space of such tweaks is small. The authors asked whether the space of all update rules that can be written as a short program is searchable, and whether a rule found on a cheap task would transfer to an expensive one.

Two obstacles make this hard. The first is that the space is huge and sparse: most random programs do nothing useful or do not run at all. The second is that a rule found on a small proxy task may only work on that task. The paper addresses the first with efficient search techniques and the second with selection on larger tasks and simplification of the result.

How it works

The method has five stages. Each one is a step in the pipeline, and the output of one is the input of the next.

  1. Encode each optimizer as a program. A candidate is a train function over arrays. Its inputs are the weight ww, the gradient gg and the learning-rate value at the current step, and its output is the weight update. It may keep extra variables, initialised to zero, to store history. Adam fits this format with two such variables, mm and vv. The building blocks are 45 common math functions, such as sums, products, and a linear interpolation.
  2. Search by evolution. A population of programs is improved in cycles. In each cycle a few programs are picked at random, the best of them becomes the parent, and the parent is copied and mutated by inserting, deleting or changing one statement. The child joins the population and the oldest member leaves. Before a child is run, an abstract execution step checks its shapes and removes programs that are duplicates in function, so the search does not waste time on them.
  3. Score on proxy tasks. Each candidate is trained on a small proxy task: a smaller model, fewer examples and fewer steps. One proxy evaluation takes about 20 minutes on one TPU v2 chip. Each full search ran on 100 chips for about 72 hours and generated 200,000 to 300,000 programs, of which 20,000 to 30,000 were actually run because the rest were caught by the cache or by the abstract execution.
  4. Select on larger tasks. Search fitness tends to rise while the program overfits the proxy, a failure the paper calls meta-overfitting. Candidates are therefore re-checked on meta-validation tasks that are larger. A funnel does this cheaply: a candidate that beats the baseline on a task 10 times larger moves on to a task 100 times larger, and the rest are dropped.
  5. Simplify. The surviving program is cut down. Statements that do not affect the output are removed using the abstract execution. Statements whose removal changes little are removed too. The remaining statements are rearranged and renamed by hand.

Stage 5 produced Lion. In the paper's derivation, the three statements that compute the update collapse into one sign function, the second moment vv is dropped because its effect on the momentum can be written with a single constant, and the bias correction is removed because it does not change the direction of the update. The result is the rule in Lion Optimizer.

flowchart LR
  A["candidate programs"] --> B["evolve by mutation"]
  B --> C["score on proxy task"]
  C --> D["funnel on larger meta-validation tasks"]
  D --> E["simplify by hand"]
  E --> F["Lion"]
  D -. "rejected at each size" .-> B

The math

The search space can be counted roughly. The paper estimates the number of programs as

np=nf l⋅nv na⋅l,n_p = n_f^{\,l} \cdot n_v^{\,n_a \cdot l},

where nfn_f is the number of available functions, ll is the program length in statements, nvn_v is the number of local variables, and nan_a is the average number of arguments per statement. This counts programs with fixed length and ignores constants.

For a rough feel, take the paper's 45 functions, programs of l=10l = 10 statements, nv=5n_v = 5 variables and na=2n_a = 2 arguments. Then np=4510⋅520n_p = 45^{10} \cdot 5^{20}. Since log⁡1045≈1.653\log_{10} 45 \approx 1.653 and log⁡105≈0.699\log_{10} 5 \approx 0.699, the logarithm of npn_p is about 16.53+13.98=30.5116.53 + 13.98 = 30.51. The space holds about 3×10303 \times 10^{30} programs of this size. A real search generates 200,000 to 300,000 of them, and only 20,000 to 30,000 are actually run.

The search objective is a fitness F(P)F(P), the validation accuracy or negative perplexity of the trained model when the program PP is used as the optimizer on a proxy task. Selection then compares candidates on the meta-validation task MkM_k, which is the kk-th funnel stage. A candidate survives stage kk only when its score on MkM_k beats the baseline. Written as a rule, the funnel keeps

Sk+1={P∈Sk:FMk(P)>FMk(AdamW)}.S_{k+1} = \{ P \in S_k : F_{M_k}(P) \gt F_{M_k}(\text{AdamW}) \}.

Here SkS_k is the set of candidates still in the funnel at stage kk, and AdamW\text{AdamW} stands for the tuned baseline. For accuracy the inequality means a higher score is better; for perplexity a lower one is, so the comparison is flipped on language tasks.

The final rule is the one derived in Lion Optimizer. With gradient gtg_t, momentum mtm_t, and decay factors β1\beta_1 and β2\beta_2, its step is

θt=θt−1−ηt(sign⁡ ⁣(β1mt−1+(1−β1)gt)+λθt−1),\theta_t = \theta_{t-1} - \eta_t \left( \operatorname{sign}\!\bigl(\beta_1 m_{t-1} + (1 - \beta_1) g_t\bigr) + \lambda \theta_{t-1} \right),

where ηt\eta_t is the learning rate at step tt, λ\lambda is the weight decay, and θt\theta_t are the weights. The momentum is updated by mt=β2mt−1+(1−β2)gtm_t = \beta_2 m_{t-1} + (1 - \beta_2) g_t. The paper's defaults are β1=0.9\beta_1 = 0.9 and β2=0.99\beta_2 = 0.99.

Results

The main results are on image classification. Table 2 compares models trained from scratch on ImageNet. With the stronger augmentation, which combines RandAugment and Mixup, Lion gives ViT-B/16 a top-1 accuracy of 80.77 against 80.12 for AdamW, and ViT-S/16 79.46 against 78.89. Without the stronger augmentation the gaps are larger: 77.44 against 75.48 for ViT-B/16, a gain of 1.96 points, and 76.70 against 76.12 for ViT-S/16. The paper notes that the gain grows with the training batch size and shrinks under strong augmentation.

When pre-trained on ImageNet-21K and then fine-tuned, Lion gives ViT-L/16 85.59 against 85.07 for AdamW, and ViT-B/16 84.45 against 84.12. On JFT the paper reports that Lion lets ViT-L/16 match ViT-H/14 trained with AdamW, at about 3 times less pre-training cost. Fine-tuning results on ImageNet show ViT-L/16 matching the previous ViT-H/14 while being half the size.

The limits are stated in the paper's Section 6. The advantage shrinks with strong augmentation. Lion also prefers larger batches: on ViT-B/16 its best batch size is 4,096, against 256 for AdamW, although it stays robust down to a batch of 64. On ResNets the methods are close, which the authors attribute to convolutional networks being easier to optimize. Lion performs about the same as AdamW on some tasks, including the base text-to-image model of Imagen and the perplexity of a large autoregressive language model. The paper also notes that the update's larger norm calls for a smaller learning rate, which is a practical difference rather than a limit of the method.

Reading guide

Read the paper in this order, with the prerequisites each part leans on.

Check yourself

QuestionThe search space estimate counts programs of fixed length with n_f functions and n_v variables. Why does the search need the abstract execution step, given that the count is so large?Show answer
A large count is not the problem by itself. Most programs are invalid, because of shape or type errors, or they are duplicates of others in function. Abstract execution catches invalid programs and identifies duplicates through a hash of their computation, so the search runs only the programs that are new and valid. The paper reports that about 20,000 to 30,000 of the 200,000 to 300,000 generated programs were run.
QuestionA candidate beats the baseline on a proxy task but not on a meta-validation task that is 10 times larger. What does the funnel do, and why?Show answer
The funnel drops the candidate. The selection keeps a program only when it beats the baseline on each larger task in turn. A program that does well only on the small proxy has probably overfit that proxy, which the paper calls meta-overfitting, so it should not move on to the expensive stages.
QuestionIn the paper's ViT-B/16 results with the stronger augmentation, Lion scores 80.77 and AdamW 80.12. What is the gap in points, and how does the paper describe its size?Show answer
The gap is 0.65 points. The paper describes the gain as smaller under strong augmentation than without it, where the same model gains 1.96 points, so the stronger augmentation narrows the advantage.
QuestionThe paper says Lion's update has a larger norm than AdamW's. What practical change does this imply for the learning rate and the weight decay?Show answer
A larger update norm means each step moves the weights further, so the learning rate should be smaller, typically 3 to 10 times smaller than for AdamW. To keep the same effective weight decay per step, the decay coefficient must be larger by the same factor.

Sources

Read the full paper

Xiangning Chen, Chen Liang, Da Huang et al., 2023. arXiv:2302.06675