mirror of
https://github.com/wassname/ray.git
synced 2026-07-24 13:20:22 +08:00
[tune] implement shim instantiation (#10456)
* Create ray.tune.suggest.create.create_scheduler * Update __init__.py * Resolve conflict in __init__.py * Create ray.tune.schedulers.create.create_scheduler * Update __init__.py * Move create_scheduler to tune.schedulers.__init__ * Move create_searcher to tune.suggest.__init__ * Delete tune.suggest.create * Delete tune.schedulers.create * Update imports for shim functions in tune.__init__ * Remove shim from tune.suggest.__init__.__all__ * Remove shim from tune.schedulers.__init__.__all__ * Add ShimCreationTest * Move ShimCreationTest to test_api * Delete test_shim.py * Add docstring for ray.tune.create_scheduler * Add docstring to ray.tune.create_searcher * Fix typo in ray.tune.create_scheduler docstring * Fix lint errors in tune.schedulers.__init__ * Fix lint errors in tune.suggest.__init__ * Fix lint errors in tune.suggest.__init__ * Fix lint errors in tune.schedulers.__init__ * Fix imports in test_api * Fix lint errors in test_api * Fix kwargs in create_searcher * Fix kwargs in create_scheduler * Merge branch 'master' into shim-instantiation * Update use-case in docs in tune.create_scheduler * Update use-case in docs in tune.create_searcher * Remove duplicate pytest run from test_api * Add check to create_searcher Co-authored-by: Richard Liaw <rliaw@berkeley.edu> * Add check to create_scheduler * lint * Compare types of instances in test_api Co-authored-by: Richard Liaw <rliaw@berkeley.edu> * Add tune.create_searcher to docs * Fix doc build * Fix tests * Add tune.create_scheduler to docs * Fix tests * Fix lint errors * Update Ax search for master * Fix metric kwarg for Ax in test_api * Fix doc build * Fix HyperOptSearch import in test_api * Fix HyperOptSearch import in create_searcher Co-authored-by: Richard Liaw <rliaw@berkeley.edu>
This commit is contained in:
co-authored by
Richard Liaw
parent
f03e91788a
commit
54215ff287
@@ -7,6 +7,69 @@ from ray.tune.schedulers.median_stopping_rule import MedianStoppingRule
|
||||
from ray.tune.schedulers.pbt import (PopulationBasedTraining,
|
||||
PopulationBasedTrainingReplay)
|
||||
|
||||
|
||||
def create_scheduler(
|
||||
scheduler,
|
||||
metric="episode_reward_mean",
|
||||
mode="max",
|
||||
**kwargs,
|
||||
):
|
||||
"""Instantiate a scheduler based on the given string.
|
||||
|
||||
This is useful for swapping between different schedulers.
|
||||
|
||||
Args:
|
||||
scheduler (str): The scheduler to use.
|
||||
metric (str): The training result objective value attribute. Stopping
|
||||
procedures will use this attribute.
|
||||
mode (str): One of {min, max}. Determines whether objective is
|
||||
minimizing or maximizing the metric attribute.
|
||||
**kwargs: Additional parameters.
|
||||
These keyword arguments will be passed to the initialization
|
||||
function of the chosen class.
|
||||
Returns:
|
||||
ray.tune.schedulers.trial_scheduler.TrialScheduler: The scheduler.
|
||||
Example:
|
||||
>>> scheduler = tune.create_scheduler('pbt')
|
||||
"""
|
||||
|
||||
def _import_async_hyperband_scheduler():
|
||||
from ray.tune.schedulers import AsyncHyperBandScheduler
|
||||
return AsyncHyperBandScheduler
|
||||
|
||||
def _import_median_stopping_rule_scheduler():
|
||||
from ray.tune.schedulers import MedianStoppingRule
|
||||
return MedianStoppingRule
|
||||
|
||||
def _import_hyperband_scheduler():
|
||||
from ray.tune.schedulers import HyperBandScheduler
|
||||
return HyperBandScheduler
|
||||
|
||||
def _import_hb_bohb_scheduler():
|
||||
from ray.tune.schedulers import HyperBandForBOHB
|
||||
return HyperBandForBOHB
|
||||
|
||||
def _import_pbt_search():
|
||||
from ray.tune.schedulers import PopulationBasedTraining
|
||||
return PopulationBasedTraining
|
||||
|
||||
SCHEDULER_IMPORT = {
|
||||
"async_hyperband": _import_async_hyperband_scheduler,
|
||||
"median_stopping_rule": _import_median_stopping_rule_scheduler,
|
||||
"hyperband": _import_hyperband_scheduler,
|
||||
"hb_bohb": _import_hb_bohb_scheduler,
|
||||
"pbt": _import_pbt_search,
|
||||
}
|
||||
scheduler = scheduler.lower()
|
||||
if scheduler not in SCHEDULER_IMPORT:
|
||||
raise ValueError(
|
||||
f"Search alg must be one of {list(SCHEDULER_IMPORT)}. "
|
||||
f"Got: {scheduler}")
|
||||
|
||||
SchedulerClass = SCHEDULER_IMPORT[scheduler]()
|
||||
return SchedulerClass(metric=metric, mode=mode, **kwargs)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"TrialScheduler", "HyperBandScheduler", "AsyncHyperBandScheduler",
|
||||
"ASHAScheduler", "MedianStoppingRule", "FIFOScheduler",
|
||||
|
||||
Reference in New Issue
Block a user