ray.tune.search.Searcher — Ray 2.46.0 (original) (raw)
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 thesuggest
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 methodsuggest
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 updateair/_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 | 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 | Restore state for this search algorithm |
restore_from_dir | Restores the state of a searcher from a given checkpoint_dir. |
save | Save state to path for this search algorithm. |
save_to_dir | Automatically saves the given searcher to the checkpoint_dir. |
set_max_concurrency | Set max concurrent trials this searcher can run. |
set_search_properties | Pass search properties to searcher. |
suggest | Queries the algorithm to retrieve the next set of parameters. |
Attributes