ray.tune.search.nevergrad.NevergradSearch#

class ray.tune.search.nevergrad.NevergradSearch(optimizer: nevergrad.optimization.Optimizer | Type[nevergrad.optimization.Optimizer] | nevergrad.optimization.base.ConfiguredOptimizer | None = None, optimizer_kwargs: Dict | None = None, space: Dict | nevergrad.p.Parameter | None = None, metric: str | None = None, mode: str | None = None, points_to_evaluate: List[Dict] | None = None)[source]#

Bases: Searcher

Uses Nevergrad to optimize hyperparameters.

Nevergrad is an open source tool from Facebook for derivative free optimization. More info can be found at: facebookresearch/nevergrad.

You will need to install Nevergrad via the following command:

$ pip install nevergrad
Parameters:
  • optimizer – Optimizer class provided from Nevergrad. See here for available optimizers: https://facebookresearch.github.io/nevergrad/optimizers_ref.html#optimizers This can also be an instance of a ConfiguredOptimizer. See the section on configured optimizers in the above link.

  • optimizer_kwargs – Kwargs passed in when instantiating the optimizer

  • space – Nevergrad parametrization to be passed to optimizer on instantiation, or list of parameter names if you passed an optimizer object.

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

Tune automatically converts search spaces to Nevergrad’s format:

import nevergrad as ng

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

current_best_params = [{
    "width": 10,
    "height": 0,
    "activation": relu",
}]

ng_search = NevergradSearch(
    optimizer=ng.optimizers.OnePlusOne,
    metric="mean_loss",
    mode="min",
    points_to_evaluate=current_best_params)

run(my_trainable, config=config, search_alg=ng_search)

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

import nevergrad as ng

space = ng.p.Dict(
    width=ng.p.Scalar(lower=0, upper=20),
    height=ng.p.Scalar(lower=-100, upper=100),
    activation=ng.p.Choice(choices=["relu", "tanh"])
)

ng_search = NevergradSearch(
    optimizer=ng.optimizers.OnePlusOne,
    space=space,
    metric="mean_loss",
    mode="min")

run(my_trainable, search_alg=ng_search)

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.

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.