Adafactor: Adaptive Learning Rates with Sublinear Memory Cost

Noam Shazeer, Mitchell SternICML 2018

As deep learning models scale to billions of parameters, memory has become a primary bottleneck. Standard adaptive optimizers like Adam are popular because they converge quickly by scaling updates for each parameter individually. However, this comes at a high cost: Adam stores two additional values (the moving averages of the first and second moments of the gradients) for every single parameter. For a large weight matrix, this triples the memory required to store the model during training.

Adafactor is a memory-efficient optimizer designed to reduce the storage requirements of adaptive methods from $O(nm)$ to $O(n+m)$ for weight matrices. By using a low-rank factorization of gradient moments and introducing novel stability techniques, it allows researchers to train much larger models on the same hardware without sacrificing performance.

Overcoming the Memory Bottleneck

The authors introduce several clever techniques to achieve sublinear memory costs:

  1. Factored Second Moments: Instead of storing a full $n \times m$ matrix of squared gradients, Adafactor only stores the sums of the rows and the sums of the columns. It then reconstructs an approximation of the full matrix using an outer product. This rank-1 approximation is optimal with respect to the generalized Kullback-Leibler divergence and drastically reduces the memory footprint.
  2. Removing Momentum: To save even more space, Adafactor drops the first-moment accumulator (momentum) entirely.
  3. Update Clipping: Removing momentum usually makes training unstable. The authors found that instability often stems from "out-of-date" second-moment estimators that produce massive, explosive updates. They introduce a clipping mechanism that scales down updates if their Root-Mean-Square (RMS) exceeds a certain threshold.
RMS of unscaled updates showing instability for high beta2
  1. Increasing Decay Rate: They propose a schedule where the decay rate of the second moment ($\beta_2$) increases over time, allowing the optimizer to be more stable early in training and more precise later on.
  2. Relative Step Size: Instead of a fixed global learning rate, Adafactor scales updates relative to the scale of the parameters themselves, making the optimizer more robust to different initialization schemes.

Key Insights

  • Structural Redundancy: Squared gradients in neural networks aren't random; they often have a row- or column-wise structure. Storing just the row and column sums captures most of the useful information for adaptivity.
  • The "Out-of-Date" Problem: When the model evolves rapidly, the second-moment accumulator can become a "liar," suggesting update sizes that are far too large. RMS-based clipping is a direct, elegant fix for this specific failure mode.
  • Scale Invariance: By using relative step sizes, the optimizer becomes less sensitive to how weights are initialized or scaled—a common headache when tuning large-scale Transformers.

Performance and Results

The researchers evaluated Adafactor using the WMT 2014 English-German machine translation task, specifically testing it on the standard Transformer architecture.

Ablation study showing Adafactor achieving 25.9 BLEU
  • Comparable Performance: On the WMT'14 task, Adafactor achieved a BLEU score of 25.9 (as seen in the optimal configuration of their ablation study), matching or slightly exceeding the performance of the standard Adam baseline (25.6) while using significantly less auxiliary memory.
  • Massive Memory Savings: For a weight matrix of size $1024 \times 1024$, Adam requires roughly 1,000,000 extra floating-point numbers for the second moment. Adafactor requires only 2,048.
  • Stability: The combination of update clipping and the increasing decay schedule allowed the model to train successfully without momentum, which previously caused models to diverge during training.

Limitations and Future Work

While highly effective for Transformers, the paper focuses heavily on this specific architecture. The effectiveness of the rank-1 approximation on convolutional layers (CNNs) or other structures isn't explored in depth. Additionally, while Adafactor is designed to be robust, it introduces new hyperparameters (like the clipping threshold $d$ and the decay schedule) that might require tuning for different domains. Finally, while it is possible to train without momentum to save memory, some tasks might still benefit from the smoothing effect of momentum if memory is not the absolute constraint.

Summary updated

BibTeX
@inproceedings{shazeer2018adafactor,
  author = {Noam Shazeer and Mitchell Stern},
  title = {{Adafactor: Adaptive Learning Rates with Sublinear Memory Cost}},
  booktitle = {International Conference on Machine Learning},
  year = {2018},
}
Figure