Stay Tuned: An Empirical Study of the Impact of Hyperparameters on LLM Tuning in Real-World Applications

Alon Halfon, Shai Gretz, Ofir Arviv, Artem Spector, Orith Toledo-Ronen, Yoav Katz, Liat Ein-Dor, Michal Shmueli-Scheuer, Noam SlonimarXiv 2024

Abstract: Fine-tuning Large Language Models (LLMs) is an effective method to enhance their performance on downstream tasks. However, choosing the appropriate setting of tuning hyperparameters (HPs) is a labor-intensive and computationally expensive process. Here, we provide recommended HP configurations for practical use-cases that represent a better starting point for practitioners, when considering two SOTA LLMs and two commonly used tuning methods. We describe Coverage-based Search (CBS), a process for ranking HP configurations based on an offline extensive grid search, such that the top ranked configurations collectively provide a practical robust recommendation for a wide range of datasets and domains. We focus our experiments on Llama-3-8B and Mistral-7B, as well as full fine-tuning and LoRa, conducting a total of > 10,000 tuning experiments. Our results suggest that, in general, Llama-3-8B and LoRA should be preferred, when possible. Moreover, we show that for both models and tuning methods, exploring only a few HP configurations, as recommended by our analysis, can provide excellent results in practice, making this work a valuable resource for practitioners.

Introduction

Adapting Large Language Models (LLMs) to specific domains typically involves fine-tuning, a process notoriously sensitive to hyperparameters (HPs) like learning rate, batch size, and epoch count. For practitioners in enterprise settings—who often work with small datasets of 100 to 1,000 samples—conducting an exhaustive grid search for every new task is computationally prohibitive. This paper introduces Coverage-based Search (CBS) to identify robust hyperparameter configurations that work across diverse tasks, providing a concrete "cheat sheet" for Llama-3 and Mistral-7B that significantly outperforms standard defaults.

Methodology

The authors conducted a massive empirical study involving over 10,000 tuning experiments. They compared two state-of-the-art models, Llama-3-8B and Mistral-7B-v0.3, using two primary methods: Full Fine-Tuning (FFT) and Low-Rank Adaptation (LoRA).

The experimental design space across models, tuning methods, tasks, and hyperparameters.

The core contribution is the Coverage-based Search (CBS) algorithm. Instead of simply averaging performance across datasets, CBS ranks HP configurations based on their "coverage." A configuration "covers" a dataset if it achieves a score within 3% of the absolute best possible result found during an exhaustive grid search for that specific dataset. This approach identifies settings that are likely to perform well on new, unseen datasets. The study utilized 13 diverse datasets across three primary tasks: Text Classification, Summarization, and Contextual Question Answering (CQA).

Key Insights

  • LoRA as a Default: In small-data scenarios, LoRA frequently matched or outperformed Full Fine-Tuning. Given its lower hardware requirements, the authors recommend LoRA as the default choice for practical applications.
  • Model Dominance: Llama-3-8B showed a clear performance advantage over Mistral-7B-v0.3 across almost all tasks.
  • The "Default" Trap: Standard hyperparameters provided by popular libraries often perform poorly on small datasets. For instance, in Mistral-7B FFT classification with 100 samples, default settings yielded a ~4% score, whereas the CBS-recommended setting achieved ~58%.
  • Efficiency of Search: Trying just the top 1 or 2 CBS-recommended configurations yields results very close to the theoretical "upper bound" (the best possible result from a full grid search).

The study provides a definitive ranking of hyperparameter configurations. The top-ranked CBS configuration (CBS_1) consistently outperformed "Default" settings by large margins across all tasks and models.

Top-ranked hyperparameter configurations for Mistral-7B and Llama-3-8B across tuning methods.

For LoRA, a learning rate of 5e-5 was frequently optimal for both models, while FFT required much smaller rates, typically between 5e-6 and 1e-5.

Conclusion

While this study provides a valuable resource for practitioners, it is limited to learning rate, scheduler, batch size, and epochs. Future work could explore additional factors like warmup ratios or weight decay. As new models are released, these specific recommendations will need updating to maintain their relevance in the rapidly evolving LLM landscape.

Summary updated

BibTeX
@misc{halfon2024stay,
  author = {Alon Halfon and Shai Gretz and Ofir Arviv and Artem Spector and Orith Toledo-Ronen and Yoav Katz and Liat Ein-Dor and Michal Shmueli-Scheuer and Noam Slonim},
  title = {{Stay Tuned: An Empirical Study of the Impact of Hyperparameters on LLM Tuning in Real-World Applications}},
  year = {2024},
  eprint = {2407.18990},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.18990},
}
Figure