ray.tune.search.Searcher
ray.tune.search.Searcher#
- class ray.tune.search.Searcher(metric: Optional[str] = None, mode: Optional[str] = None)[source]#
Bases:
object
Abstract class for wrapping suggesting algorithms.
Custom algorithms can extend this class easily by overriding the
suggest
method provide generated parameters for the trials.Any subclass that implements
__init__
must also call the constructor of this class:super(Subclass, self).__init__(...)
.To track suggestions and their corresponding evaluations, the method
suggest
will be passed a trial_id, which will be used in subsequent notifications.Not all implementations support multi objectives.
Note to Tune developers: If a new searcher is added, please update
air/_internal/usage.py
.- Parameters
metric – The training result objective value attribute. If list then list of training result objective value attributes
mode – If string One of {min, max}. If list then list of max and min, determines whether objective is minimizing or maximizing the metric attribute. Must match type of metric.
class ExampleSearch(Searcher): def __init__(self, metric="mean_loss", mode="min", **kwargs): super(ExampleSearch, self).__init__( metric=metric, mode=mode, **kwargs) self.optimizer = Optimizer() self.configurations = {} def suggest(self, trial_id): configuration = self.optimizer.query() self.configurations[trial_id] = configuration def on_trial_complete(self, trial_id, result, **kwargs): configuration = self.configurations[trial_id] if result and self.metric in result: self.optimizer.update(configuration, result[self.metric]) tuner = tune.Tuner( trainable_function, tune_config=tune.TuneConfig( search_alg=ExampleSearch() ) ) tuner.fit()
DeveloperAPI: This API may change across minor Ray releases.
Methods
add_evaluated_point
(parameters, value[, ...])Pass results from a point that has been evaluated separately.
add_evaluated_trials
(trials_or_analysis, metric)Pass results from trials that have been evaluated separately.
on_trial_complete
(trial_id[, result, error])Notification for the completion of trial.
on_trial_result
(trial_id, result)Optional notification for result during training.
restore
(checkpoint_path)Restore state for this search algorithm
restore_from_dir
(checkpoint_dir)Restores the state of a searcher from a given checkpoint_dir.
save
(checkpoint_path)Save state to path for this search algorithm.
save_to_dir
(checkpoint_dir[, session_str])Automatically saves the given searcher to the checkpoint_dir.
set_max_concurrency
(max_concurrent)Set max concurrent trials this searcher can run.
set_search_properties
(metric, mode, config, ...)Pass search properties to searcher.
suggest
(trial_id)Queries the algorithm to retrieve the next set of parameters.
Attributes
The training result objective value attribute.
Specifies if minimizing or maximizing the metric.