Skip to content

Add an example using Optuna and Transformers #304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

ParagEkbote
Copy link

What does this PR do?

In this end-to-end tutorial, we are going to utilize the optuna library to perform hyperparameter optimization on a BERT model using the IMDB dataset.

Firstly, we will load and preprocess the dataset and define the model we want to perform HPO on. Then, we shall set the metrics and wrap it inside the trainer class along with a search space that will search the best set of hyperparameters for the learning rate, weight decay and batch size. Lastly, we will visualize the results as well.

Please let me know if any modifications are required and I will make the necessary changes.

Who can review?

@stevhliu.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@stevhliu
Copy link
Member

stevhliu commented Jun 4, 2025

Thanks for your work! However, I don't think its all that different from the current hyperparameter search docs in Transformers except its a more complete example.

@merveenoyan @sergiopaniego what do you think?

@ParagEkbote
Copy link
Author

ParagEkbote commented Jun 4, 2025

Just for the record, I'd actually wanted to include support for the transformer's library in their optuna-integration package. But since there is backend support provided by the transformers library, I contributed an starting example to their repo.

This PR builds on that example and provides a more hands-on approach for users to understand how to apply HPO to transformer models 🙂

@merveenoyan
Copy link
Collaborator

@ParagEkbote cookbook mostly contains end-to-end applied AI recipes where library integrations shine 💫 rather than minimal examples. it would be great to make it a more applied ML type of recipe

@ParagEkbote
Copy link
Author

I have now added the following improvements to the recipe to make it more applied:

  1. The successful trials are now saved in sqlite using RDBStorage.
  2. Observability is now available using Weight & Biases to track and analyze the HPO trials.
  3. Also, we can perform the final training from the optimized parameters and push the model to HF Hub.

Could you please review the changes?

cc: @stevhliu, @merveenoyan

Copy link
Member

@sergiopaniego sergiopaniego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for the contribution, @ParagEkbote! 🙌

To make it more aligned with the rest of the recipes, it would be great to add a bit more context about the problem this recipe is aiming to solve. Including visuals or showcasing the results would also go a long way in making the explanation clearer and more engaging. I’d recommend checking out the other recipes for inspiration 😄 Also, make sure it runs as it is in Colab

What do you think?

@ParagEkbote
Copy link
Author

ParagEkbote commented Jun 17, 2025

Thanks so much for the contribution, @ParagEkbote! 🙌

To make it more aligned with the rest of the recipes, it would be great to add a bit more context about the problem this recipe is aiming to solve. Including visuals or showcasing the results would also go a long way in making the explanation clearer and more engaging. I’d recommend checking out the other recipes for inspiration 😄 Also, make sure it runs as it is in Colab

What do you think?

What type of visuals or results can help for the recipe. Also, are there any specific sections do you think additional context is required?

cc: @sergiopaniego

@sergiopaniego
Copy link
Member

sergiopaniego commented Jun 23, 2025

What type of visuals or results can help for the recipe. Also, are there any specific sections do you think additional context is required?

cc: @sergiopaniego

For example, we currently don't have any output throughout the notebook so we are not displaying any results 😄

@ParagEkbote
Copy link
Author

ParagEkbote commented Jun 25, 2025

The visualizations which can be created:
image

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants