-
Notifications
You must be signed in to change notification settings - Fork 505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support string alg in tune #1093
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test.
flaml/tune/tune.py
Outdated
search_alg: An instance of BlendSearch as the search algorithm | ||
to be used. The same instance can be used for iterative tuning. | ||
search_alg: An instance/string of the search algorithm | ||
to be used. The same instance/string can be used for iterative tuning. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be used. The same instance/string can be used for iterative tuning. | |
to be used. The same instance can be used for iterative tuning. |
My understanding is that this sentence is about using the same instance for iterative tuning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved
flaml/tune/tune.py
Outdated
@@ -504,15 +503,19 @@ def easy_objective(config): | |||
try: | |||
import optuna as _ | |||
|
|||
SearchAlgorithm = BlendSearch | |||
SearchAlgorithm = BlendSearch if not search_alg else eval(search_alg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of eval
is not safe. Could you use an alternative way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use assert
to make it feasible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, I don't like the use of eval
. Unless you get an approval from an experience Python engineer, I'm against it. Even locals
is better.
Second, the code doesn't look correct in the try...except block. The try part tries to import optuna before using BlendSearch. If the choice is not BlendSearch, we shouldn't enter the try...except block.
flaml/tune/tune.py
Outdated
"BlendSearch", | ||
"CFO", | ||
], "If lexico_objectives is not None, search_alg must be CFO or BlendSearch." | ||
search_alg.lexico_objectives = lexico_objectives |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we implement this in set_search_properties
? Otherwise we need to document this way of setting lexico_objectives
somewhere. Conceptually I think it should be part of set_search_properties
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I agree. I support it in CFO for now. Will make it work in BlendSearch in future PR.
@@ -481,12 +481,11 @@ def easy_objective(config): | |||
else: | |||
logger.setLevel(logging.CRITICAL) | |||
|
|||
from .searcher.blendsearch import BlendSearch, CFO | |||
from .searcher.blendsearch import BlendSearch, CFO, RandomSearch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RandomSearch is not used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we may use it in eval(search_alg)
flaml/tune/tune.py
Outdated
"CFO", | ||
"CFOCat", | ||
"RandomSearch", | ||
], "The string of the search_alg must be feasible." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"feasible" is not clear.
flaml/tune/tune.py
Outdated
@@ -504,15 +503,19 @@ def easy_objective(config): | |||
try: | |||
import optuna as _ | |||
|
|||
SearchAlgorithm = BlendSearch | |||
SearchAlgorithm = BlendSearch if not search_alg else eval(search_alg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, I don't like the use of eval
. Unless you get an approval from an experience Python engineer, I'm against it. Even locals
is better.
Second, the code doesn't look correct in the try...except block. The try part tries to import optuna before using BlendSearch. If the choice is not BlendSearch, we shouldn't enter the try...except block.
flaml/tune/searcher/flow2.py
Outdated
@@ -317,6 +317,7 @@ def set_search_properties( | |||
metric: Optional[str] = None, | |||
mode: Optional[str] = None, | |||
config: Optional[Dict] = None, | |||
lexico_objectives: Optional[Dict] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this argument added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
test/tune/test_tune.py
Outdated
# Iterative training function - can be any arbitrary training procedure | ||
_evaluation_fn(step, width, height) | ||
# Feed the score back back to Tune. | ||
print("Trial stopped", step) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
) | ||
metric = lexico_objectives["metrics"][0] or DEFAULT_METRIC | ||
else: | ||
if not search_alg or search_alg == "BlendSearch": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when search_alg=="BlendSearch"
, we shouldn't automatically switch to CFO. We should raise an error if the import fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. resolved.
assert search_alg.__class__.__name__ in [ | ||
"CFO", | ||
], "If lexico_objectives is not None, the search_alg must be CFO for now." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such assertions and logging happen in different places: here, 519, 487. Could you add TODO notes to modify them later in case they are forgotten?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved
# lexico tune | ||
tune.run( | ||
_BraninCurrin, search_alg="CFO", num_samples=10, config=mo_search_space, lexico_objectives=lexico_objectives | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add another test with lexico_objectives andsearch_alg= "BlendSearch"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
flaml/tune/tune.py
Outdated
logger.warning("If lexico_objectives is not None, search_alg is forced to be CFO") | ||
search_alg = None | ||
if search_alg is None: | ||
logger.warning("If lexico_objectives is not None, search_alg is forced to be CFO for now.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not put this warning in the place where SearchAlgorithm is forced to be CFO? i.e., immediately after line 518.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
Why are these changes needed?
Support specifying search algorithm by passing the corresponding string in tune.
Related issue number
N/A
Checks