Rethinking Learning Rate Tuning in the Era of Language Models
One of the most important hyperparameters
Last updated
Copyright Continuum Labs - 2023
One of the most important hyperparameters
Last updated
The learning rate is a critical hyperparameter that determines the step size used to update the model's weights during optimization.
The authors of this December 2023 paper highlight the recent success of LMs and the trend of fine-tuning pre-trained LMs for various applications due to the high costs associated with training LMs from scratch.
They emphasize the importance of the learning rate as a critical hyperparameter in LM fine-tuning, which directly impacts both fine-tuning efficiency and the quality of the fine-tuned LMs.
The authors argue that existing learning rate policies, primarily designed for traditional deep neural networks (DNNs), may not work well for LM fine-tuning, and there is a need to reassess the research challenges and opportunities in learning rate tuning for LMs.
Based on the analysis provided in the paper, there are several key challenges associated with choosing the right learning rate, both for traditional deep neural network (DNN) training and large language model (LLM) fine-tuning:
The learning rate is one of the most critical hyperparameters in both DNN training and LM fine-tuning. It controls the magnitude of gradients updated on the model parameters, allowing the optimizer to adjust the learning speed for each iteration. Choosing an inappropriate learning rate can significantly impair the training process and the resulting model's performance.
It can be a daunting task to identify a good learning rate. If the learning rate is too small, the model may fail to converge or progress very slowly. On the other hand, if the learning rate is too large, the model may overshoot the optimal solution, leading to suboptimal performance or even divergence.
The conventional method for finding the right learning rate involves manual tuning, where different learning rates are tried one at a time. This trial-and-error approach is tedious, time-consuming, and highly expensive, especially for LLMs with their high complexity and fine-tuning costs.
While there has been research on learning rate policies for traditional DNN training, there is a lack of systematic studies on how to achieve high efficiency and high accuracy in LLM fine-tuning.
Most existing LLM fine-tuning methods still follow similar assumptions and principles to traditional deep learning training/fine-tuning, which may not be optimal given the unique characteristics of LLMs.
The paper discusses several key differences between LMs and traditional DNNs, including:
Model complexity: LMs have billions of parameters, while traditional DNNs have millions
Training/fine-tuning costs: LM training/fine-tuning is much more expensive than traditional DNN training
Model initialization: LM fine-tuning often starts from pre-trained models, while traditional DNN training starts from random initialisation.
Training epochs: LM training/fine-tuning requires fewer epochs (2-3) compared to traditional DNN training (100+).
Evaluation strategies: LM evaluation may involve time-consuming real-world tasks, while traditional DNNs can be quickly evaluated on testing data.
These differences highlight the need to rethink the learning rate tuning paradigm for LLMs.
The authors present LRBench++, a learning rate benchmarking and tuning tool for both traditional DNNs and LLMs.
LRBench++ provides support for LLM implementations, iteration-based LR tuning, and systematic NLP learning tasks for evaluating LLMs.
It also incorporates popular hyperparameter tuning algorithms, such as grid search and random search, and supports different LR tuning methods for various training/fine-tuning objectives.
The LRBench++ system is an enhanced version of LRBench designed for evaluating, selecting, and tuning learning rate (LR) policies to optimise both traditional deep neural network (DNN) training and language model (LM) fine-tuning.
It incorporates several core components and features to address the unique challenges associated with LM training and fine-tuning. Let's dive into the details of each component and how they work together:
The LR schedule monitor continuously tracks the training/fine-tuning status of the DNN/LLM and updates the learning rate value based on the specified LR policy.
Functionality: It closely monitors the progress of the training/fine-tuning process, including metrics such as the current epoch, iteration, and loss values. Based on this information and the selected LR policy, the monitor adjusts the learning rate accordingly. This ensures that the LR is dynamically adapted throughout the training/fine-tuning process.
The LR policy database serves as a repository to store and organise the LR tuning results for different learning tasks.
Functionality: It maintains a structured collection of LR tuning results, categorized by the specific learning task (e.g., image classification, object detection, sentiment analysis). This database allows users to access and leverage previous tuning results, facilitating knowledge sharing and reducing the need for redundant tuning efforts.
The LR value range test employs a grid search approach to determine an appropriate range of LR values, effectively narrowing down the search space.
Functionality: It systematically explores a predefined grid of LR values and evaluates the model's performance for each value. By analysing the results, it identifies a suitable range of LR values that yield good performance. This range serves as a starting point for further fine-grained tuning, saving computational resources and time.
The LR policy visualizer provides a visual representation of the DNN/LLM training/fine-tuning status and the corresponding LR values over time.
Functionality: It generates intuitive visualizations, such as plots and graphs, that display the evolution of the learning rate throughout the training/fine-tuning process. These visualizations help users gain insights into the behavior of different LR policies and their impact on model performance.
The LR policy evaluator assesses and compares alternative LR policies to estimate optimal LR parameters and enables dynamic LR tuning.
Functionality: It conducts a comprehensive evaluation of different LR policies by running multiple training/fine-tuning experiments with varying LR configurations.
By analysing the results, it identifies the most promising LR policies and estimates the best LR parameters for a given learning task. Additionally, it supports dynamic LR tuning, allowing for real-time adjustments based on the model's performance during training/fine-tuning.
LRBench++ incorporates various optimisation techniques to enhance the efficiency and scalability of the LR tuning process.
Grid Search: It performs an exhaustive search over a predefined grid of LR parameter values, evaluating all possible combinations to find the optimal configuration.
Random Search: It randomly samples LR parameter values from a defined search space, allowing for a more efficient exploration compared to grid search.
Distributed Parallel Tuning: Built on top of Ray Tune [30], it enables distributed and parallel execution of LR tuning experiments, leveraging multiple computing resources to accelerate the tuning process.
Single Policy LR Selection
Aims to identify the best single LR policy that maximizes model accuracy within given training/fine-tuning constraints, such as a predefined number of iterations.
Multi-policy LR Composition
Focuses on composing multiple LR policies to achieve optimal model accuracy while adhering to the specified training/fine-tuning constraints.
Cost-effective LR Tuning
Seeks to minimize training costs while reaching a target accuracy threshold, balancing performance and computational resources.
By leveraging these components and features, LRBench++ provides a comprehensive platform for benchmarking and tuning learning rate policies for both traditional DNNs and LLMs.
Its modular design allows users to utilize different modules based on their specific requirements, making it adaptable to various real-world scenarios. LRBench++ aims to serve as a public platform for the community to collect, share, and leverage LR tuning results, fostering collaboration and advancing the field of deep learning and large language models.
The authors summarise common practices in LM fine-tuning settings and discuss the research challenges and opportunities in learning rate tuning for LMs, including cost-effective LR tuning, benchmarking LRs, and evaluating LM performance during training/fine-tuning.
The authors present LRBench++, a valuable tool for benchmarking and tuning learning rates for both traditional DNNs and LLMs. The experimental analysis reveals key insights into the impact of learning rates on LLM fine-tuning and provides a foundation for future research in this area.
When fine-tuning, it's often recommended to use a smaller learning rate than used during pre-training, as you want to make smaller updates to the already learned weights rather than learning from scratch.
We can't always use a high learning rate because it can cause the optimisation algorithm to overshoot the optimal values of the parameters, resulting in instability and slow convergence.
Additionally, a high learning rate can cause the loss to fluctuate wildly, making it difficult to determine whether the model is improving or not.
The function to calculate new weights using a learning rate is:
new_weights = old_weights - learning_rate * gradient
The learning rate is an important parameter, which depends on the optimiser, the model, and many more other hyperparameters.
A usual good starting point is 0.1 for SGD, and 1e-3 for Adam.
The deeper the model is, the lower the learning rate usually should be. For instance, Transformer models usually apply learning rates of 1e-5 to 1e-4 for Adam.
The lower your batch, the lower the learning rate should be. Consider using gradient accumulation if your batch size is getting too small (PyTorch Lightning supports this, see here).
Consider using the PyTorch Lightning learning rate finder toolkit for an initial good guess.
Alpaca-7B: The learning rate is (2e-5). The LR Scheduler used is "WarmupDecayLR". It is trained for 3 epochs with a warmup percentage of 0.03.
Vicuna-7B: The learning rate is (2e-5). It uses the "cosine" learning rate scheduler. The training duration is 3 epochs with a warmup percentage of 0.03.
WizardLM-7B: Here, the learning rate is also (2e-5), with a "cosine" LR scheduler. It's trained for 3 epochs, but the warmup is different, being 2 (which might indicate 2% or 2 epochs, depending on the context).
GPT4All-J-6B: The learning rate is (2e-5) with a "WarmupLR" scheduler. The model is trained for 2 epochs with a warmup of 500, which likely refers to 500 steps.
Dolly-7B: This model has a slightly lower learning rate of (5e-6). It also uses the "WarmupLR" scheduler, is trained for 2 epochs, and has a warmup of 50 steps.
N.B. In scientific notation, "2×10^−5" means 2 times 10 raised to the power of negative 5. This is a way to represent very small or very large numbers succinctly. Specifically, 2×10^−5 is equal to 0.00002.