I am using optuna
as the backend in trainer.hyperparameter_search()
. I would like to use grid search in this method.
Even though optuna
does support grid search (see optuna
doc), I could not see in how do I implement this with trainer.hyperparameter_search()
as it seems the method used here defaults to some complicated strategy and there is no way to change this default behavior.
I know I could set several categorical values like following but this will still use default search algorithm rather than enumerating all possible combinations (there should be 3\times 3=9 parameters to try). So even if I set n_trail=9
, the search algorithm might not look at all 9 combinations.
def hp_space_optuna(trial):
return {
"learning_rate": trial.suggest_categorical("learning_rate", [1e-5, 3e-5, 5e-5]),
"num_train_epochs": trial.suggest_int("num_train_epochs", 1, 3),
}
best_trail = trainer.hyperparameter_search(hp_space=hp_space_optuna,
direction="maximize",
backend="optuna",
n_trials=9)
I am wondering how do I directly use grid search in trainer.hyperparameter_search()
.