Skip to content

Commit

Permalink
[tune] Preparation for deadline schedulers (ray-project#22006)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yard1 authored Feb 22, 2022
1 parent dfe4706 commit 4a15c6f
Show file tree
Hide file tree
Showing 19 changed files with 1,315 additions and 123 deletions.
12 changes: 6 additions & 6 deletions doc/source/tune/api_docs/schedulers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ An example of this in use can be found here: :doc:`/tune/examples/xgboost_dynami

.. autoclass:: ray.tune.schedulers.ResourceChangingScheduler

evenly_distribute_cpus_gpus
~~~~~~~~~~~~~~~~~~~~~~~~~~~
DistributeResources
~~~~~~~~~~~~~~~~~~~

.. autofunction:: ray.tune.schedulers.resource_changing_scheduler.evenly_distribute_cpus_gpus
.. autoclass:: ray.tune.schedulers.resource_changing_scheduler.DistributeResources

evenly_distribute_cpus_gpus_distributed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DistributeResourcesToTopJob
~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autofunction:: ray.tune.schedulers.resource_changing_scheduler.evenly_distribute_cpus_gpus_distributed
.. autoclass:: ray.tune.schedulers.resource_changing_scheduler.DistributeResourcesToTopJob

FIFOScheduler
-------------
Expand Down
8 changes: 8 additions & 0 deletions python/ray/tune/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ py_test(
tags = ["team:ml", "exclusive", "tests_dir_T"],
)

py_test(
name = "test_trial_scheduler_resource_changing",
size = "small",
srcs = ["tests/test_trial_scheduler_resource_changing.py"],
deps = [":tune_lib"],
tags = ["team:ml", "exclusive", "tests_dir_T"],
)

py_test(
name = "test_tune_restore_warm_start",
size = "large",
Expand Down
8 changes: 4 additions & 4 deletions python/ray/tune/examples/xgboost_dynamic_resources_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def example_resources_allocation_function(
trial has currently, the scheduler will skip the update process
internally (same with None).
See :func:`evenly_distribute_cpus_gpus` for a more complex,
See :class:`DistributeResources` for a more complex,
robust approach.
Args:
Expand Down Expand Up @@ -221,15 +221,15 @@ def example_resources_allocation_function(
return PlacementGroupFactory([{"CPU": cpu_to_use, "GPU": 0}])

# You can either define your own resources_allocation_function, or
# use the default one - evenly_distribute_cpus_gpus
# use the default one - DistributeResources

# from ray.tune.schedulers.resource_changing_scheduler import \
# evenly_distribute_cpus_gpus
# DistributeResources

scheduler = ResourceChangingScheduler(
base_scheduler=base_scheduler,
resources_allocation_function=example_resources_allocation_function
# resources_allocation_function=evenly_distribute_cpus_gpus # default
# resources_allocation_function=DistributeResources() # default
)

if use_class_trainable:
Expand Down
3 changes: 2 additions & 1 deletion python/ray/tune/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Experiment:
"""

# Keys that will be present in `public_spec` dict.
PUBLIC_KEYS = {"stop", "num_samples"}
PUBLIC_KEYS = {"stop", "num_samples", "time_budget_s"}

def __init__(
self,
Expand Down Expand Up @@ -188,6 +188,7 @@ def __init__(
spec = {
"run": self._run_identifier,
"stop": stopping_criteria,
"time_budget_s": time_budget_s,
"config": config,
"resources_per_trial": resources_per_trial,
"num_samples": num_samples,
Expand Down
1 change: 1 addition & 0 deletions python/ray/tune/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"iterations_since_restore",
"timesteps_since_restore",
"config",
"warmup_time",
)

# __duplicate__ is a magic keyword used internally to
Expand Down
4 changes: 3 additions & 1 deletion python/ray/tune/schedulers/async_hyperband.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def __init__(
self._metric_op = -1.0
self._time_attr = time_attr

def set_search_properties(self, metric: Optional[str], mode: Optional[str]) -> bool:
def set_search_properties(
self, metric: Optional[str], mode: Optional[str], **spec
) -> bool:
if self._metric and metric:
return False
if self._mode and mode:
Expand Down
4 changes: 3 additions & 1 deletion python/ray/tune/schedulers/hyperband.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def __init__(
self._time_attr = time_attr
self._stop_last_trials = stop_last_trials

def set_search_properties(self, metric: Optional[str], mode: Optional[str]) -> bool:
def set_search_properties(
self, metric: Optional[str], mode: Optional[str], **spec
) -> bool:
if self._metric and metric:
return False
if self._mode and mode:
Expand Down
4 changes: 3 additions & 1 deletion python/ray/tune/schedulers/median_stopping_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def __init__(
self._last_pause = collections.defaultdict(lambda: float("-inf"))
self._results = collections.defaultdict(list)

def set_search_properties(self, metric: Optional[str], mode: Optional[str]) -> bool:
def set_search_properties(
self, metric: Optional[str], mode: Optional[str], **spec
) -> bool:
if self._metric and metric:
return False
if self._mode and mode:
Expand Down
4 changes: 3 additions & 1 deletion python/ray/tune/schedulers/pbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ def __init__(
self._num_checkpoints = 0
self._num_perturbations = 0

def set_search_properties(self, metric: Optional[str], mode: Optional[str]) -> bool:
def set_search_properties(
self, metric: Optional[str], mode: Optional[str], **spec
) -> bool:
if self._metric and metric:
return False
if self._mode and mode:
Expand Down
Loading

0 comments on commit 4a15c6f

Please sign in to comment.