ray.tune.search.bohb.TuneBOHB#

class ray.tune.search.bohb.TuneBOHB(space: Dict | ConfigSpace.ConfigurationSpace | None = None, bohb_config: Dict | None = None, metric: str | None = None, mode: str | None = None, points_to_evaluate: List[Dict] | None = None, seed: int | None = None, max_concurrent: int = 0)[source]#

Bases: Searcher

BOHB suggestion component.

Requires HpBandSter and ConfigSpace to be installed. You can install HpBandSter and ConfigSpace with: pip install hpbandster ConfigSpace.

This should be used in conjunction with HyperBandForBOHB.

Parameters:
  • space – Continuous ConfigSpace search space. Parameters will be sampled from this space which will be used to run trials.

  • bohb_config – configuration for HpBandSter BOHB algorithm

  • metric – The training result objective value attribute. If None but a mode was passed, the anonymous metric _metric will be used per default.

  • mode – One of {min, max}. Determines whether objective is minimizing or maximizing the metric attribute.

  • points_to_evaluate – Initial parameter suggestions to be run first. This is for when you already have some good parameters you want to run first to help the algorithm make better suggestions for future parameters. Needs to be a list of dicts containing the configurations.

  • seed – Optional random seed to initialize the random number generator. Setting this should lead to identical initial configurations at each run.

  • max_concurrent – Number of maximum concurrent trials. If this Searcher is used in a ConcurrencyLimiter, the max_concurrent value passed to it will override the value passed here. Set to <= 0 for no limit on concurrency.

Tune automatically converts search spaces to TuneBOHB’s format:

config = {
    "width": tune.uniform(0, 20),
    "height": tune.uniform(-100, 100),
    "activation": tune.choice(["relu", "tanh"])
}

algo = TuneBOHB(metric="mean_loss", mode="min")
bohb = HyperBandForBOHB(
    time_attr="training_iteration",
    metric="mean_loss",
    mode="min",
    max_t=100)
run(my_trainable, config=config, scheduler=bohb, search_alg=algo)

If you would like to pass the search space manually, the code would look like this:

import ConfigSpace as CS

config_space = CS.ConfigurationSpace()
config_space.add_hyperparameter(
    CS.UniformFloatHyperparameter("width", lower=0, upper=20))
config_space.add_hyperparameter(
    CS.UniformFloatHyperparameter("height", lower=-100, upper=100))
config_space.add_hyperparameter(
    CS.CategoricalHyperparameter(
        name="activation", choices=["relu", "tanh"]))

algo = TuneBOHB(
    config_space, metric="mean_loss", mode="min")
bohb = HyperBandForBOHB(
    time_attr="training_iteration",
    metric="mean_loss",
    mode="min",
    max_t=100)
run(my_trainable, scheduler=bohb, search_alg=algo)

Methods

add_evaluated_point

Pass results from a point that has been evaluated separately.

add_evaluated_trials

Pass results from trials that have been evaluated separately.

restore_from_dir

Restores the state of a searcher from a given checkpoint_dir.

save_to_dir

Automatically saves the given searcher to the checkpoint_dir.

Attributes

CKPT_FILE_TMPL

FINISHED

metric

The training result objective value attribute.

mode

Specifies if minimizing or maximizing the metric.