smac.intensification.successive_halving module

class smac.intensification.successive_halving.SuccessiveHalving(tae_runner: smac.tae.execute_ta_run.ExecuteTARun, stats: smac.stats.stats.Stats, traj_logger: smac.utils.io.traj_logging.TrajLogger, rng: numpy.random.mtrand.RandomState, instances: List[str], instance_specifics: Mapping[str, numpy.ndarray] = None, cutoff: Optional[float] = None, deterministic: bool = False, initial_budget: Optional[float] = None, max_budget: Optional[float] = None, eta: float = 3, num_initial_challengers: Optional[int] = None, run_obj_time: bool = True, n_seeds: Optional[int] = None, instance_order: Optional[str] = 'shuffle_once', adaptive_capping_slackfactor: float = 1.2, inst_seed_pairs: Optional[List[Tuple[str, int]]] = None, min_chall: int = 1, incumbent_selection: str = 'highest_executed_budget')[source]

Bases: smac.intensification.abstract_racer.AbstractRacer

Races multiple challengers against an incumbent using Successive Halving method

Implementation following the description in “BOHB: Robust and Efficient Hyperparameter Optimization at Scale” (Falkner et al. 2018) Supplementary reference: http://proceedings.mlr.press/v80/falkner18a/falkner18a-supp.pdf

Successive Halving intensifier (and Hyperband) can operate on two kinds of budgets: 1. ‘Instances’ as budget:

When multiple instances are provided or when run objective is “runtime”, this is the criterion used as budget for successive halving iterations i.e., the budget determines how many instances the challengers are evaluated on at a time. Top challengers for the next iteration are selected based on the combined performance across all instances used.

If initial_budget and max_budget are not provided, then they are set to 1 and total number of available instances respectively by default.

  1. ‘Real-valued’ budget:

    This is used when there is only one instance provided and when run objective is “quality”, i.e., budget is a positive, real-valued number that can be passed to the target algorithm as an argument. It can be used to control anything by the target algorithm, Eg: number of epochs for training a neural network.

    initial_budget and max_budget are required parameters for this type of budget.

Examples for successive halving (and hyperband) can be found here: * Runtime objective and multiple instances (instances as budget): examples/spear_qcp/SMAC4AC_SH_spear_qcp.py * Quality objective and multiple instances (instances as budget): examples/BOHB4HPO_sgd_instances.py * Quality objective and single instance (real-valued budget): examples/BOHB4HPO_mlp.py

Parameters
  • tae_runner (smac.tae.execute_ta_run.ExecuteTARun Object) – target algorithm run executor

  • stats (smac.stats.stats.Stats) – stats object

  • traj_logger (smac.utils.io.traj_logging.TrajLogger) – TrajLogger object to log all new incumbents

  • rng (np.random.RandomState) –

  • instances (typing.List[str]) – list of all instance ids

  • instance_specifics (typing.Mapping[str,np.ndarray]) – mapping from instance name to instance specific string

  • cutoff (typing.Optional[int]) – cutoff of TA runs

  • deterministic (bool) – whether the TA is deterministic or not

  • initial_budget (typing.Optional[float]) – minimum budget allowed for 1 run of successive halving

  • max_budget (typing.Optional[float]) – maximum budget allowed for 1 run of successive halving

  • eta (float) – ‘halving’ factor after each iteration in a successive halving run. Defaults to 3

  • num_initial_challengers (typing.Optional[int]) – number of challengers to consider for the initial budget. If None, calculated internally

  • run_obj_time (bool) – whether the run objective is runtime or not (if true, apply adaptive capping)

  • n_seeds (typing.Optional[int]) – Number of seeds to use, if TA is not deterministic. Defaults to None, i.e., seed is set as 0

  • instance_order (typing.Optional[str]) – how to order instances. Can be set to: [None, shuffle_once, shuffle] * None - use as is given by the user * shuffle_once - shuffle once and use across all SH run (default) * shuffle - shuffle before every SH run

  • adaptive_capping_slackfactor (float) – slack factor of adpative capping (factor * adaptive cutoff)

  • inst_seed_pairs (typing.List[typing.Tuple[str, int]], optional) – Do not set this argument, it will only be used by hyperband!

  • min_chall (int) – minimal number of challengers to be considered (even if time_bound is exhausted earlier). This class will raise an exception if a value larger than 1 is passed.

  • incumbent_selection (str) – How to select incumbent in successive halving. Only active for real-valued budgets. Can be set to: [highest_executed_budget, highest_budget, any_budget] * highest_executed_budget - incumbent is the best in the highest budget run so far (default) * highest_budget - incumbent is selected only based on the highest budget * any_budget - incumbent is the best on any budget i.e., best performance regardless of budget

_compare_configs(incumbent: ConfigSpace.configuration_space.Configuration, challenger: ConfigSpace.configuration_space.Configuration, run_history: smac.runhistory.runhistory.RunHistory, log_traj: bool = True) → Optional[ConfigSpace.configuration_space.Configuration][source]

Compares the challenger with current incumbent and returns the best configuration, based on the given incumbent selection design.

Parameters
Returns

incumbent configuration

Return type

typing.Optional[Configuration]

_compare_configs_across_budgets(challenger: ConfigSpace.configuration_space.Configuration, incumbent: ConfigSpace.configuration_space.Configuration, run_history: smac.runhistory.runhistory.RunHistory, log_traj: bool = True) → Optional[ConfigSpace.configuration_space.Configuration][source]

compares challenger with current incumbent on any budget

Parameters
Returns

incumbent configuration

Return type

typing.Optional[Configuration]

_init_sh_params(initial_budget: Optional[float], max_budget: Optional[float], eta: float, num_initial_challengers: Optional[int]) → None[source]

initialize Successive Halving parameters

Parameters
  • initial_budget (typing.Optional[float]) – minimum budget allowed for 1 run of successive halving

  • max_budget (typing.Optional[float]) – maximum budget allowed for 1 run of successive halving

  • eta (float) – ‘halving’ factor after each iteration in a successive halving run

  • num_initial_challengers (typing.Optional[int]) – number of challengers to consider for the initial budget

_top_k(configs: List[ConfigSpace.configuration_space.Configuration], run_history: smac.runhistory.runhistory.RunHistory, k: int) → List[ConfigSpace.configuration_space.Configuration][source]

Selects the top ‘k’ configurations from the given list based on their performance.

This retrieves the performance for each configuration from the runhistory and checks that the highest budget they’ve been evaluated on is the same for each of the configurations.

Parameters
Returns

top challenger configurations, sorted in increasing costs

Return type

typing.List[Configuration]

_update_stage(run_history: smac.runhistory.runhistory.RunHistory) → None[source]

Update tracking information for a new stage/iteration and update statistics. This method is called to initialize stage variables and after all configurations of a successive halving stage are completed.

Parameters

run_history (smac.runhistory.runhistory.RunHistory) – stores all runs we ran so far

eval_challenger(challenger: ConfigSpace.configuration_space.Configuration, incumbent: Optional[ConfigSpace.configuration_space.Configuration], run_history: smac.runhistory.runhistory.RunHistory, time_bound: float = 2147483647.0, log_traj: bool = True) → Tuple[ConfigSpace.configuration_space.Configuration, float][source]

Running intensification via successive halving to determine the incumbent configuration. Side effect: adds runs to run_history

Parameters
  • challenger (Configuration) – promising configuration

  • incumbent (typing.Optional[Configuration]) – best configuration so far, None in 1st run

  • run_history (smac.runhistory.runhistory.RunHistory) – stores all runs we ran so far

  • time_bound (float, optional (default=2 ** 31 - 1)) – time in [sec] available to perform intensify

  • log_traj (bool) – whether to log changes of incumbents in trajectory

Returns

incumbent and incumbent cost

Return type

typing.Tuple[Configuration, float]

get_next_challenger(challengers: Optional[List[ConfigSpace.configuration_space.Configuration]], chooser: Optional[smac.optimizer.epm_configuration_chooser.EPMChooser], run_history: smac.runhistory.runhistory.RunHistory, repeat_configs: bool = True) → Tuple[Optional[ConfigSpace.configuration_space.Configuration], bool][source]

Selects which challenger to use based on the iteration stage and set the iteration parameters. First iteration will choose configurations from the chooser or input challengers, while the later iterations pick top configurations from the previously selected challengers in that iteration

Parameters
Returns

  • typing.Optional[Configuration] – next configuration to evaluate

  • bool – flag telling if the configuration is newly sampled or one currently being tracked