Mechanic: A Learning Rate Tuner

Ashok Cutkosky, Aaron Defazio, Harsh Mehta

TL;DR

Mechanic is a plug-and-play meta-optimization wrapper that automatically tunes the global learning rate scale factor for any base optimization algorithm on-the-fly. By bridging the gap between online convex optimization theory and deep learning practice, it eliminates the need for expensive manual learning rate grid searches while matching or exceeding the performance of expertly tuned baselines.

What Problem Does This Paper Address?

Selecting the optimal learning rate is one of the most tedious and resource-intensive aspects of training deep neural networks. Even modern "adaptive" optimizers like Adam or Lion, which adjust learning rates for individual parameters, still rely on a manually tuned global scalar factor. Finding this factor typically requires running multiple expensive grid or random searches.

While prior automatic tuning methods exist, they usually fall into two flawed camps: empirical approaches (like hypergradient descent) that lack robust theoretical guarantees and can be unstable, or theory-driven "learning-rate-free" methods that are hand-crafted for one specific optimizer. The authors of this paper tackle a grander challenge: creating a universal, theoretically grounded, and highly practical learning rate tuner that works as a black-box wrapper around any optimization algorithm.

Methods

Mechanic treats the global learning rate scale factor ($s$) as a variable to be optimized by a separate "meta-optimizer" using the framework of Online Convex Optimization (OCO).

Instead of updating model weights directly, the base optimizer (e.g., AdamW) proposes an update vector ($u_t$). Mechanic then scales this update by its own internal scalar ($s_t$) before applying it to the model. To determine the optimal scale, Mechanic feeds the base optimizer's trajectory into a parameter-free "tuner" algorithm.

To transform pure OCO theory into a practical deep learning tool, the authors introduced two key algorithmic modifications:

  1. Ensembling for Recency Bias: Standard theory struggles with non-convex deep learning landscapes where recent gradients matter more than older ones. Mechanic resolves this by running $n=6$ parallel tuners, each using a different exponential moving average coefficient ($\beta$). It sums their outputs to determine the final scale factor.
  2. Tuner Weight Decay: The authors added a peculiar weight-decay-esque regularization term directly to the tuner's input, which significantly stabilizes training and reduces variance across different random seeds.

Datasets

The authors rigorously evaluated Mechanic across a diverse suite of tasks:

  • Language Modeling: BERT-Base and BERT-Large pre-training on the Wikibooks dataset, followed by fine-tuning on the 5 largest datasets of the GLUE benchmark. They also evaluated an LSTM on IWSLT14 and a GPT Transformer on BookWiki.
  • Image Classification: Pre-training Vision Transformers (ViT-B and ViT-L) on the massive JFT-300M dataset, with fine-tuning on ImageNet, CIFAR-10, and CIFAR-100. They also trained ResNet-18 and WideResNet from scratch on CIFAR.
  • Convex Optimization: A benchmark suite of 12 standard logistic regression datasets (including Sensorless, Aloi, and DNA).

Key Insights and Ideas

  • True Black-Box Flexibility: Mechanic requires zero knowledge of the base optimizer's internal state (like momentum or slot variables). It only needs the final update vector $u_t$, meaning it can seamlessly wrap around future optimization algorithms without modification.
  • Automatic Discovery of Human Heuristics: Without any explicit programming, Mechanic automatically rediscovers well-known empirical heuristics. For instance, it correctly learns to decrease the learning rate scale factor when batch sizes shrink or when the overall model size increases.
Scaling values $s$ learned by Mechanic while varying batch size and model size.
  • The Power of Parameter-Free Ensembling: Running multiple tuners with different $\beta$ values typically introduces a new hyperparameter tuning problem. However, because parameter-free OCO algorithms have bounded worst-case regret, mathematically combining their outputs allows Mechanic to automatically track the best-performing $\beta$ configuration with negligible computational overhead.

Key Results

  • BERT Pre-training & Fine-tuning: Mechanic matched or slightly improved Masked Language Modeling (MLM) accuracy compared to heavily tuned AdamW and Lion baselines. Furthermore, models pre-trained with Mechanic transferred beautifully to downstream GLUE tasks, frequently outperforming the manually tuned baselines.
  • Vision Tasks: When pre-training ViT models on JFT-300M, Mechanic substantially beat the baseline performance. On smaller datasets like ImageNet-1k, it remained highly competitive, landing very close to expertly tuned baselines.
  • Comparison to D-adaptation: Mechanic was compared directly against D-adaptation (another prominent learning-rate-free method). Mechanic proved significantly more versatile, requiring no manual adjustments for different base optimizers, while outperforming D-adaptation on larger language and translation tasks.
Comparing Mechanic with D-adaptation and manually tuned baselines on vision and language tasks.

Limitations and Future Work

  • Incompatibility with Dropout: The authors found that Mechanic does not perform well when combined with dropout regularization. For their fine-tuning experiments, they had to set the dropout rate to 0, noting that exploring why dropout disrupts the tuner is a key area for future research.
  • Train vs. Validation Optimization: Mechanic utilizes training set gradients to learn the learning rate, meaning it optimizes strictly for training loss. Human engineers, by contrast, tune learning rates based on validation set performance to prevent overfitting. Developing a principled way to incorporate validation feedback into an OCO framework remains an open challenge.

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