Using Optuna for hyperparameter search
Optuna is one of the hyperparameter search tools that supports PyTorch. You can read in detail about the search strategies used by the tool, such as Tree-Structured Parzen Estimation (TPE) and Covariance Matrix Adaptation Evolution Strategy (CMA-ES), in the Optuna paper [11]. Besides the advanced hyperparameter search methodologies, the tool also provides a sleek API, which we will explore in a moment.
In this section, we will once again build and train the MNIST model, but this time, using Optuna to figure out the optimal hyperparameter setting. We will discuss important parts of the code step by step in the form of an exercise. The full code can be found on our GitHub [12].
Defining the model architecture and loading the dataset
First, we will define an Optuna-compliant model object. By Optuna-compliant, we mean adding APIs within the model definition code that are provided by Optuna to enable the parameterization of the model hyperparameters...