EasyTPP Hyper-parameter Optimization Modules#

Use pipeline_config_id: hpo_runner_config with the same data and experiment sections as a normal runner configuration. Add:

hpo:
  storage_uri: sqlite://hpo_test.db
  is_continuous: false
  framework_id: optuna
  num_trials: 10
  num_jobs: 1

The trial-count key is num_trials. Runner construction initializes its data loader and reads training statistics; skip_data_loader has been removed.

From the repository root, run the provided example:

python examples/train_nhp_hpo.py --config_dir examples/configs/hpo_config.yaml --experiment_id NHP_train

The script builds a config through Config.build_from_yaml_file, then calls HyperTuner.build_from_config(config).run(). Optuna must be installed to run HPO.

class easy_tpp.hpo.HyperTuner(config, trial_end_callbacks: List[callable] = None)#

Bases: Registrable

static build_from_config(config, trial_end_callbacks: List[callable] = None)#

Load yaml config file from disk.

Parameters:
  • config (EasyTPP.Config) – config class

  • trial_end_callbacks (List[callable]) – List of callback functions to be executed after each trial.

Returns:

Config object corresponding to cls.

Return type:

EasyTPP.Config

abstractmethod get_all_best_runner_configs()#
abstractmethod get_best_runner_config_by_name(runner_id)#
Parameters:

runner_id (str)

Returns:

abstractmethod get_num_remain_trials_by_name(runner_id)#
classmethod get_registered_name()#

Get the name of the registered hpo class.

Returns:

the name of the registered hpo class.

Return type:

str

classmethod register_trial_func(model_id, overwrite=True)#

Register the trial functions in HPO

Parameters:
  • model_id (str) – id of the models.

  • overwrite (bool, optional) – whether to overwrite the trial function. Defaults to True.

Returns:

the registered trial function

Return type:

dict

classmethod retrieve_trial_func_by_model_name(name)#

Retrieve the trail function by the model id

Parameters:

name (str) – model id.

Raises:

RuntimeError – non registered error for the hpo framework.

Returns:

registered trial center

Return type:

dict

abstractmethod run()#

Run the process.

Raises:

NotImplementedError – error raised in base class.

class easy_tpp.hpo.OptunaTuner(config, trial_end_callbacks)#

Bases: HyperTuner

get_all_best_runner_configs()#

Get all best runner configs. Obtain from storage.

Returns:

Dict of all best runner configs.

Return type:

Dict[str, EasyTPP.RunnerConfig]

get_best_runner_config_by_name(exp_id)#

Get the best runner config by runner_id. Obtain it from storage.

Parameters:

exp_id (str) – experiment id.

Returns:

best runner config.

Return type:

EasyTPP.RunnerConfig

get_num_remain_trials_by_name(exp_id)#

Get the num of remaining trails by experiment id.

Parameters:

exp_id (str) – experiment id.

Returns:

num of remaining trails.

Return type:

int

optimize(base_runner_config, train_loader=None, valid_loader=None, test_loader=None, exp_id=None, **kwargs)#

Run the optimization process.

Parameters:
  • base_runner_config (EasyTPP.RunnerConfig) – runner config.

  • train_loader (EasyTPP.DataLoader) – train data loader.

  • valid_loader (EasyTPP.DataLoader) – valid data loader

  • test_loader (EasyTPP.DataLoader, optional) – test data loader. Defaults to None.

  • exp_id (str, optional) – experiment id. Defaults to None.

Raises:

RuntimeError – best trial is not found.

Returns:

best_metric and best_runner_config

Return type:

tuple

run()#

Run the HPO process.

Returns:

best_metric, best_runner_config

Return type:

tuple