Adafactor is an adaptive learning-rate optimizer that stores a factorized approximation of the squared-gradient statistics instead of a full per-parameter copy, which cuts optimizer memory to a small fraction of what the Adam optimizer requires. In Artificial intelligence, it is used mainly for training large transformer models, where optimizer state can otherwise consume more memory than the model weights themselves.
Introduced by Noam Shazeer and Mitchell Stern in 2018, Adafactor became the default optimizer for the T5 family and was later used in other large language model projects. It keeps the per-parameter adaptivity that makes Adam effective while removing most of its memory overhead.
How Adafactor factorizes second-moment estimates
Adafactor reduces memory by replacing the full second-moment matrix of a weight matrix with row and column statistics. Adam keeps an exponential moving average of squared gradients for every parameter, so a weight matrix of size n by m needs n times m extra values. Adafactor instead keeps one vector of row sums with n entries and one vector of column sums with m entries.
At each step, the optimizer reconstructs an estimate of the per-parameter second moment as the outer product of the row and column vectors, divided by the total sum. This is a rank-one approximation, and it works well because squared gradients in neural network layers tend to have strong row and column structure. Vectors such as biases and layer-normalization gains are small, so Adafactor stores their full second moments.
The update then divides the gradient by the square root of this estimate, as in Adam. The memory cost for a matrix falls from O(nm) to O(n + m), which for a 4,096 by 16,384 feed-forward layer means about 20,000 stored values instead of roughly 67 million.
| Optimizer | First moment | Second moment | Extra values per matrix |
|---|---|---|---|
| SGD with momentum | n × m | None | n × m |
| Adam or AdamW | n × m | n × m | 2 × n × m |
| Adafactor with momentum | n × m | n + m | n × m + n + m |
| Adafactor without momentum | None | n + m | n + m |
Key mechanisms beyond factorization
Factorization alone made training unstable in the original experiments, so Adafactor adds several stabilizing mechanisms. Together they explain why the method behaves differently from Adam even when the factorized estimate is accurate.
- Update clipping: the root mean square of each update is capped at a threshold, typically 1.0, which prevents sudden large steps when the second-moment estimate lags behind.
- Increasing decay rate: the second-moment decay grows over time, commonly as 1 minus t to the power of -0.8, so early estimates adapt quickly and later ones become smooth.
- Relative step size: the step is scaled by the root mean square of the parameter itself, so large weights receive proportionally larger updates.
- Optional momentum: the first moment can be disabled entirely, which saves the most memory and was the setting used for T5.
The table below lists the main hyperparameters and their usual default values in common implementations. Defaults vary slightly between libraries, so it is worth confirming them before reproducing published results.
| Hyperparameter | Common default | What it controls |
|---|---|---|
| Clipping threshold | 1.0 | Maximum RMS of a single update |
| Decay exponent | -0.8 | How fast second-moment decay approaches 1 |
| Epsilon 1 | 1e-30 | Numerical floor for squared gradients |
| Epsilon 2 | 1e-3 | Minimum parameter scale for relative steps |
| Beta 1 | None or 0.9 | Whether momentum is used |
| Relative step | min(1e-2, 1/√t) | Built-in step size when no learning rate is given |
Adafactor compared with other optimizers
Adafactor sits between plain SGD and full Adam in the trade-off between memory and adaptivity. It is closely related to RMSprop, which also divides by a running average of squared gradients, but adds factorization, clipping and relative scaling.
| Optimizer | Memory overhead | Adaptivity | Typical use |
|---|---|---|---|
| Adafactor | Very low to moderate | Per row and column | Large transformers under memory limits |
| AdamW | Two copies of weights | Per parameter | Default for most deep learning |
| RMSprop | One copy of weights | Per parameter | Recurrent and reinforcement learning |
| Lion optimizer | One copy of weights | Sign-based | Memory-conscious large models |
| SGD with momentum | One copy of weights | None | Vision models, convex problems |
In practice, AdamW usually reaches slightly better quality at equal compute when memory is not a constraint. Adafactor wins when memory is the binding limit, because the saved state can be spent on larger batch sizes or bigger models.
Configuring Adafactor for training
Adafactor can run in two broad modes. In the original mode, it computes its own relative step size and needs no external learning rate. In the more common modern mode, practitioners disable the relative step and supply an explicit learning rate schedule with warmup, which gives behavior closer to Adam and makes tuning more predictable.
For fine-tuning T5 checkpoints, a constant learning rate of about 1e-3 with Adafactor is a widely used recipe, which is much higher than typical Adam rates of 1e-5 to 1e-4. Copying Adam learning rates into Adafactor, or the reverse, is a frequent source of poor results.
| Situation | Recommended setting | Reason |
|---|---|---|
| Pretraining under tight memory | Factorized, no momentum | Smallest optimizer state |
| Fine-tuning T5 models | External learning rate near 1e-3 | Matches original training recipe |
| Unstable loss spikes | Enable momentum, keep clipping | Smoother update direction |
| Ample accelerator memory | Consider AdamW instead | Often slightly better convergence |
Limitations and common mistakes
Adafactor’s main weakness is sensitivity to configuration. Without momentum, training can be noisier and, at very large scale, more prone to loss spikes, which led some later projects to re-enable momentum or switch back to AdamW.
- Mixing step-size modes: setting an external learning rate while relative steps remain enabled produces unexpected scaling.
- Ignoring parameter scale: relative steps make updates depend on weight magnitude, which interacts with weight decay and initialization.
- Assuming identical results to Adam: the factorized estimate is an approximation, so hyperparameters rarely transfer unchanged.
- Overlooking low-precision effects: very small epsilon values require care in bfloat16 or float16 arithmetic.
Stripped to the essentials
Training a large AI model means nudging billions of numbers in small steps. Smart optimizers keep notes on every number to decide how big each step should be. Those notes take a great deal of memory.
Adafactor keeps shorter notes. Instead of one note per number, it keeps one note per row and one per column of each table of numbers. It then estimates the rest. This saves most of the memory and still gives each number a sensible step size.
The result is simple. The same hardware can train a bigger model.
Where it is applied
A research team wants to fine-tune a three-billion-parameter T5 model on a corpus of legal summaries, but it has only eight accelerators with 40 GB of memory each. With AdamW, the weights, gradients and two optimizer moments in 32-bit precision would need about 48 GB of state before activations are counted, which does not fit when every device holds a full replica.
The team switches to Adafactor with factorization enabled, no momentum and a constant learning rate of 1e-3. The optimizer state shrinks to a few megabytes for the second-moment statistics, so the freed memory supports a larger batch per device and fewer gradient accumulation steps.
Training converges within the planned budget, and validation loss tracks closely with a smaller reference run that used AdamW. The team keeps update clipping at 1.0 and reports stable training without loss spikes across the full schedule.