mirror of
https://github.com/vale981/ray
synced 2025-03-05 18:11:42 -05:00
[Tune] Add soft imports test (#16450)
This commit is contained in:
parent
5967cd3cf3
commit
ec7d7c8630
5 changed files with 134 additions and 77 deletions
|
@ -261,16 +261,24 @@
|
||||||
commands:
|
commands:
|
||||||
- cleanup() { if [ "${BUILDKITE_PULL_REQUEST}" = "false" ]; then ./ci/travis/upload_build_info.sh; fi }; trap cleanup EXIT
|
- cleanup() { if [ "${BUILDKITE_PULL_REQUEST}" = "false" ]; then ./ci/travis/upload_build_info.sh; fi }; trap cleanup EXIT
|
||||||
- TUNE_TESTING=1 ./ci/travis/install-dependencies.sh
|
- TUNE_TESTING=1 ./ci/travis/install-dependencies.sh
|
||||||
- bazel test --config=ci $(./scripts/bazel_export_options) --test_tag_filters=-jenkins_only,-example,-flaky,-py37 python/ray/tune/...
|
- bazel test --config=ci $(./scripts/bazel_export_options) --test_tag_filters=-jenkins_only,-example,-flaky,-py37,-soft_imports python/ray/tune/...
|
||||||
- bazel test --config=ci $(./scripts/bazel_export_options) --build_tests_only --test_tag_filters=example,-tf,-pytorch,-py37,-flaky python/ray/tune/...
|
- bazel test --config=ci $(./scripts/bazel_export_options) --build_tests_only --test_tag_filters=example,-tf,-pytorch,-py37,-flaky,-soft_imports python/ray/tune/...
|
||||||
|
|
||||||
- label: ":octopus: Tune tests and examples {2/2}"
|
- label: ":octopus: Tune tests and examples {2/2}"
|
||||||
conditions: ["RAY_CI_TUNE_AFFECTED"]
|
conditions: ["RAY_CI_TUNE_AFFECTED"]
|
||||||
commands:
|
commands:
|
||||||
- cleanup() { if [ "${BUILDKITE_PULL_REQUEST}" = "false" ]; then ./ci/travis/upload_build_info.sh; fi }; trap cleanup EXIT
|
- cleanup() { if [ "${BUILDKITE_PULL_REQUEST}" = "false" ]; then ./ci/travis/upload_build_info.sh; fi }; trap cleanup EXIT
|
||||||
- TUNE_TESTING=1 ./ci/travis/install-dependencies.sh
|
- TUNE_TESTING=1 ./ci/travis/install-dependencies.sh
|
||||||
- bazel test --config=ci $(./scripts/bazel_export_options) --build_tests_only --test_tag_filters=tf,-pytorch,-py37,-flaky python/ray/tune/...
|
- bazel test --config=ci $(./scripts/bazel_export_options) --build_tests_only --test_tag_filters=tf,-pytorch,-py37,-flaky,-soft_imports python/ray/tune/...
|
||||||
- bazel test --config=ci $(./scripts/bazel_export_options) --build_tests_only --test_tag_filters=-tf,pytorch,-py37,-flaky python/ray/tune/...
|
- bazel test --config=ci $(./scripts/bazel_export_options) --build_tests_only --test_tag_filters=-tf,pytorch,-py37,-flaky,-soft_imports python/ray/tune/...
|
||||||
|
|
||||||
|
- label: ":octopus: Tune soft imports test"
|
||||||
|
conditions: ["RAY_CI_TUNE_AFFECTED"]
|
||||||
|
commands:
|
||||||
|
- cleanup() { if [ "${BUILDKITE_PULL_REQUEST}" = "false" ]; then ./ci/travis/upload_build_info.sh; fi }; trap cleanup EXIT
|
||||||
|
# no TUNE_TESTING=1 on purpose
|
||||||
|
- ./ci/travis/install-dependencies.sh
|
||||||
|
- bazel test --config=ci $(./scripts/bazel_export_options) --build_tests_only --test_tag_filters=soft_imports python/ray/tune/...
|
||||||
|
|
||||||
- label: ":octopus: SGD tests and examples"
|
- label: ":octopus: SGD tests and examples"
|
||||||
conditions: ["RAY_CI_SGD_AFFECTED"]
|
conditions: ["RAY_CI_SGD_AFFECTED"]
|
||||||
|
|
|
@ -203,6 +203,14 @@ py_test(
|
||||||
tags = ["exclusive"],
|
tags = ["exclusive"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
py_test(
|
||||||
|
name = "test_soft_imports",
|
||||||
|
size = "small",
|
||||||
|
srcs = ["tests/test_soft_imports.py"],
|
||||||
|
deps = [":tune_lib"],
|
||||||
|
tags = ["soft_imports"],
|
||||||
|
)
|
||||||
|
|
||||||
py_test(
|
py_test(
|
||||||
name = "test_sync",
|
name = "test_sync",
|
||||||
size = "medium",
|
size = "medium",
|
||||||
|
|
|
@ -7,6 +7,94 @@ from ray.tune.suggest.variant_generator import grid_search
|
||||||
from ray.tune.suggest.repeater import Repeater
|
from ray.tune.suggest.repeater import Repeater
|
||||||
|
|
||||||
|
|
||||||
|
def _import_variant_generator():
|
||||||
|
return BasicVariantGenerator
|
||||||
|
|
||||||
|
|
||||||
|
def _import_ax_search():
|
||||||
|
from ray.tune.suggest.ax import AxSearch
|
||||||
|
return AxSearch
|
||||||
|
|
||||||
|
|
||||||
|
def _import_blendsearch_search():
|
||||||
|
from ray.tune.suggest.flaml import BlendSearch
|
||||||
|
return BlendSearch
|
||||||
|
|
||||||
|
|
||||||
|
def _import_cfo_search():
|
||||||
|
from ray.tune.suggest.flaml import CFO
|
||||||
|
return CFO
|
||||||
|
|
||||||
|
|
||||||
|
def _import_dragonfly_search():
|
||||||
|
from ray.tune.suggest.dragonfly import DragonflySearch
|
||||||
|
return DragonflySearch
|
||||||
|
|
||||||
|
|
||||||
|
def _import_skopt_search():
|
||||||
|
from ray.tune.suggest.skopt import SkOptSearch
|
||||||
|
return SkOptSearch
|
||||||
|
|
||||||
|
|
||||||
|
def _import_hyperopt_search():
|
||||||
|
from ray.tune.suggest.hyperopt import HyperOptSearch
|
||||||
|
return HyperOptSearch
|
||||||
|
|
||||||
|
|
||||||
|
def _import_bayesopt_search():
|
||||||
|
from ray.tune.suggest.bayesopt import BayesOptSearch
|
||||||
|
return BayesOptSearch
|
||||||
|
|
||||||
|
|
||||||
|
def _import_bohb_search():
|
||||||
|
from ray.tune.suggest.bohb import TuneBOHB
|
||||||
|
return TuneBOHB
|
||||||
|
|
||||||
|
|
||||||
|
def _import_nevergrad_search():
|
||||||
|
from ray.tune.suggest.nevergrad import NevergradSearch
|
||||||
|
return NevergradSearch
|
||||||
|
|
||||||
|
|
||||||
|
def _import_optuna_search():
|
||||||
|
from ray.tune.suggest.optuna import OptunaSearch
|
||||||
|
return OptunaSearch
|
||||||
|
|
||||||
|
|
||||||
|
def _import_zoopt_search():
|
||||||
|
from ray.tune.suggest.zoopt import ZOOptSearch
|
||||||
|
return ZOOptSearch
|
||||||
|
|
||||||
|
|
||||||
|
def _import_sigopt_search():
|
||||||
|
from ray.tune.suggest.sigopt import SigOptSearch
|
||||||
|
return SigOptSearch
|
||||||
|
|
||||||
|
|
||||||
|
def _import_hebo_search():
|
||||||
|
from ray.tune.suggest.hebo import HEBOSearch
|
||||||
|
return HEBOSearch
|
||||||
|
|
||||||
|
|
||||||
|
SEARCH_ALG_IMPORT = {
|
||||||
|
"variant_generator": _import_variant_generator,
|
||||||
|
"random": _import_variant_generator,
|
||||||
|
"ax": _import_ax_search,
|
||||||
|
"dragonfly": _import_dragonfly_search,
|
||||||
|
"skopt": _import_skopt_search,
|
||||||
|
"hyperopt": _import_hyperopt_search,
|
||||||
|
"bayesopt": _import_bayesopt_search,
|
||||||
|
"bohb": _import_bohb_search,
|
||||||
|
"nevergrad": _import_nevergrad_search,
|
||||||
|
"optuna": _import_optuna_search,
|
||||||
|
"zoopt": _import_zoopt_search,
|
||||||
|
"sigopt": _import_sigopt_search,
|
||||||
|
"hebo": _import_hebo_search,
|
||||||
|
"blendsearch": _import_blendsearch_search,
|
||||||
|
"cfo": _import_cfo_search,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def create_searcher(
|
def create_searcher(
|
||||||
search_alg,
|
search_alg,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
|
@ -30,78 +118,6 @@ def create_searcher(
|
||||||
>>> search_alg = tune.create_searcher('ax')
|
>>> search_alg = tune.create_searcher('ax')
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _import_variant_generator():
|
|
||||||
return BasicVariantGenerator
|
|
||||||
|
|
||||||
def _import_ax_search():
|
|
||||||
from ray.tune.suggest.ax import AxSearch
|
|
||||||
return AxSearch
|
|
||||||
|
|
||||||
def _import_blendsearch_search():
|
|
||||||
from ray.tune.suggest.flaml import BlendSearch
|
|
||||||
return BlendSearch
|
|
||||||
|
|
||||||
def _import_cfo_search():
|
|
||||||
from ray.tune.suggest.flaml import CFO
|
|
||||||
return CFO
|
|
||||||
|
|
||||||
def _import_dragonfly_search():
|
|
||||||
from ray.tune.suggest.dragonfly import DragonflySearch
|
|
||||||
return DragonflySearch
|
|
||||||
|
|
||||||
def _import_skopt_search():
|
|
||||||
from ray.tune.suggest.skopt import SkOptSearch
|
|
||||||
return SkOptSearch
|
|
||||||
|
|
||||||
def _import_hyperopt_search():
|
|
||||||
from ray.tune.suggest.hyperopt import HyperOptSearch
|
|
||||||
return HyperOptSearch
|
|
||||||
|
|
||||||
def _import_bayesopt_search():
|
|
||||||
from ray.tune.suggest.bayesopt import BayesOptSearch
|
|
||||||
return BayesOptSearch
|
|
||||||
|
|
||||||
def _import_bohb_search():
|
|
||||||
from ray.tune.suggest.bohb import TuneBOHB
|
|
||||||
return TuneBOHB
|
|
||||||
|
|
||||||
def _import_nevergrad_search():
|
|
||||||
from ray.tune.suggest.nevergrad import NevergradSearch
|
|
||||||
return NevergradSearch
|
|
||||||
|
|
||||||
def _import_optuna_search():
|
|
||||||
from ray.tune.suggest.optuna import OptunaSearch
|
|
||||||
return OptunaSearch
|
|
||||||
|
|
||||||
def _import_zoopt_search():
|
|
||||||
from ray.tune.suggest.zoopt import ZOOptSearch
|
|
||||||
return ZOOptSearch
|
|
||||||
|
|
||||||
def _import_sigopt_search():
|
|
||||||
from ray.tune.suggest.sigopt import SigOptSearch
|
|
||||||
return SigOptSearch
|
|
||||||
|
|
||||||
def _import_hebo_search():
|
|
||||||
from ray.tune.suggest.hebo import HEBOSearch
|
|
||||||
return HEBOSearch
|
|
||||||
|
|
||||||
SEARCH_ALG_IMPORT = {
|
|
||||||
"variant_generator": _import_variant_generator,
|
|
||||||
"random": _import_variant_generator,
|
|
||||||
"ax": _import_ax_search,
|
|
||||||
"dragonfly": _import_dragonfly_search,
|
|
||||||
"skopt": _import_skopt_search,
|
|
||||||
"hyperopt": _import_hyperopt_search,
|
|
||||||
"bayesopt": _import_bayesopt_search,
|
|
||||||
"bohb": _import_bohb_search,
|
|
||||||
"nevergrad": _import_nevergrad_search,
|
|
||||||
"optuna": _import_optuna_search,
|
|
||||||
"zoopt": _import_zoopt_search,
|
|
||||||
"sigopt": _import_sigopt_search,
|
|
||||||
"hebo": _import_hebo_search,
|
|
||||||
"blendsearch": _import_blendsearch_search,
|
|
||||||
"cfo": _import_cfo_search,
|
|
||||||
}
|
|
||||||
search_alg = search_alg.lower()
|
search_alg = search_alg.lower()
|
||||||
if search_alg not in SEARCH_ALG_IMPORT:
|
if search_alg not in SEARCH_ALG_IMPORT:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
|
|
@ -11,12 +11,13 @@ from ray.tune.suggest.suggestion import UNRESOLVED_SEARCH_SPACE, \
|
||||||
UNDEFINED_METRIC_MODE, UNDEFINED_SEARCH_SPACE
|
UNDEFINED_METRIC_MODE, UNDEFINED_SEARCH_SPACE
|
||||||
from ray.tune.suggest.variant_generator import parse_spec_vars
|
from ray.tune.suggest.variant_generator import parse_spec_vars
|
||||||
from ray.tune.utils.util import unflatten_dict
|
from ray.tune.utils.util import unflatten_dict
|
||||||
from zoopt import Solution, ValueType
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import zoopt
|
import zoopt
|
||||||
|
from zoopt import Solution, ValueType
|
||||||
except ImportError:
|
except ImportError:
|
||||||
zoopt = None
|
zoopt = None
|
||||||
|
Solution = ValueType = None
|
||||||
|
|
||||||
from ray.tune.suggest import Searcher
|
from ray.tune.suggest import Searcher
|
||||||
|
|
||||||
|
|
24
python/ray/tune/tests/test_soft_imports.py
Normal file
24
python/ray/tune/tests/test_soft_imports.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
class TestSoftImports(unittest.TestCase):
|
||||||
|
"""Tests whether it's possible to use Ray Tune without soft dependencies
|
||||||
|
"""
|
||||||
|
|
||||||
|
def testSoftImports(self):
|
||||||
|
import ray.tune.schedulers # noqa: F401
|
||||||
|
from ray.tune.suggest import SEARCH_ALG_IMPORT
|
||||||
|
for name, import_func in SEARCH_ALG_IMPORT.items():
|
||||||
|
print(f"testing searcher {name}")
|
||||||
|
searcher = import_func()
|
||||||
|
|
||||||
|
# ensure that the dependencies aren't actually installed
|
||||||
|
if searcher and name not in ("variant_generator", "random"):
|
||||||
|
with self.assertRaises(AssertionError):
|
||||||
|
searcher()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import pytest
|
||||||
|
sys.exit(pytest.main(["-v", __file__]))
|
Loading…
Add table
Reference in a new issue