From 2828f4c8fa64fe355cbdb99591f34cc5b0b4fab9 Mon Sep 17 00:00:00 2001 From: Ravi Dalal Date: Mon, 4 Nov 2024 10:52:37 -0800 Subject: [PATCH 01/19] updated optuna_search to allow users to configure optuna storage Signed-off-by: Ravi Dalal --- .../ray/tune/search/optuna/optuna_search.py | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/python/ray/tune/search/optuna/optuna_search.py b/python/ray/tune/search/optuna/optuna_search.py index f1656039a4af4..b1515bce79620 100644 --- a/python/ray/tune/search/optuna/optuna_search.py +++ b/python/ray/tune/search/optuna/optuna_search.py @@ -31,12 +31,14 @@ import optuna as ot from optuna.distributions import BaseDistribution as OptunaDistribution from optuna.samplers import BaseSampler + from optuna.storages import BaseStorage from optuna.trial import Trial as OptunaTrial from optuna.trial import TrialState as OptunaTrialState except ImportError: ot = None OptunaDistribution = None BaseSampler = None + BaseStorage = None OptunaTrialState = None OptunaTrial = None @@ -133,7 +135,9 @@ class OptunaSearch(Searcher): a delay when suggesting new configurations. This is an Optuna issue and may be fixed in a future Optuna release. - + storage: Optuna storage used for storing trial results to s + torages other than in-momemory storage, + for instance optuna.storages.RDBStorage. seed: Seed to initialize sampler with. This parameter is only used when ``sampler=None``. In all other cases, the sampler you pass should be initialized with the seed already. @@ -305,7 +309,7 @@ def define_search_space(trial: optuna.Trial): ) tuner.fit() - .. versionadded:: 0.8.8 + .. versionadded:: 0.8.9 """ @@ -322,6 +326,8 @@ def __init__( mode: Optional[Union[str, List[str]]] = None, points_to_evaluate: Optional[List[Dict]] = None, sampler: Optional["BaseSampler"] = None, + study_name: Optional[str] = None, + storage: Optional["BaseStorage"] = None, seed: Optional[int] = None, evaluated_rewards: Optional[List] = None, ): @@ -343,8 +349,10 @@ def __init__( self._points_to_evaluate = points_to_evaluate or [] self._evaluated_rewards = evaluated_rewards - - self._study_name = "optuna" # Fixed study name for in-memory storage + if study_name: + self._study_name = study_name + else: + self._study_name = "optuna" # Fixed study name for in-memory storage if sampler and seed: logger.warning( @@ -362,6 +370,17 @@ def __init__( self._sampler = sampler self._seed = seed + if storage: + assert ( + study_name + ), "You must pass a study name if you are passing a storage." + assert isinstance(storage, BaseStorage), ( + "You can only pass an instance of " + "`optuna.samplers.BaseStorage` " + "as a storage to `OptunaSearcher`." + ) + self._storage = storage + self._completed_trials = set() self._ot_trials = {} @@ -380,7 +399,10 @@ def _setup_study(self, mode: Union[str, list]): self._metric = DEFAULT_METRIC pruner = ot.pruners.NopPruner() - storage = ot.storages.InMemoryStorage() + if self._storage: + storage = self._storage + else: + storage = ot.storages.InMemoryStorage() if self._sampler: sampler = self._sampler From 0dbeee5807e574140fb0acbb66bcb28eb96d93ce Mon Sep 17 00:00:00 2001 From: Ravi Dalal Date: Mon, 4 Nov 2024 15:39:15 -0800 Subject: [PATCH 02/19] fixed linting error Signed-off-by: Ravi Dalal --- python/ray/tune/search/optuna/optuna_search.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/ray/tune/search/optuna/optuna_search.py b/python/ray/tune/search/optuna/optuna_search.py index b1515bce79620..9bf305c845f96 100644 --- a/python/ray/tune/search/optuna/optuna_search.py +++ b/python/ray/tune/search/optuna/optuna_search.py @@ -135,8 +135,8 @@ class OptunaSearch(Searcher): a delay when suggesting new configurations. This is an Optuna issue and may be fixed in a future Optuna release. - storage: Optuna storage used for storing trial results to s - torages other than in-momemory storage, + storage: Optuna storage used for storing trial results to + storages other than in-momemory storage, for instance optuna.storages.RDBStorage. seed: Seed to initialize sampler with. This parameter is only used when ``sampler=None``. In all other cases, the sampler From ea8d81de5f52743dac644c1aabc7cf5671737083 Mon Sep 17 00:00:00 2001 From: Ravi Dalal Date: Mon, 4 Nov 2024 16:58:47 -0800 Subject: [PATCH 03/19] initialized _storage attribute Signed-off-by: Ravi Dalal --- python/ray/tune/search/optuna/optuna_search.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/ray/tune/search/optuna/optuna_search.py b/python/ray/tune/search/optuna/optuna_search.py index 9bf305c845f96..ba90b850e67e9 100644 --- a/python/ray/tune/search/optuna/optuna_search.py +++ b/python/ray/tune/search/optuna/optuna_search.py @@ -380,6 +380,8 @@ def __init__( "as a storage to `OptunaSearcher`." ) self._storage = storage + else: + self._storage = None self._completed_trials = set() From 770db2fbba032d469571080070cd02f1dc8a6108 Mon Sep 17 00:00:00 2001 From: Ravi Dalal Date: Tue, 5 Nov 2024 10:01:17 -0800 Subject: [PATCH 04/19] optimized code Signed-off-by: Ravi Dalal --- python/ray/tune/search/optuna/optuna_search.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/python/ray/tune/search/optuna/optuna_search.py b/python/ray/tune/search/optuna/optuna_search.py index ba90b850e67e9..4d7f2dc252250 100644 --- a/python/ray/tune/search/optuna/optuna_search.py +++ b/python/ray/tune/search/optuna/optuna_search.py @@ -379,10 +379,8 @@ def __init__( "`optuna.samplers.BaseStorage` " "as a storage to `OptunaSearcher`." ) - self._storage = storage - else: - self._storage = None + self._storage = storage self._completed_trials = set() self._ot_trials = {} From 1e27f121e66c1fd0df5686c96aacc9f5726d6325 Mon Sep 17 00:00:00 2001 From: Ravi Dalal Date: Wed, 6 Nov 2024 13:14:09 -0800 Subject: [PATCH 05/19] addressed PR comments Signed-off-by: Ravi Dalal --- python/ray/tune/search/optuna/optuna_search.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/python/ray/tune/search/optuna/optuna_search.py b/python/ray/tune/search/optuna/optuna_search.py index 4d7f2dc252250..5eea0ae9fd620 100644 --- a/python/ray/tune/search/optuna/optuna_search.py +++ b/python/ray/tune/search/optuna/optuna_search.py @@ -371,16 +371,15 @@ def __init__( self._seed = seed if storage: - assert ( - study_name - ), "You must pass a study name if you are passing a storage." assert isinstance(storage, BaseStorage), ( "You can only pass an instance of " "`optuna.samplers.BaseStorage` " "as a storage to `OptunaSearcher`." ) + self._storage = storage + else: + self._storage = ot.storages.InMemoryStorage() - self._storage = storage self._completed_trials = set() self._ot_trials = {} @@ -399,10 +398,6 @@ def _setup_study(self, mode: Union[str, list]): self._metric = DEFAULT_METRIC pruner = ot.pruners.NopPruner() - if self._storage: - storage = self._storage - else: - storage = ot.storages.InMemoryStorage() if self._sampler: sampler = self._sampler @@ -424,7 +419,7 @@ def _setup_study(self, mode: Union[str, list]): ) self._ot_study = ot.study.create_study( - storage=storage, + storage=self._storage, sampler=sampler, pruner=pruner, study_name=self._study_name, From ccefd5cf298e22d1ef313f5de81e0293f451031d Mon Sep 17 00:00:00 2001 From: Ravi Dalal Date: Thu, 7 Nov 2024 08:52:23 -0800 Subject: [PATCH 06/19] added comment for study_name Signed-off-by: Ravi Dalal --- python/ray/tune/search/optuna/optuna_search.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/ray/tune/search/optuna/optuna_search.py b/python/ray/tune/search/optuna/optuna_search.py index 5eea0ae9fd620..4ba8914cdd49b 100644 --- a/python/ray/tune/search/optuna/optuna_search.py +++ b/python/ray/tune/search/optuna/optuna_search.py @@ -135,6 +135,8 @@ class OptunaSearch(Searcher): a delay when suggesting new configurations. This is an Optuna issue and may be fixed in a future Optuna release. + study_name: Optuna study name that uniquely identifies the trial + results. Defaults to ``optuna``. storage: Optuna storage used for storing trial results to storages other than in-momemory storage, for instance optuna.storages.RDBStorage. From 4ab211bc9891b5be0ee237526ffca4c77787d895 Mon Sep 17 00:00:00 2001 From: Ravi Dalal Date: Mon, 25 Nov 2024 10:51:44 -0800 Subject: [PATCH 07/19] reverted versionadded Signed-off-by: Ravi Dalal --- python/ray/tune/search/optuna/optuna_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ray/tune/search/optuna/optuna_search.py b/python/ray/tune/search/optuna/optuna_search.py index 4ba8914cdd49b..1a5a61e04e53f 100644 --- a/python/ray/tune/search/optuna/optuna_search.py +++ b/python/ray/tune/search/optuna/optuna_search.py @@ -311,7 +311,7 @@ def define_search_space(trial: optuna.Trial): ) tuner.fit() - .. versionadded:: 0.8.9 + .. versionadded:: 0.8.8 """ From 01a29b09ab41daa464bdb737e1783e03b72cdb65 Mon Sep 17 00:00:00 2001 From: Ravi Dalal <12639199+ravi-dalal@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:16:49 -0800 Subject: [PATCH 08/19] Update python/ray/tune/search/optuna/optuna_search.py Co-authored-by: Hongpeng Guo Signed-off-by: Ravi Dalal <12639199+ravi-dalal@users.noreply.github.com> --- python/ray/tune/search/optuna/optuna_search.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python/ray/tune/search/optuna/optuna_search.py b/python/ray/tune/search/optuna/optuna_search.py index 1a5a61e04e53f..faae30f5a150c 100644 --- a/python/ray/tune/search/optuna/optuna_search.py +++ b/python/ray/tune/search/optuna/optuna_search.py @@ -374,9 +374,8 @@ def __init__( if storage: assert isinstance(storage, BaseStorage), ( - "You can only pass an instance of " - "`optuna.samplers.BaseStorage` " - "as a storage to `OptunaSearcher`." + "The `storage` parameter in `OptunaSearcher` must be an instance " + "of `optuna.samplers.BaseStorage`." ) self._storage = storage else: From 09cb437241b03b1964881c6880478468605c47c7 Mon Sep 17 00:00:00 2001 From: Ravi Dalal <12639199+ravi-dalal@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:17:36 -0800 Subject: [PATCH 09/19] Update python/ray/tune/search/optuna/optuna_search.py Co-authored-by: matthewdeng Signed-off-by: Ravi Dalal <12639199+ravi-dalal@users.noreply.github.com> --- python/ray/tune/search/optuna/optuna_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ray/tune/search/optuna/optuna_search.py b/python/ray/tune/search/optuna/optuna_search.py index faae30f5a150c..9f4b7e535d633 100644 --- a/python/ray/tune/search/optuna/optuna_search.py +++ b/python/ray/tune/search/optuna/optuna_search.py @@ -136,7 +136,7 @@ class OptunaSearch(Searcher): This is an Optuna issue and may be fixed in a future Optuna release. study_name: Optuna study name that uniquely identifies the trial - results. Defaults to ``optuna``. + results. Defaults to ``"optuna"``. storage: Optuna storage used for storing trial results to storages other than in-momemory storage, for instance optuna.storages.RDBStorage. From e4a8546edf437ddb8ebd5dd6570b0c840454bea5 Mon Sep 17 00:00:00 2001 From: Ravi Dalal <12639199+ravi-dalal@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:17:56 -0800 Subject: [PATCH 10/19] Update python/ray/tune/search/optuna/optuna_search.py Co-authored-by: matthewdeng Signed-off-by: Ravi Dalal <12639199+ravi-dalal@users.noreply.github.com> --- python/ray/tune/search/optuna/optuna_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ray/tune/search/optuna/optuna_search.py b/python/ray/tune/search/optuna/optuna_search.py index 9f4b7e535d633..3cc1972483ca8 100644 --- a/python/ray/tune/search/optuna/optuna_search.py +++ b/python/ray/tune/search/optuna/optuna_search.py @@ -138,7 +138,7 @@ class OptunaSearch(Searcher): study_name: Optuna study name that uniquely identifies the trial results. Defaults to ``"optuna"``. storage: Optuna storage used for storing trial results to - storages other than in-momemory storage, + storages other than in-memory storage, for instance optuna.storages.RDBStorage. seed: Seed to initialize sampler with. This parameter is only used when ``sampler=None``. In all other cases, the sampler From a2f706d68da10aca4072b553c4cf60629c8023e1 Mon Sep 17 00:00:00 2001 From: Ravi Dalal Date: Mon, 25 Nov 2024 18:21:52 -0800 Subject: [PATCH 11/19] added storage to testOptuna unit tests Signed-off-by: Ravi Dalal --- python/ray/tune/tests/test_searchers.py | 37 +++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/python/ray/tune/tests/test_searchers.py b/python/ray/tune/tests/test_searchers.py index c7b88f87109b8..4d20ec61d8207 100644 --- a/python/ray/tune/tests/test_searchers.py +++ b/python/ray/tune/tests/test_searchers.py @@ -232,15 +232,24 @@ def testNevergradWithRequiredOptimizerKwargs(self): def testOptuna(self): from optuna.samplers import RandomSampler + from optuna.storages import JournalStorage + from optuna.storages.journal import JournalFileBackend from ray.tune.search.optuna import OptunaSearch np.random.seed(1000) # At least one nan, inf, -inf and float + storage_file_path = "/tmp/my_test_study.log" with self.check_searcher_checkpoint_errors_scope(): out = tune.run( _invalid_objective, - search_alg=OptunaSearch(sampler=RandomSampler(seed=1234)), + search_alg=OptunaSearch( + sampler=RandomSampler(seed=1234), + study_name="my_test_study", + storage=JournalStorage( + JournalFileBackend(file_path=storage_file_path) + ), + ), config=self.config, metric="_metric", mode="max", @@ -248,6 +257,7 @@ def testOptuna(self): reuse_actors=False, ) self.assertCorrectExperimentOutput(out) + self.assertTrue(os.path.exists(storage_file_path)) def testOptunaReportTooOften(self): from optuna.samplers import RandomSampler @@ -358,12 +368,18 @@ def run_add_evaluated_trials(self, searcher, get_len_X, get_len_y): searcher_copy.suggest("1") def testOptuna(self): + from optuna.storages import JournalStorage + from optuna.storages.journal import JournalFileBackend from optuna.trial import TrialState from ray.tune.search.optuna import OptunaSearch + storage_file_path = "/tmp/my_test_study.log" + searcher = OptunaSearch( space=self.space, + study_name="my_test_study", + storage=JournalStorage(JournalFileBackend(file_path=storage_file_path)), metric="metric", mode="max", points_to_evaluate=[{self.param_name: self.valid_value}], @@ -373,6 +389,7 @@ def testOptuna(self): get_len = lambda s: len(s._ot_study.trials) # noqa E731 self.assertGreater(get_len(searcher), 0) + self.assertTrue(os.path.exists(storage_file_path)) searcher = OptunaSearch( space=self.space, @@ -608,9 +625,19 @@ def testNevergrad(self): self._restore(searcher) def testOptuna(self): + from optuna.storages import JournalStorage + from optuna.storages.journal import JournalFileBackend + from ray.tune.search.optuna import OptunaSearch - searcher = OptunaSearch(space=self.config, metric=self.metric_name, mode="max") + storage_file_path = "/tmp/my_test_study.log" + searcher = OptunaSearch( + space=self.config, + study_name="my_test_study", + storage=JournalStorage(JournalFileBackend(file_path=storage_file_path)), + metric=self.metric_name, + mode="max", + ) self._save(searcher) searcher = OptunaSearch() @@ -662,15 +689,20 @@ def tearDownClass(cls): def testOptuna(self): from optuna.samplers import RandomSampler + from optuna.storages import JournalStorage + from optuna.storages.journal import JournalFileBackend from ray.tune.search.optuna import OptunaSearch np.random.seed(1000) + storage_file_path = "/tmp/my_test_study.log" out = tune.run( _multi_objective, search_alg=OptunaSearch( sampler=RandomSampler(seed=1234), + study_name="my_test_study", + storage=JournalStorage(JournalFileBackend(file_path=storage_file_path)), metric=["a", "b", "c"], mode=["max", "min", "max"], ), @@ -685,6 +717,7 @@ def testOptuna(self): self.assertGreaterEqual(best_trial_b.config["b"], 0.8) best_trial_c = out.get_best_trial("c", "max") self.assertGreaterEqual(best_trial_c.config["c"], 0.8) + self.assertTrue(os.path.exists(storage_file_path)) if __name__ == "__main__": From 12364f8249de09c256c4a221deba487c7f444573 Mon Sep 17 00:00:00 2001 From: Ravi Dalal Date: Tue, 26 Nov 2024 12:35:25 -0800 Subject: [PATCH 12/19] added optunasearch with storage unit tests Signed-off-by: Ravi Dalal --- python/ray/tune/tests/test_searchers.py | 79 ++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/python/ray/tune/tests/test_searchers.py b/python/ray/tune/tests/test_searchers.py index 4d20ec61d8207..5346966c81d42 100644 --- a/python/ray/tune/tests/test_searchers.py +++ b/python/ray/tune/tests/test_searchers.py @@ -232,6 +232,25 @@ def testNevergradWithRequiredOptimizerKwargs(self): def testOptuna(self): from optuna.samplers import RandomSampler + + from ray.tune.search.optuna import OptunaSearch + + np.random.seed(1000) # At least one nan, inf, -inf and float + + with self.check_searcher_checkpoint_errors_scope(): + out = tune.run( + _invalid_objective, + search_alg=OptunaSearch(sampler=RandomSampler(seed=1234), storage=None), + config=self.config, + metric="_metric", + mode="max", + num_samples=8, + reuse_actors=False, + ) + self.assertCorrectExperimentOutput(out) + + def testOptunaWithStorage(self): + from optuna.samplers import RandomSampler from optuna.storages import JournalStorage from optuna.storages.journal import JournalFileBackend @@ -374,8 +393,22 @@ def testOptuna(self): from ray.tune.search.optuna import OptunaSearch - storage_file_path = "/tmp/my_test_study.log" + # OptunaSearch with in-memory storage + searcher = OptunaSearch( + space=self.space, + storage=None, + metric="metric", + mode="max", + points_to_evaluate=[{self.param_name: self.valid_value}], + evaluated_rewards=[1.0], + ) + + get_len = lambda s: len(s._ot_study.trials) # noqa E731 + self.assertGreater(get_len(searcher), 0) + + # OptunaSearch with external storage + storage_file_path = "/tmp/my_test_study.log" searcher = OptunaSearch( space=self.space, study_name="my_test_study", @@ -625,6 +658,22 @@ def testNevergrad(self): self._restore(searcher) def testOptuna(self): + from ray.tune.search.optuna import OptunaSearch + + searcher = OptunaSearch( + space=self.config, + storage=None, + metric=self.metric_name, + mode="max", + ) + self._save(searcher) + + searcher = OptunaSearch() + self._restore(searcher) + + assert "not_completed" in searcher._ot_trials + + def testOptunaWithStorage(self): from optuna.storages import JournalStorage from optuna.storages.journal import JournalFileBackend @@ -644,6 +693,7 @@ def testOptuna(self): self._restore(searcher) assert "not_completed" in searcher._ot_trials + self.assertTrue(os.path.exists(storage_file_path)) def testZOOpt(self): from ray.tune.search.zoopt import ZOOptSearch @@ -689,6 +739,33 @@ def tearDownClass(cls): def testOptuna(self): from optuna.samplers import RandomSampler + + from ray.tune.search.optuna import OptunaSearch + + np.random.seed(1000) + + out = tune.run( + _multi_objective, + search_alg=OptunaSearch( + sampler=RandomSampler(seed=1234), + storage=None, + metric=["a", "b", "c"], + mode=["max", "min", "max"], + ), + config=self.config, + num_samples=16, + reuse_actors=False, + ) + + best_trial_a = out.get_best_trial("a", "max") + self.assertGreaterEqual(best_trial_a.config["a"], 0.8) + best_trial_b = out.get_best_trial("b", "min") + self.assertGreaterEqual(best_trial_b.config["b"], 0.8) + best_trial_c = out.get_best_trial("c", "max") + self.assertGreaterEqual(best_trial_c.config["c"], 0.8) + + def testOptunaWithStorage(self): + from optuna.samplers import RandomSampler from optuna.storages import JournalStorage from optuna.storages.journal import JournalFileBackend From f1661901d66c634e791b1012dfe32ee5952b6e11 Mon Sep 17 00:00:00 2001 From: Ravi Dalal Date: Wed, 27 Nov 2024 17:28:10 -0800 Subject: [PATCH 13/19] updated optuna version Signed-off-by: Ravi Dalal --- python/requirements/ml/tune-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/requirements/ml/tune-requirements.txt b/python/requirements/ml/tune-requirements.txt index 03ebfbd876b66..cefcb903f9625 100644 --- a/python/requirements/ml/tune-requirements.txt +++ b/python/requirements/ml/tune-requirements.txt @@ -10,4 +10,4 @@ hpbandster==0.7.4; python_version < "3.12" hyperopt @ git+https://github.com/hyperopt/hyperopt.git@2504ee61419737e814e2dec2961b15d12775529c future nevergrad==0.4.3.post7 -optuna==3.2.0 +optuna==4.1.0 From 080bb58b3f53711752f4462c06be398abfc32156 Mon Sep 17 00:00:00 2001 From: Ravi Dalal Date: Thu, 5 Dec 2024 16:56:13 +0530 Subject: [PATCH 14/19] updated python/requirements_compiled.txt file Signed-off-by: Ravi Dalal --- python/requirements_compiled.txt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/python/requirements_compiled.txt b/python/requirements_compiled.txt index 8a3293e17268c..8a2fea83673e9 100644 --- a/python/requirements_compiled.txt +++ b/python/requirements_compiled.txt @@ -295,8 +295,6 @@ cloudpickle==2.2.0 # tensorflow-probability cma==3.2.2 # via nevergrad -cmaes==0.10.0 - # via optuna cmdstanpy==1.2.0 # via prophet colorama==0.4.6 @@ -1166,7 +1164,6 @@ numpy==1.26.4 # bayesian-optimization # bokeh # cma - # cmaes # cmdstanpy # configspace # contourpy @@ -1309,7 +1306,7 @@ opt-einsum==3.3.0 # via # pyro-ppl # tensorflow -optuna==3.2.0 +optuna==4.1.0 # via -r /ray/ci/../python/requirements/ml/tune-requirements.txt orjson==3.9.10 # via gradio @@ -1519,7 +1516,7 @@ py-cpuinfo==9.0.0 # via deepspeed py-partiql-parser==0.5.0 # via moto -py-spy==0.4.0 ; python_version < "3.12" +py-spy==0.3.14 # via -r /ray/ci/../python/requirements.txt py4j==0.10.9.7 # via pyspark @@ -2473,4 +2470,4 @@ zoopt==0.4.1 # The following packages are considered to be unsafe in a requirements file: # pip -# setuptools +# setuptools \ No newline at end of file From a30b1e5e51130145d83b1a70985898b8d08a25c7 Mon Sep 17 00:00:00 2001 From: Hongpeng Guo Date: Thu, 5 Dec 2024 16:00:56 -0800 Subject: [PATCH 15/19] fix optuna upgrade issue Signed-off-by: Hongpeng Guo --- python/ray/tune/search/optuna/optuna_search.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/python/ray/tune/search/optuna/optuna_search.py b/python/ray/tune/search/optuna/optuna_search.py index 3cc1972483ca8..b6fa869922cdf 100644 --- a/python/ray/tune/search/optuna/optuna_search.py +++ b/python/ray/tune/search/optuna/optuna_search.py @@ -613,6 +613,15 @@ def add_evaluated_point( else: intermediate_values_dict = None + # If the trial state is FAILED, the value must be `None` in Optuna==4.1.0 + # Reference: https://github.com/optuna/optuna/pull/5211 + # This is a temporary fix for the issue that Optuna enforces the value + # to be `None` if the trial state is FAILED. + # TODO (hpguo): A better solution may requires us to update the base class + # to allow the `value` arg in `add_evaluated_point` being `Optional[float]`. + if ot_trial_state == OptunaTrialState.FAIL: + value = None + trial = ot.trial.create_trial( state=ot_trial_state, value=value, From 9a0204233f913a7e08cf327e3938cfb806ca37f1 Mon Sep 17 00:00:00 2001 From: Hongpeng Guo Date: Fri, 6 Dec 2024 13:33:19 -0800 Subject: [PATCH 16/19] fix py-spy version Signed-off-by: Hongpeng Guo --- python/requirements_compiled.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/requirements_compiled.txt b/python/requirements_compiled.txt index 8a2fea83673e9..72888c7c97c38 100644 --- a/python/requirements_compiled.txt +++ b/python/requirements_compiled.txt @@ -1516,7 +1516,7 @@ py-cpuinfo==9.0.0 # via deepspeed py-partiql-parser==0.5.0 # via moto -py-spy==0.3.14 +py-spy==0.4.0 ; python_version < "3.12" # via -r /ray/ci/../python/requirements.txt py4j==0.10.9.7 # via pyspark @@ -2470,4 +2470,4 @@ zoopt==0.4.1 # The following packages are considered to be unsafe in a requirements file: # pip -# setuptools \ No newline at end of file +# setuptools From 2c407c7be24c3dc5c1d4dd96a9933b8a8537efac Mon Sep 17 00:00:00 2001 From: Hongpeng Guo Date: Mon, 9 Dec 2024 15:38:48 -0800 Subject: [PATCH 17/19] update storage default behavior Signed-off-by: Hongpeng Guo --- python/ray/tune/search/optuna/optuna_search.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/python/ray/tune/search/optuna/optuna_search.py b/python/ray/tune/search/optuna/optuna_search.py index b6fa869922cdf..7c89f2df28ea7 100644 --- a/python/ray/tune/search/optuna/optuna_search.py +++ b/python/ray/tune/search/optuna/optuna_search.py @@ -377,9 +377,11 @@ def __init__( "The `storage` parameter in `OptunaSearcher` must be an instance " "of `optuna.samplers.BaseStorage`." ) - self._storage = storage - else: - self._storage = ot.storages.InMemoryStorage() + # If storage is not provided, just set self._storage to None + # so that the default in-memory storage is used. We don't explicitly + # set self._storage to InMemoryStorage because it is a new API in Optuna + # and we want to keep the backward compatibility. + self._storage = storage self._completed_trials = set() From 5f330b530dc376ab093fc6762866e7955a4e7362 Mon Sep 17 00:00:00 2001 From: Hongpeng Guo Date: Mon, 9 Dec 2024 17:08:00 -0800 Subject: [PATCH 18/19] Update python/ray/tune/search/optuna/optuna_search.py Co-authored-by: Justin Yu Signed-off-by: Hongpeng Guo --- python/ray/tune/search/optuna/optuna_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ray/tune/search/optuna/optuna_search.py b/python/ray/tune/search/optuna/optuna_search.py index 7c89f2df28ea7..8170d233408be 100644 --- a/python/ray/tune/search/optuna/optuna_search.py +++ b/python/ray/tune/search/optuna/optuna_search.py @@ -375,7 +375,7 @@ def __init__( if storage: assert isinstance(storage, BaseStorage), ( "The `storage` parameter in `OptunaSearcher` must be an instance " - "of `optuna.samplers.BaseStorage`." + "of `optuna.storages.BaseStorage`." ) # If storage is not provided, just set self._storage to None # so that the default in-memory storage is used. We don't explicitly From 2df22ac130ec82311c7157fb1812b5d1dc621f4d Mon Sep 17 00:00:00 2001 From: Hongpeng Guo Date: Mon, 9 Dec 2024 17:08:07 -0800 Subject: [PATCH 19/19] Update python/ray/tune/search/optuna/optuna_search.py Co-authored-by: Justin Yu Signed-off-by: Hongpeng Guo --- python/ray/tune/search/optuna/optuna_search.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/python/ray/tune/search/optuna/optuna_search.py b/python/ray/tune/search/optuna/optuna_search.py index 8170d233408be..6c440b380c663 100644 --- a/python/ray/tune/search/optuna/optuna_search.py +++ b/python/ray/tune/search/optuna/optuna_search.py @@ -378,9 +378,7 @@ def __init__( "of `optuna.storages.BaseStorage`." ) # If storage is not provided, just set self._storage to None - # so that the default in-memory storage is used. We don't explicitly - # set self._storage to InMemoryStorage because it is a new API in Optuna - # and we want to keep the backward compatibility. + # so that the default in-memory storage is used. self._storage = storage self._completed_trials = set()