How to Perform Hyperparameter Optimization in PyTorch Using Optuna
Last Updated on September 27, 2024 by Editorial Team
Author(s): Benjamin Bodner
Originally published on Towards AI.
This is how you 10X training speed and boost your modelβs performance.
This member-only story is on us. Upgrade to access all of Medium.
Source: Image made by author with Dall E 3All neural networks require hyperparameters to be selected as part of the training process, and they can have very significant effects on the speed of convergence and final performance.
These hyperparameters require special tuning to maximize the potential of your model properly. This hyperparameter tuning process is an integral part of neural network training, and it is, in a sense, the βgradient-freeβ component in a mostly βgradient-basedβ optimization problem.
In this post, we will explore one of the leading libraries in hyperparameter optimization, Optuna, which makes the process super simple and highly effective. Weβll break down the process into 5 simple steps.
Weβll start by importing the relevant packages and creating a simple, fully-connected neural network using PyTorch. A fully connected neural network is defined with one hidden layer.
For reproducibility, we also set a manual random seed.
Next, weβll set up the standard components we will need for hyperparameter optimization. Weβll perform the following steps:
1. Download the FashionMNIST dataset.
2. Define the hyperparameter search space: We define (a) which hyperparameters we want to optimize and (b) what values we want to allow them to take. In… Read the full blog for free on Medium.
Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming aΒ sponsor.
Published via Towards AI