-
Notifications
You must be signed in to change notification settings - Fork 33
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
Make HEBO sampler supports Define-by-Run manner, maximization, parallelization, and constant_liar #196
Conversation
#195 |
Current example (L50-L58). search_space = {
"x": FloatDistribution(-10, 10),
"y": IntDistribution(0, 10),
}
sampler = HEBOSampler(search_space)
study = optuna.create_study(sampler=sampler) Suggestion. import optuna
import optunahub
def objective(trial: optuna.trial.Trial) -> float:
x = trial.suggest_float("x", -10, 10)
y = trial.suggest_int("y", -10, 10)
return x**2 + y**2
module = optunahub.load_module("samplers/hebo")
sampler = module.HEBOSampler(search_space={
"x": optuna.distributions.FloatDistribution(-10, 10),
"y": optuna.distributions.IntDistribution(-10, 10),
})
study = optuna.create_study(sampler=sampler)
study.optimize(objective, n_trials=100)
print(study.best_trial.params, study.best_trial.value) |
I've updated my comment (#196 (comment)). |
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.
LGTM
@nabenabe0928 If you have no further concerns, please merge this PR.
Note: I added "stateless" mode for parallelization; in the mode, it creates entire HEBO model in every trial and thus requires more computational cost. I preserved previous "define-and-run" mode for compartibility. It is not stateless but faster. |
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.
Thank you for the PR, I left some comments:)
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
@nabenabe0928 Thank you for comments! I revised the code. PTAL. |
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 left some comments, but you do not have to address all!
In the worst case, we can once merge this PR and can make another PR!
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
Co-authored-by: Shuhei Watanabe <[email protected]>
Thank you for additional comments! |
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.
LGTM, but I will check if the performance is fine just in case!
params = pd.DataFrame([t.params for t in trials]) | ||
values[np.isnan(values)] = worst_value | ||
values *= sign | ||
hebo.observe(params, values) |
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 will check if the shape is correct here (seems (1, N)
is correct?)
Anyways, I will benchmark your code and merge this PR!
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.
Thanks! fyi: I confirmed that simply changing line134 to hebo.observe(params, values[None, :])
or hebo.observe(params, values[None, :].T)
fails.
I confirmed it works! |
Contributor Agreements
Please read the contributor agreements and if you agree, please click the checkbox below.
Tip
Please follow the Quick TODO list to smoothly merge your PR.
Motivation
I would like to see a HEBO implementation that can be a drop-in replacement of Samplers in Optuna code that is written in Define-by-Run (its search space is not conditional).
I also want it to support parallelization.
Description of the changes
Modified existing HEBO package.
TODO List towards PR Merge
Please remove this section if this PR is not an addition of a new package.
Otherwise, please check the following TODO list:
./template/
to create your package<COPYRIGHT HOLDER>
inLICENSE
of your package with your nameREADME.md
in your package__init__.py
from __future__ import annotations
at the head of any Python files that include typing to support older Python versionsREADME.md
README.md