Hyperparameter Search with Transformers and Ray Tune

📰 Hugging Face Blog

Use Ray Tune for hyperparameter search with Transformers to improve model performance

intermediate Published 2 Nov 2020
Action Steps
  1. Install Ray Tune and Hugging Face Transformers library
  2. Define the search space for hyperparameters
  3. Use Ray Tune's built-in schedulers, such as PBT or Bayesian Optimization, to perform hyperparameter search
  4. Evaluate the performance of the model with the optimized hyperparameters
Who Needs to Know This

Data scientists and machine learning engineers can benefit from using Ray Tune to optimize hyperparameters for their Transformer models, leading to improved performance and efficiency

Key Insight

💡 Advanced hyperparameter tuning techniques like PBT and Bayesian Optimization can significantly improve model performance compared to simple grid search

Share This
🚀 Boost your Transformer model's performance with Ray Tune's hyperparameter search!

Key Takeaways

Use Ray Tune for hyperparameter search with Transformers to improve model performance

Full Article

Published Time: 2020-11-02T00:00:00.005Z

# Hyperparameter Search with Transformers and Ray Tune

[![Image 1: Hugging Face's logo](https://huggingface.co/front/assets/huggingface_logo-noborder.svg)Hugging Face](https://huggingface.co/)

* [Models](https://huggingface.co/models)
* [Datasets](https://huggingface.co/datasets)
* [Spaces](https://huggingface.co/spaces)
* [Buckets new](https://huggingface.co/storage)
* [Docs](https://huggingface.co/docs)
* [Enterprise](https://huggingface.co/enterprise)
* [Pricing](https://huggingface.co/pricing)
*
*
* * *

* [Log In](https://huggingface.co/login)
* [Sign Up](https://huggingface.co/join)

[Back to Articles](https://huggingface.co/blog)

# [](https://huggingface.co/blog/ray-tune#hyperparameter-search-with-transformers-and-ray-tune) Hyperparameter Search with Transformers and Ray Tune

Published November 2, 2020

[Update on GitHub](https://github.com/huggingface/blog/blob/main/ray-tune.md)

[- [x] Upvote 4](https://huggingface.co/login?next=%2Fblog%2Fray-tune)
* [![Image 2](https://huggingface.co/avatars/a92dea7d853bbabbf60b351c207b6875.svg)](https://huggingface.co/etomoscow "etomoscow")
* [![Image 3](https://cdn-avatars.huggingface.co/v1/production/uploads/645d63c0ce72244df7b36be8/09vhYAzgv1svwvQM4eIE9.jpeg)](https://huggingface.co/Moreza009 "Moreza009")
* [![Image 4](https://cdn-avatars.huggingface.co/v1/production/uploads/noauth/x8e_7GDCWVKREXUJeV6uw.png)](https://huggingface.co/AmrataYadav "AmrataYadav")
* [![Image 5](https://huggingface.co/avatars/4ef00e120c2f2db759bb6236dcba7d57.svg)](https://huggingface.co/Cavali "Cavali")

[![Image 6: system's avatar](https://cdn-avatars.huggingface.co/v1/production/uploads/1646125250765-61af81e7a7205fb7cc9ec0cb.png)](https://huggingface.co/system)

[system system Follow](https://huggingface.co/system)

##### [](https://huggingface.co/blog/ray-tune#a-guest-blog-post-by-richard-liaw-from-the-anyscale-team) A guest blog post by Richard Liaw from the Anyscale team

* [Try it out today:](https://huggingface.co/blog/ray-tune#try-it-out-today "Try it out today:")

With cutting edge research implementations, thousands of trained models easily accessible, the Hugging Face [transformers](https://github.com/huggingface/transformers) library has become critical to the success and growth of natural language processing today.
For any machine learning model to achieve good performance, users often need to implement some form of parameter tuning. Yet, nearly everyone ([1](https://medium.com/@prakashakshay90/fine-tuning-bert-model-using-pytorch-f34148d58a37), [2](https://mccormickml.com/2019/07/22/BERT-fine-tuning/#advantages-of-fine-tuning)) either ends up disregarding hyperparameter tuning or opting to do a simplistic grid search with a small search space.

However, simple experiments are able to show the benefit of using an advanced tuning technique. Below is [a recent experiment run on a BERT](https://medium.com/distributed-computing-with-ray/hyperparameter-optimization-for-transformers-a-guide-c4e32c6c989b) model from [Hugging Face transformers](https://github.com/huggingface/transformers) on the [RTE dataset](https://aclweb.org/aclwiki/Textual_Entailment_Resource_Pool). Genetic optimization techniques like [PBT](https://docs.ray.io/en/latest/tune/api_docs/schedulers.html#population-based-training-tune-schedulers-populationbasedtraining) can provide large performance improvements compared to standard hyperparameter optimization techniques.

**Algorithm****Best Val Acc.****Best Test Acc.****Total GPU min****Total $ cost**
Grid Search 74%65.4%45 min$2.30
Bayesian Optimization +Early Stop 77%66.9%104 min$5.30
Population-based Training 78%70.5%48 min$2.45

If you’re leveraging [Transformers](https://github.com/huggingface/transformers), you’ll want to have a way to easily access powerful hyperparameter tuning solutions without giving up the customizability of the Transformers framework.

[![Image 7: alt_text](https://huggin
Read full article → ← Back to Reads

Related Videos

5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
State Spaced Model (SSM) - Mamba LLM models #aiwithakash #genai #aiintamil
State Spaced Model (SSM) - Mamba LLM models #aiwithakash #genai #aiintamil
AI with Akash
9. BERT Special Tokens for Beginners | Explained in Tamil | GenAI | Agents | Embedding Model | BERT
9. BERT Special Tokens for Beginners | Explained in Tamil | GenAI | Agents | Embedding Model | BERT
AI with Akash
8. Tokenizers for Beginners | Explained in Tamil | GenAI | Agents | RAG
8. Tokenizers for Beginners | Explained in Tamil | GenAI | Agents | RAG
AI with Akash
LangSmith or Langfuse? #aiwithakash #genai #aiintamil
LangSmith or Langfuse? #aiwithakash #genai #aiintamil
AI with Akash
RLHF vs DPO #aiwithakash #genai #aiintamil
RLHF vs DPO #aiwithakash #genai #aiintamil
AI with Akash