returnn.tf.hyper_param_tuning
#
Here we provide some logic to perform hyper-parameter search.
See demos/demo-hyper-param-tuning.config
for an example config.
For each entry in the config where search should be performed on,
you declare it as an instance of HyperParam
.
Then, this module will find all such instances in the config and replace it with values during search.
The search itself is some evolutionary genetic search. There are many variants to it, e.g. such as what kind of manipulations you, e.g. cross-over and mutation, and also, how you sample new random values. The current logic probably can be improved.
Currently, each search is a training started from the scratch, and the accumulated train score is used as an evaluation measure. This probably also can be improved. Also, instead of always starting from scratch, we could keep intermediate results and resume from them, or use real training intermediate results and resume from them. We could even do some simple search in the beginning of each epoch when we keep it cheap enough.
Also, we could store the population of hyper params on disk to allow resuming of a search.
- class returnn.tf.hyper_param_tuning.HyperParam(dtype=None, bounds=None, classes=None, log=False, default=None)[source]#
Represents one hyper parameter.
- Parameters:
dtype (str|type|None|list) – e.g. “float”, “int” or “bool”, or if Collection, will be classes
bounds (None|list[int|float]) – inclusive
classes (list|None) –
log (bool) – if in log-scale
default (float|int|object|None) –
- merge_values(value1, value2)[source]#
Merge two values, which are valid values for this HyperParam.
- Parameters:
value1 (T) –
value2 (T) –
- Return type:
T
- get_value(selected, eps=1e-16)[source]#
- Parameters:
selected (float) – must be between 0 and 1
eps (float) – if in log-space and you have e.g. bounds=[0,1], will be the lowest value, before 0. see code.
- Return type:
float|int|bool|object
- class returnn.tf.hyper_param_tuning.Individual(hyper_param_mapping, name)[source]#
One instance of hyper params.
- Parameters:
hyper_param_mapping (dict[HyperParam]) –
name (str) –
- cross_over(hyper_params, population, random_seed)[source]#
- Parameters:
hyper_params (list[HyperParam]) –
population (list[Individual]) –
random_seed (int) –
- Returns:
copy of self, cross-overd with others
- Return type:
- class returnn.tf.hyper_param_tuning.Optimization(config, train_data)[source]#
Hyper parameter optimization handler class.
- Parameters:
config (returnn.config.Config) –
train_data (Dataset) –
- get_population(iteration_idx, num_individuals)[source]#
- Parameters:
iteration_idx (int) –
num_individuals (int) –
- Return type:
list[Individual]
- get_individual(iteration_idx, individual_idx)[source]#
- Parameters:
iteration_idx (int) –
individual_idx (int) –
- Return type:
- cross_over(population, iteration_idx)[source]#
- Parameters:
population (list[Individual]) – modified in-place
iteration_idx (int) –
- create_config_instance(hyper_param_mapping, gpu_ids)[source]#
- Parameters:
hyper_param_mapping (dict[HyperParam]) – maps each hyper param to some value
gpu_ids (set[int]) –
- Return type: