Mechanic: A Learning Rate Tuner

Ashok Cutkosky, Aaron Defazio, Harsh Mehta

Abstract

The learning rate (LR) remains the most critical hyperparameter in modern deep learning, often requiring expensive manual grid searches to optimize. We present Mechanic, a "plug-and-play" wrapper that automatically tunes the learning rate scale factor for any base optimization algorithm (e.g., SGD, Adam, Lion). Built on the principles of Online Convex Optimization (OCO), Mechanic treats LR selection as a betting game, adjusting the scale factor based on the "wealth" generated by successful updates. Our evaluation across large-scale BERT and Vision Transformer (ViT) tasks demonstrates that Mechanic matches or exceeds the performance of expertly tuned hyperparameters while automatically adapting to changes in batch size and model scale.

Introduction

In modern deep learning, the learning rate is arguably the most critical hyperparameter. Even "adaptive" optimizers like Adam require a global scale factor to be tuned manually. Finding the optimal LR usually involves a "resource sink": running the same model multiple times with different settings (grid search) to see which one works best.

While researchers have proposed "learning-rate-free" optimizers before, they are often hand-crafted for specific algorithms. Mechanic addresses this by acting as a generic, modular wrapper. It takes the update vector from any base optimizer and automatically determines the best scale factor on the fly, saving significant time, compute resources, and environmental impact.

Methodology

Mechanic is built on a theoretical foundation called Online Convex Optimization (OCO). Instead of replacing the base optimizer, Mechanic wraps it. If a base optimizer (e.g., AdamW) suggests an update vector $\mathbf{u}_t$, Mechanic applies a learned scalar $s_t$, making the actual update $s_t \cdot \mathbf{u}_t$.

The core mechanism relies on Wealth-Regret Duality. The tuner treats the base optimizer’s progress as a "reward." It "bets" on a scale factor; if the resulting gradient indicates the model is moving in a helpful direction (decreasing loss), the tuner wins "wealth," which it uses to justify a larger scale factor in the next step. To move from pure theory to deep learning reality, the authors introduced several practical refinements:

  • Multiple Time-Scales: It tracks statistics using six different moving average speeds, making it robust to different training phases.
  • Scale-Free Property: The algorithm is designed so that rescaling input gradients does not change the tuner's behavior.
  • Weight-Decay Correction: A specific term was added to ensure compatibility with base optimizers that already utilize regularization.

Experimental Evaluation

The authors rigorously tested Mechanic across several domains, including NLP (BERT pre-training on Wikibooks and GLUE fine-tuning) and Computer Vision (large-scale pre-training of Vision Transformers on JFT-300M). They also utilized a suite of 12 classic convex benchmarks to compare against other theoretical methods.

Key Results

In BERT pre-training, Mechanic-tuned AdamW and Lion either matched or slightly outperformed the best possible manually tuned versions in Masked Language Modeling (MLM) accuracy. On ViT models, Mechanic was highly competitive, substantially beating the baseline during pre-training on JFT-300M.

One of the most impressive findings is Mechanic's automatic adaptation to scale. As batch sizes were varied from 256 to 8192, the tuner successfully tracked the optimal scaling values, maintaining high accuracy without manual retuning. Similarly, it automatically adjusted the learning rate when model sizes were varied, decreasing the scale factor for larger models to maintain stability.

Mechanic's performance and adaptation across varying batch sizes and model sizes. The left panels show MLM accuracy matching manually tuned AdamW, while the right panels show the automatic adjustment of the scale factor s.

Discussion and Limitations

Despite its success, Mechanic faces specific challenges. The authors found that Dropout interferes with the tuner's ability to sense the "true" reward of its learning rate choices, likely due to the introduced stochastic noise. Additionally, Mechanic currently optimizes for training loss. In deep learning, hyperparameters are often tuned for validation performance; bridging this gap—perhaps by providing the tuner with validation gradients—remains an area for future research.

Conclusion

Mechanic represents a significant step toward autonomous optimization. By providing a generic, theoretically grounded wrapper, it eliminates the need for expensive hyperparameter sweeps while matching the performance of expert tuning. Its ability to adapt to varying batch and model sizes makes it a robust tool for large-scale machine learning pipelines.

Summary updated

BibTeX
@inproceedings{cutkosky2023mechanic,
  author = {Ashok Cutkosky and Aaron Defazio and Harsh Mehta},
  title = {{Mechanic: A Learning Rate Tuner}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=uhKtQMn21D},
}
Figure