ray.tune.search.skopt.SkOptSearch#

class ray.tune.search.skopt.SkOptSearch(optimizer: skopt.optimizer.Optimizer | None = None, space: List[str] | Dict[str, Tuple | List] = None, metric: str | None = None, mode: str | None = None, points_to_evaluate: List[Dict] | None = None, evaluated_rewards: List | None = None, convert_to_python: bool = True)[source]#

Bases: Searcher

Uses Scikit Optimize (skopt) to optimize hyperparameters.

Scikit-optimize is a black-box optimization library. Read more here: https://scikit-optimize.github.io.

You will need to install Scikit-Optimize to use this module.

pip install scikit-optimize

This Search Algorithm requires you to pass in a skopt Optimizer object.

This searcher will automatically filter out any NaN, inf or -inf results.

Parameters:
  • optimizer – Optimizer provided from skopt.

  • space – A dict mapping parameter names to valid parameters, i.e. tuples for numerical parameters and lists for categorical parameters. If you passed an optimizer instance as the optimizer argument, this should be a list of parameter names instead.

  • 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.

  • evaluated_rewards – If you have previously evaluated the parameters passed in as points_to_evaluate you can avoid re-running those trials by passing in the reward attributes as a list so the optimiser can be told the results without needing to re-compute the trial. Must be the same length as points_to_evaluate.

  • convert_to_python – SkOpt outputs numpy primitives (e.g. np.int64) instead of Python types. If this setting is set to True, the values will be converted to Python primitives.

Tune automatically converts search spaces to SkOpt’s format:

config = {
    "width": tune.uniform(0, 20),
    "height": tune.uniform(-100, 100)
}

current_best_params = [
    {
        "width": 10,
        "height": 0,
    },
    {
        "width": 15,
        "height": -20,
    }
]

skopt_search = SkOptSearch(
    metric="mean_loss",
    mode="min",
    points_to_evaluate=current_best_params)

tuner = tune.Tuner(
    trainable_function,
    tune_config=tune.TuneConfig(
        search_alg=skopt_search
    ),
    param_space=config
)
tuner.fit()

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

parameter_names = ["width", "height"]
parameter_ranges = [(0,20),(-100,100)]
current_best_params = [[10, 0], [15, -20]]

skopt_search = SkOptSearch(
    parameter_names=parameter_names,
    parameter_ranges=parameter_ranges,
    metric="mean_loss",
    mode="min",
    points_to_evaluate=current_best_params)

tuner = tune.Tuner(
    trainable_function,
    tune_config=tune.TuneConfig(
        search_alg=skopt_search
    ),
)
tuner.fit()

Methods

add_evaluated_trials

Pass results from trials that have been evaluated separately.

on_trial_complete

Notification for the completion of trial.

on_trial_result

Optional notification for result during training.

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.

set_max_concurrency

Set max concurrent trials this searcher can run.

Attributes

CKPT_FILE_TMPL

FINISHED

metric

The training result objective value attribute.

mode

Specifies if minimizing or maximizing the metric.