TL;DR
Adafactor is an optimizer for training neural networks. It scales each update by a running estimate of the squared gradients, as Adam does, but it stores that estimate for a weight matrix as one row total and one column total instead of one number per weight. It also drops momentum, clips unusually large updates, and sets step sizes relative to the size of the weights. On a machine translation task, the authors report quality comparable to Adam while using very little extra memory. Builds on: Adam Optimizer, Matrix Factorization, Kullback–Leibler Divergence · Leads to: Adafactor Optimizer, T5
Why it mattered
Adafactor became one of the standard optimizers for training large language and translation models with billions of weights. The reason is memory. Adam keeps two extra numbers per weight, so its optimizer state alone is twice the size of the weights. Adafactor's factored store removes most of that cost for the big weight matrices that dominate a Transformer, which lets the same hardware train a larger model or a larger batch. The T5 family of models (T5) was trained with Adafactor, which is the clearest sign of its practical uptake. The paper's own claim is narrower: on one benchmark, Adafactor matches the quality of Adam with momentum while storing much less.
The problem
Adaptive optimizers such as RMSProp and Adam divide each gradient by the square root of a running average of past squared gradients, one average per weight. This gives every weight its own effective step size, which helps on noisy, badly scaled problems. The cost is memory: for a weight matrix with rows and columns, the squared-gradient average has entries, as large as the matrix itself. Adam also keeps a momentum average of the gradient, so it stores two extra matrices. The paper points out that computing power for training grew much faster than memory, so this overhead became a real limit on model size.
Two further issues come up when one tries to remove that memory. Without momentum, Adam becomes unstable when the learning rate is not warmed up. The authors trace this to a second-moment average that is too slow to follow a model that is changing quickly, so the updates become too large. The paper addresses both issues and also asks for step sizes that match the scale of each parameter.
How it works
Here is the method in the order it runs, for one weight matrix of size in a training step.
- Receive a gradient. Compute the gradient of the loss with respect to . It is an matrix of the same size as .
- Square and sum the gradient. Compute element by element, then add a tiny constant . Keep only two sums: the sum of each row, a vector of length , and the sum of each column, a vector of length . Each is a moving average over steps, with decay .
- Rebuild an estimate of the full average. Form the rank-one matrix whose entry in row and column is . The denominator is the total of all the row sums. This is the only full-size object, and it is never stored.
- Normalise the gradient. Divide each entry of by the square root of the corresponding estimate from step 3. The result is , the unscaled update.
- Clip the update. Measure the root-mean-square of . If it is larger than the threshold , shrink the whole update so its root-mean-square equals . This is update clipping.
- Set the step from the weights. Compute the step size as , where is the relative step size and . Larger weights get larger steps.
- Update. Set . There is no momentum term.
flowchart LR A[Gradient G_t] --> B[Row sums R_t and column sums C_t of G_t squared] B --> C[Rank-one estimate of the second moment] C --> D[Normalised update U_t] D --> E[Clip the update to RMS d] E --> F[Scale by the weight size and the relative step] F --> G[New weights X_t]
Here is a tiny instance of step 3. Take a matrix of averaged squared gradients . The row sums are and , the column sums are and , and the total is . The rank-one estimate is . Its row sums are and and its column sums are and , the same as . The estimate keeps the margins of but cannot keep every entry, and that is the approximation the method accepts.
The math
Step 3: the best rank-one approximation
The paper compares two ways to measure how far a nonnegative approximation is from a nonnegative matrix . One is the Frobenius norm, which leads to the singular value decomposition, but its truncated factors can be negative and do not combine across time steps the way moving averages need. The other is the generalized Kullback-Leibler divergence, also called the I-divergence, which for nonnegative scalars is
It is nonnegative and equals zero only when . The paper minimises over nonnegative and , which is the rank-one case.
The paper's Lemma 1 gives the solution in closed form:
Here is a column of ones. The factor is the vector of row sums, and is the row of column sums. The proof sets the derivatives of the loss with respect to and to zero, which gives and . The pair gives the same loss for any , so the paper fixes the scale by choosing to be the row sums. This is the canonical solution.
The formula is linear in . Because the row sums of a moving average equal the moving average of the row sums, the factored store can be updated with the same recursion as Adam's second moment. That is why the method is compatible with exponential smoothing.
Algorithm 2 in symbols: the factored update
The accumulators are and . The full estimate is , divided by the bias correction as in Adam. Memory per matrix is numbers instead of . For a weight matrix that is numbers instead of .
Section 7 in symbols: the decay schedule
The paper writes Adam's second moment as a weighted sum of past squared gradients, . If the gradients have a stable mean square, the expected estimate equals the true mean square when the weights add up to one, which holds for any schedule with . The paper proposes the schedule
It starts at when and rises toward . Past gradients must also lose their weight as training goes on, which requires to diverge. That holds only when . When the estimate is the plain average of all past squared gradients. The paper's recommended value is , which gives .
Section 6 in symbols: update clipping
Let be the root-mean-square of the entries of , which is near 1 when the second-moment estimate is accurate. The clipped update is
When , nothing changes. When it is larger, the update is scaled so that its root-mean-square is exactly . The paper uses .
Results
The experiments train the Transformer of Vaswani et al. on the WMT 2014 English-to-German translation task, using the Tensor2Tensor code. Scores are BLEU on the newstest2013 development set, with beam size 4 and length penalty 0.6. Models are trained for 100,000 steps, with batches of about 4,096 input tokens and 4,096 target tokens. The authors note that these batches are about 8 times smaller than those in the original Transformer paper, and that each run took less than two hours on one Google TPU v2. Because the regime is shorter and the code differs, the authors say the scores should not be compared with the original paper's numbers.
The main findings, from the paper's Table 2 and text:
- Factored second moments matched the baseline. Adam with full second moments scored 25.6 BLEU with warmup. Adam with factored second moments and momentum off scored 25.6 with warmup as well (row J, with clipping).
- Momentum was not needed with warmup. Adam with momentum scored 25.4 with warmup, against 25.6 without momentum (rows A and B).
- Without warmup, Adam without momentum became unstable and scored 0.1 BLEU. Adding update clipping to the factored version raised its no-warmup score from 0.2 to 22.4 (rows C and J). Row N, which uses the decay schedule and clipping with full second moments, scored 25.9 with warmup and 22.4 without.
- Using only row means or only column means gave different results: row means were similar to the baseline, while column means were much worse. The authors suspect that a shared embedding and output matrix, where frequent tokens have much larger gradients, is the cause.
- Relative step sizes made Adafactor more resilient to how embedding parameters were initialised and scaled. In Table 3, Adam scored 26.4 with the standard embedding scheme and 24.2 with a naive scheme that uses no multiplier, while Adafactor scored 26.6 and 25.4 in the same two settings.
- Plain SGD with tuned learning rates was poorer and less stable, and some settings diverged.
The limits are as important as the results. There is one model and one translation task. The paper reports that results are "comparable" to Adam, not better. The authors state that it is not clear whether relative step sizes improve stability, because the step sizes in the experiments are not directly comparable. The update-clipping result for a threshold of 2 was no better than no clipping. The memory saving is a property of the storage, not a proof of faster training.
Reading guide
- Abstract and Section 1 need Stochastic Gradient Descent and Adam Optimizer. Read the introduction for the memory argument, which needs only the idea of one stored number per weight.
- Section 2 (Adam) needs Adam Optimizer, Momentum and Exponential Moving Average. Algorithm 1 is the reference for everything after it.
- Section 3 (factored second moments) needs Matrix Factorization, Singular Value Decomposition (SVD) and Kullback–Leibler Divergence. Read Lemma 1 slowly: the proof is a derivative and a symmetry argument.
- Section 4 (no momentum) needs Momentum and Learning Rate Warmup.
- Section 5 (out-of-date second moment) needs Exponential Moving Average. The RMS diagnostic in this section is the idea that clipping later acts on.
- Section 6 (update clipping) needs Gradient Norm Clipping for the comparison in Section 6.1.
- Section 7 (decay schedule) needs Exponential Moving Average and the sum-of-weights argument from the math section above.
- Section 8 (relative step size and Algorithms 4 to 6) is the full method. Its final form is Adafactor Optimizer.
- Section 9 (setup) needs Transformer and BLEU Score to interpret the tables.
Check yourself
QuestionFor a weight matrix with 512 rows and 2048 columns, how many numbers does Adam's second-moment store need, and how many does the factored store need?Show answer
Adam stores one number per weight, so numbers. The factored store keeps one row total per row and one column total per column, so numbers. The ratio is about 400 to 1.
QuestionTake the matrix . What rank-one estimate does the paper's formula give, and what are its row sums?Show answer
The row sums are and . The column sums are and . The total is . Each entry of the estimate is row sum times column sum divided by total: the top-left entry is , the top-right is , and the bottom row is and by the same rule. The estimate is . Its row sums are and , which match the row sums of , as the margin-preserving property requires.
QuestionWhy does the paper require in the schedule ?Show answer
The weight of a gradient from step in the second-moment estimate is multiplied by a product of decay terms over all later steps. For that weight to fade to zero as training continues, the sum must diverge, and that requires . If is larger, the sum converges, and very old gradients keep a fixed share of the estimate forever, so the estimate can go out of date again.
QuestionA team wants to use Adafactor in place of Adam to train a model with very large embedding tables that are shared with the output layer. What does the paper suggest they check, and why?Show answer
The paper found that using only column means of the second-moment estimate worked much worse than the full factored estimate in the shared embedding case, and it suspected that frequent tokens dominate the gradient magnitudes in that layer. The team should compare the factored estimate with the full one on their own model, watch training for instability, and consider relative step sizes together with the embedding initialisation and scaling, since the paper showed the choice matters.