Skip to content

Commit 1570ff7

Browse files
committed
[tune] Require optuna>=3.0.0 in OptunaSearch
OptunaSearch already requires the Optuna 3.0+ distributions API: it unconditionally builds optuna.distributions.FloatDistribution during search-space conversion. On older Optuna it fails with a confusing AttributeError instead of a clear message. This codifies the already-required minimum: - Raise a clear ImportError when optuna<3.0.0, mirroring the existing XGBoostTrainer version guard. - Remove the unreachable MOTPESampler (<2.9.0) branch; default to TPESampler, which handles single- and multi-objective optimization. - Update the docstring: drop the stale MOTPESampler/2.10.0 text and note that OptunaSearch requires optuna>=3.0. The Tune Optuna example already assumes and installs optuna>=3.0.0. Part of #60512. Signed-off-by: Adel Nour <ans9868@nyu.edu>
1 parent 51971fa commit 1570ff7

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

python/ray/tune/search/optuna/optuna_search.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class OptunaSearch(Searcher):
9797
9898
Multi-objective optimization is supported.
9999
100+
.. note::
101+
``OptunaSearch`` requires ``optuna>=3.0``.
102+
100103
Args:
101104
space: Hyperparameter search space definition for
102105
Optuna's sampler. This can be either a :class:`dict` with
@@ -127,20 +130,10 @@ class OptunaSearch(Searcher):
127130
for future parameters. Needs to be a list of dicts containing the
128131
configurations.
129132
sampler: Optuna sampler used to
130-
draw hyperparameter configurations. Defaults to ``MOTPESampler``
131-
for multi-objective optimization with Optuna<2.9.0, and
132-
``TPESampler`` in every other case.
133+
draw hyperparameter configurations. Defaults to ``TPESampler``,
134+
which supports both single- and multi-objective optimization.
133135
See https://optuna.readthedocs.io/en/stable/reference/samplers/index.html
134136
for available Optuna samplers.
135-
136-
.. warning::
137-
Please note that with Optuna 2.10.0 and earlier
138-
default ``MOTPESampler``/``TPESampler`` suffer
139-
from performance issues when dealing with a large number of
140-
completed trials (approx. >100). This will manifest as
141-
a delay when suggesting new configurations.
142-
This is an Optuna issue and may be fixed in a future
143-
Optuna release.
144137
study_name: Optuna study name that uniquely identifies the trial
145138
results. Defaults to ``"optuna"``.
146139
storage: Optuna storage used for storing trial results to
@@ -340,6 +333,11 @@ def __init__(
340333
evaluated_rewards: Optional[List] = None,
341334
):
342335
assert ot is not None, "Optuna must be installed! Run `pip install optuna`."
336+
if version.parse(ot.__version__) < version.parse("3.0.0"):
337+
raise ImportError(
338+
"`OptunaSearch` requires the `optuna` version to be >= 3.0.0. "
339+
'Upgrade with: `pip install -U "optuna>=3.0"`'
340+
)
343341
super(OptunaSearch, self).__init__(metric=metric, mode=mode)
344342

345343
if isinstance(space, dict) and space:
@@ -408,12 +406,8 @@ def _setup_study(self, mode: Union[str, list]):
408406

409407
if self._sampler:
410408
sampler = self._sampler
411-
elif isinstance(mode, list) and version.parse(ot.__version__) < version.parse(
412-
"2.9.0"
413-
):
414-
# MOTPESampler deprecated in Optuna>=2.9.0
415-
sampler = ot.samplers.MOTPESampler(seed=self._seed)
416409
else:
410+
# TPESampler handles both single- and multi-objective optimization.
417411
sampler = ot.samplers.TPESampler(seed=self._seed)
418412

419413
if isinstance(mode, list):

0 commit comments

Comments
 (0)