ray.tune.search.Searcher#
- class ray.tune.search.Searcher(metric: str | None = None, mode: str | None = None)[source]#
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
Pass results from a point that has been evaluated separately.
Pass results from trials that have been evaluated separately.
Notification for the completion of trial.
Optional notification for result during training.
Restore state for this search algorithm
Restores the state of a searcher from a given checkpoint_dir.
Save state to path for this search algorithm.
Automatically saves the given searcher to the checkpoint_dir.
Set max concurrent trials this searcher can run.
Pass search properties to searcher.
Queries the algorithm to retrieve the next set of parameters.
Attributes
The training result objective value attribute.
Specifies if minimizing or maximizing the metric.