Hyperparameter Search using Trainer API
Last updated
Last updated
π Transformers provides a class optimized for training π Transformers models, making it easier to start training without manually writing your own training loop. The provides API for hyperparameter search. This doc shows how to enable it in example.
supports four hyperparameter search backends currently: , , and .
you should install them before using them as the hyperparameter search backend
Copied
Define the hyperparameter search space, different backends need different format.
For sigopt, see sigopt , itβs like following:
Copied
Copied
Copied
Copied
Copied
Copied
Copied
Call hyperparameter search, get the best trial parameters, backend could be "optuna"
/"sigopt"
/"wandb"
/"ray"
. direction can be"minimize"
or "maximize"
, which indicates whether to optimize greater or lower objective.
You could define your own compute_objective function, if not defined, the default compute_objective will be called, and the sum of eval metric like f1 is returned as objective value.
Copied
Currently, Hyperparameter search for DDP is enabled for optuna and sigopt. Only the rank-zero process will generate the search trial and pass the argument to other ranks.
For optuna, see optuna , itβs like following:
Optuna provides multi-objective HPO. You can pass direction
in hyperparameter_search
and define your own compute_objective to return multiple objective values. The Pareto Front (List[BestRun]
) will be returned in hyperparameter_search, you should refer to the test case TrainerHyperParameterMultiObjectOptunaIntegrationTest
in . Itβs like following
For raytune, see raytune , itβs like following:
For wandb, see wandb , itβs like following:
Define a model_init
function and pass it to the , as an example:
Create a with your model_init
function, training arguments, training and test datasets, and evaluation function: