A programming framework for agentic AI
move searcher and scheduler into tune (#746)
Chi Wang860cbc233e3a
diff --git a/flaml/__init__.py b/flaml/__init__.pyindex 87bb428b3..ecd80cf69 100644--- a/flaml/__init__.py+++ b/flaml/__init__.py@@ -1,4 +1,4 @@-from flaml.searcher import CFO, BlendSearch, FLOW2, BlendSearchTuner, RandomSearch+from flaml.tune.searcher import CFO, BlendSearch, FLOW2, BlendSearchTuner, RandomSearchfrom flaml.automl import AutoML, logger_formatterfrom flaml.onlineml.autovw import AutoVWfrom flaml.version import __version__diff --git a/flaml/automl.py b/flaml/automl.pyindex e830856e7..f91074cac 100644--- a/flaml/automl.py+++ b/flaml/automl.py@@ -2961,7 +2961,7 @@ class AutoML(BaseEstimator):else:from ray.tune.search.optuna import OptunaSearch as SearchAlgoexcept (ImportError, AssertionError):- from .searcher.suggestion import OptunaSearch as SearchAlgo+ from flaml.tune.searcher.suggestion import OptunaSearch as SearchAlgoelse:raise NotImplementedError(f"hpo_method={self._hpo_method} is not recognized. "@@ -3125,7 +3125,7 @@ class AutoML(BaseEstimator):else:from ray.tune.search import ConcurrencyLimiterexcept (ImportError, AssertionError):- from .searcher.suggestion import ConcurrencyLimiter+ from flaml.tune.searcher.suggestion import ConcurrencyLimiterif self._hpo_method in ("cfo", "grid"):from flaml import CFO as SearchAlgoelif "optuna" == self._hpo_method:@@ -3138,13 +3138,13 @@ class AutoML(BaseEstimator):else:from ray.tune.search.optuna import OptunaSearch as SearchAlgoexcept (ImportError, AssertionError):- from .searcher.suggestion import OptunaSearch as SearchAlgo+ from flaml.tune.searcher.suggestion import OptunaSearch as SearchAlgoelif "bs" == self._hpo_method:from flaml import BlendSearch as SearchAlgoelif "random" == self._hpo_method:- from flaml.searcher import RandomSearch as SearchAlgo+ from flaml.tune.searcher import RandomSearch as SearchAlgoelif "cfocat" == self._hpo_method:- from flaml.searcher.cfo_cat import CFOCat as SearchAlgo+ from flaml.tune.searcher.cfo_cat import CFOCat as SearchAlgoelse:raise NotImplementedError(f"hpo_method={self._hpo_method} is not recognized. "diff --git a/flaml/onlineml/autovw.py b/flaml/onlineml/autovw.pyindex 1ec4e6cbb..da0e520b7 100644--- a/flaml/onlineml/autovw.py+++ b/flaml/onlineml/autovw.py@@ -8,8 +8,8 @@ from flaml.tune import (polynomial_expansion_set,)from flaml.onlineml import OnlineTrialRunner-from flaml.scheduler import ChaChaScheduler-from flaml.searcher import ChampionFrontierSearcher+from flaml.tune.scheduler import ChaChaScheduler+from flaml.tune.searcher import ChampionFrontierSearcherfrom flaml.onlineml.trial import get_ns_feature_dim_from_vw_examplelogger = logging.getLogger(__name__)diff --git a/flaml/onlineml/trial_runner.py b/flaml/onlineml/trial_runner.pyindex 7ef7e119e..3860d0afb 100644--- a/flaml/onlineml/trial_runner.py+++ b/flaml/onlineml/trial_runner.py@@ -1,7 +1,7 @@import numpy as npimport mathfrom flaml.tune import Trial-from flaml.scheduler import TrialScheduler+from flaml.tune.scheduler import TrialSchedulerimport loggingdiff --git a/flaml/scheduler/__init__.py b/flaml/tune/scheduler/__init__.pysimilarity index 100%rename from flaml/scheduler/__init__.pyrename to flaml/tune/scheduler/__init__.pydiff --git a/flaml/scheduler/online_scheduler.py b/flaml/tune/scheduler/online_scheduler.pysimilarity index 99%rename from flaml/scheduler/online_scheduler.pyrename to flaml/tune/scheduler/online_scheduler.pyindex 55f2563fe..bf235afcd 100644--- a/flaml/scheduler/online_scheduler.py+++ b/flaml/tune/scheduler/online_scheduler.py@@ -1,7 +1,7 @@import numpy as npimport loggingfrom typing import Dict-from flaml.scheduler import TrialScheduler+from flaml.tune.scheduler import TrialSchedulerfrom flaml.tune import Triallogger = logging.getLogger(__name__)diff --git a/flaml/scheduler/trial_scheduler.py b/flaml/tune/scheduler/trial_scheduler.pysimilarity index 100%rename from flaml/scheduler/trial_scheduler.pyrename to flaml/tune/scheduler/trial_scheduler.pydiff --git a/flaml/searcher/__init__.py b/flaml/tune/searcher/__init__.pysimilarity index 100%rename from flaml/searcher/__init__.pyrename to flaml/tune/searcher/__init__.pydiff --git a/flaml/searcher/blendsearch.py b/flaml/tune/searcher/blendsearch.pysimilarity index 97%rename from flaml/searcher/blendsearch.pyrename to flaml/tune/searcher/blendsearch.pyindex 269de2612..e22ae6055 100644--- a/flaml/searcher/blendsearch.py+++ b/flaml/tune/searcher/blendsearch.py@@ -20,12 +20,12 @@ try:except (ImportError, AssertionError):from .suggestion import Searcherfrom .suggestion import OptunaSearch as GlobalSearch-from ..tune.trial import unflatten_dict, flatten_dict-from ..tune import INCUMBENT_RESULT+from ..trial import unflatten_dict, flatten_dict+from .. import INCUMBENT_RESULTfrom .search_thread import SearchThreadfrom .flow2 import FLOW2-from ..tune.space import add_cost_to_space, indexof, normalize, define_by_run_func-from ..tune.result import TIME_TOTAL_S+from ..space import add_cost_to_space, indexof, normalize, define_by_run_func+from ..result import TIME_TOTAL_Simport logging@@ -939,7 +939,7 @@ try:qloguniform,)except (ImportError, AssertionError):- from ..tune.sample import (+ from ..sample import (uniform,quniform,choice,diff --git a/flaml/searcher/cfo_cat.py b/flaml/tune/searcher/cfo_cat.pysimilarity index 100%rename from flaml/searcher/cfo_cat.pyrename to flaml/tune/searcher/cfo_cat.pydiff --git a/flaml/searcher/flow2.py b/flaml/tune/searcher/flow2.pysimilarity index 98%rename from flaml/searcher/flow2.pyrename to flaml/tune/searcher/flow2.pyindex d5722db21..226f624ac 100644--- a/flaml/searcher/flow2.py+++ b/flaml/tune/searcher/flow2.py@@ -18,11 +18,10 @@ try:from ray.tune.utils.util import flatten_dict, unflatten_dictexcept (ImportError, AssertionError):from .suggestion import Searcher- from ..tune import sample- from ..tune.trial import flatten_dict, unflatten_dict-from flaml.tune.sample import _BackwardsCompatibleNumpyRng+ from flaml.tune import sample+ from ..trial import flatten_dict, unflatten_dictfrom flaml.config import SAMPLE_MULTIPLY_FACTOR-from ..tune.space import (+from ..space import (complete_config,denormalize,normalize,@@ -85,7 +84,7 @@ class FLOW2(Searcher):self.space = space or {}self._space = flatten_dict(self.space, prevent_delimiter=True)self._random = np.random.RandomState(seed)- self.rs_random = _BackwardsCompatibleNumpyRng(seed + 19823)+ self.rs_random = sample._BackwardsCompatibleNumpyRng(seed + 19823)self.seed = seedself.init_config = init_configself.best_config = flatten_dict(init_config)diff --git a/flaml/searcher/online_searcher.py b/flaml/tune/searcher/online_searcher.pysimilarity index 99%rename from flaml/searcher/online_searcher.pyrename to flaml/tune/searcher/online_searcher.pyindex 81a98c458..d56710f09 100644--- a/flaml/searcher/online_searcher.py+++ b/flaml/tune/searcher/online_searcher.py@@ -2,10 +2,9 @@ import numpy as npimport loggingimport itertoolsfrom typing import Dict, Optional, List-from flaml.tune import Categorical, Float, PolynomialExpansionSet-from flaml.tune import Trial+from flaml.tune import Categorical, Float, PolynomialExpansionSet, Trialfrom flaml.onlineml import VowpalWabbitTrial-from flaml.searcher import CFO+from flaml.tune.searcher import CFOlogger = logging.getLogger(__name__)diff --git a/flaml/searcher/search_thread.py b/flaml/tune/searcher/search_thread.pysimilarity index 99%rename from flaml/searcher/search_thread.pyrename to flaml/tune/searcher/search_thread.pyindex 0d39507bd..d61089e49 100644--- a/flaml/searcher/search_thread.py+++ b/flaml/tune/searcher/search_thread.py@@ -16,7 +16,7 @@ try:except (ImportError, AssertionError):from .suggestion import Searcherfrom .flow2 import FLOW2-from ..tune.space import add_cost_to_space, unflatten_hierarchical+from ..space import add_cost_to_space, unflatten_hierarchicalimport logginglogger = logging.getLogger(__name__)diff --git a/flaml/searcher/suggestion.py b/flaml/tune/searcher/suggestion.pysimilarity index 97%rename from flaml/searcher/suggestion.pyrename to flaml/tune/searcher/suggestion.pyindex 30105dcae..a349c2f14 100644--- a/flaml/searcher/suggestion.py+++ b/flaml/tune/searcher/suggestion.py@@ -23,7 +23,7 @@ import loggingfrom typing import Any, Dict, Optional, Union, List, Tuple, Callableimport picklefrom .variant_generator import parse_spec_vars-from ..tune.sample import (+from ..sample import (Categorical,Domain,Float,@@ -32,7 +32,7 @@ from ..tune.sample import (Quantized,Uniform,)-from ..tune.trial import flatten_dict, unflatten_dict+from ..trial import flatten_dict, unflatten_dictlogger = logging.getLogger(__name__)diff --git a/flaml/searcher/variant_generator.py b/flaml/tune/searcher/variant_generator.pysimilarity index 96%rename from flaml/searcher/variant_generator.pyrename to flaml/tune/searcher/variant_generator.pyindex 388b0b574..fb0c8ed0e 100644--- a/flaml/searcher/variant_generator.py+++ b/flaml/tune/searcher/variant_generator.py@@ -20,7 +20,7 @@ import loggingfrom typing import Any, Dict, Generator, List, Tupleimport numpyimport random-from ..tune.sample import Categorical, Domain, RandomState+from ..sample import Categorical, Domain, RandomStatetry:from ray import __version__ as ray_versiondiff --git a/flaml/tune/space.py b/flaml/tune/space.pyindex 1c0b5c184..a6b5090e7 100644--- a/flaml/tune/space.py+++ b/flaml/tune/space.py@@ -10,7 +10,7 @@ try:from ray.tune.search.variant_generator import generate_variantsexcept (ImportError, AssertionError):from . import sample- from ..searcher.variant_generator import generate_variants+ from .searcher.variant_generator import generate_variantsfrom typing import Dict, Optional, Any, Tuple, Generatorimport numpy as npimport loggingdiff --git a/flaml/tune/tune.py b/flaml/tune/tune.pyindex 9209dccd1..56e8dbaed 100644--- a/flaml/tune/tune.py+++ b/flaml/tune/tune.py@@ -355,7 +355,7 @@ def run(else:logger.setLevel(logging.CRITICAL)- from ..searcher.blendsearch import BlendSearch, CFO+ from .searcher.blendsearch import BlendSearch, CFOif search_alg is None:flaml_scheduler_resource_attr = (@@ -409,7 +409,7 @@ def run(else:from ray.tune.search import ConcurrencyLimiterelse:- from flaml.searcher.suggestion import ConcurrencyLimiter+ from flaml.tune.searcher.suggestion import ConcurrencyLimiterif (search_alg.__class__.__name__in [diff --git a/test/nni/flaml_nni_wrap.py b/test/nni/flaml_nni_wrap.pyindex f81d04164..bc76e05cf 100644--- a/test/nni/flaml_nni_wrap.py+++ b/test/nni/flaml_nni_wrap.py@@ -1,4 +1,4 @@-from flaml.searcher.blendsearch import BlendSearchTuner as BST+from flaml.tune.searcher.blendsearch import BlendSearchTuner as BSTclass BlendSearchTuner(BST):diff --git a/test/tune/example_scheduler.py b/test/tune/example_scheduler.pyindex 5fc5e2854..e3d11320d 100644--- a/test/tune/example_scheduler.py+++ b/test/tune/example_scheduler.py@@ -26,7 +26,7 @@ def easy_objective(use_raytune, config):def test_tune_scheduler(smoke_test=True, use_ray=True, use_raytune=False):import numpy as np- from flaml.searcher.blendsearch import BlendSearch+ from flaml.tune.searcher.blendsearch import BlendSearchnp.random.seed(100)easy_objective_custom_tune = partial(easy_objective, use_raytune)diff --git a/test/tune/test_flaml_raytune_consistency.py b/test/tune/test_flaml_raytune_consistency.pyindex 98b36e5df..736a64d9b 100644--- a/test/tune/test_flaml_raytune_consistency.py+++ b/test/tune/test_flaml_raytune_consistency.py@@ -28,7 +28,7 @@ low_cost_partial_config = {"x": 1}def setup_searcher(searcher_name):- from flaml.searcher.blendsearch import BlendSearch, CFO, RandomSearch+ from flaml.tune.searcher.blendsearch import BlendSearch, CFO, RandomSearchif "cfo" in searcher_name:searcher = CFO(diff --git a/test/tune/test_record_incumbent.py b/test/tune/test_record_incumbent.pyindex b267ee0f9..9cec3c1da 100644--- a/test/tune/test_record_incumbent.py+++ b/test/tune/test_record_incumbent.py@@ -7,7 +7,7 @@ def rosenbrock_function(config: dict):funcLoss = 50for key, value in config.items():if key in ["x1", "x2", "x3", "x4", "x5"]:- funcLoss += value ** 2 - 10 * np.cos(2 * np.pi * value)+ funcLoss += value**2 - 10 * np.cos(2 * np.pi * value)if INCUMBENT_RESULT in config.keys():print("----------------------------------------------")print("incumbent result", config[INCUMBENT_RESULT])@@ -62,7 +62,7 @@ def test_record_incumbent(method="BlendSearch"):use_incumbent_result_in_evaluation=True,)elif method == "CFOCat":- from flaml.searcher.cfo_cat import CFOCat+ from flaml.tune.searcher.cfo_cat import CFOCatalgo = CFOCat(use_incumbent_result_in_evaluation=True,diff --git a/test/tune/test_reproducibility.py b/test/tune/test_reproducibility.pyindex c0229b8cf..974bdfd57 100644--- a/test/tune/test_reproducibility.py+++ b/test/tune/test_reproducibility.py@@ -26,7 +26,7 @@ def _easy_objective(use_raytune, config):def test_tune(externally_setup_searcher=False, use_ray=False, use_raytune=False):from flaml import tune- from flaml.searcher.blendsearch import BlendSearch+ from flaml.tune.searcher.blendsearch import BlendSearcheasy_objective_custom_tune = partial(_easy_objective, use_raytune)search_space = {diff --git a/test/tune/test_restore.py b/test/tune/test_restore.pyindex 7a047e6d4..ef3c95425 100644--- a/test/tune/test_restore.py+++ b/test/tune/test_restore.py@@ -3,7 +3,7 @@ import shutilimport tempfileimport unittestimport numpy as np-from flaml.searcher.suggestion import ConcurrencyLimiter+from flaml.tune.searcher.suggestion import ConcurrencyLimiterfrom flaml import tunefrom flaml import CFOdiff --git a/test/tune/test_scheduler.py b/test/tune/test_scheduler.pyindex 52bf50092..e12f0f6bb 100644--- a/test/tune/test_scheduler.py+++ b/test/tune/test_scheduler.py@@ -1,6 +1,6 @@"""Require: pip install flaml[test,ray]"""-from flaml.scheduler.trial_scheduler import TrialScheduler+from flaml.tune.scheduler.trial_scheduler import TrialSchedulerimport numpy as npfrom flaml import tunediff --git a/test/tune/test_searcher.py b/test/tune/test_searcher.pyindex 7c1e70c98..440c08ab0 100644--- a/test/tune/test_searcher.py+++ b/test/tune/test_searcher.py@@ -32,8 +32,12 @@ def wrong_define_search_space(trial):def test_searcher():- from flaml.searcher.suggestion import OptunaSearch, Searcher, ConcurrencyLimiter- from flaml.searcher.blendsearch import BlendSearch, CFO, RandomSearch+ from flaml.tune.searcher.suggestion import (+ OptunaSearch,+ Searcher,+ ConcurrencyLimiter,+ )+ from flaml.tune.searcher.blendsearch import BlendSearch, CFO, RandomSearchfrom flaml.tune import sample as flamlsamplesearcher = Searcher()@@ -306,6 +310,6 @@ def test_no_optuna():import syssubprocess.check_call([sys.executable, "-m", "pip", "uninstall", "-y", "optuna"])- import flaml.searcher.suggestion+ import flaml.tune.searcher.suggestionsubprocess.check_call([sys.executable, "-m", "pip", "install", "optuna==2.8.0"])diff --git a/test/tune/test_space.py b/test/tune/test_space.pyindex f0c018b63..0081d1ffb 100644--- a/test/tune/test_space.py+++ b/test/tune/test_space.py@@ -69,7 +69,7 @@ def test_define_by_run():def test_grid():- from flaml.searcher.variant_generator import (+ from flaml.tune.searcher.variant_generator import (generate_variants,grid_search,TuneError,diff --git a/test/tune/test_tune.py b/test/tune/test_tune.pyindex 3ba47b9c8..8608461b9 100644--- a/test/tune/test_tune.py+++ b/test/tune/test_tune.py@@ -1,6 +1,6 @@"""Require: pip install flaml[test,ray]"""-from flaml.searcher.blendsearch import BlendSearch+from flaml import BlendSearchimport timeimport osfrom sklearn.model_selection import train_test_split@@ -146,7 +146,7 @@ def _test_xgboost(method="BlendSearch"):},)elif "CFOCat" == method:- from flaml.searcher.cfo_cat import CFOCat+ from flaml.tune.searcher.cfo_cat import CFOCatalgo = CFOCat(low_cost_partial_config={