Implementing Grid Search
Grid Search is one of the variants of the Exhaustive Search hyperparameter tuning group (see Chapter 3) that the NNI package can implement. To show you how we can implement Grid Search with the NNI package, let’s use the same data and pipeline as in the examples in the previous section. However, here, we’ll define a new hyperparameter space since NNI supports only limited types of sampling distribution.
The following code shows how to implement Grid Search with the NNI package. Here, we’ll use the NNI command-line tool (nnictl) instead of using pure Python code. You can find the more detailed code in the GitHub repository mentioned in the Technical requirements section:
- Prepare the model to be tuned in a script. Here, we’ll name the script
model.py
. There are several functions defined within this script, includingload_data
,get_default_parameters
,get_model
, andrun
.