Skip to content
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 batched sampling with BoTorch #4591

Merged
merged 17 commits into from
May 12, 2023

Conversation

kstoneriv3
Copy link
Contributor

@kstoneriv3 kstoneriv3 commented Apr 9, 2023

Motivation

Currently, botorch integration of Optuna does not take the running trials into account when calculating the acquisition function. (By the way, in contrast, TPE has the constant_lier option that tries to leverage the information of running trials.) However, the original botorch API can leverage this information, and that seems to substantially improve parallel optimization performance.

On a simple benchmark using 10-dimensional quadratic function (y = sum_{i=0, ..., 9} |x_i|^2 with -5 <= x_i <= 5), with n_trials = 40 and n_workers=10, the average objective values were 4.55 ± 0.22 (w/ batching) vs 10.30 ± 0.59 (w/o batching). The script for the benchmark can be found at https://gist.github.com/kstoneriv3/1e877830e535d9ebea0f9d55ed50734c.

Description of the changes

I just need to change several lines of code at optuna.integration.botorch for passing the information about running trials to the BoTorch API. The test is WIP.

@github-actions github-actions bot added the optuna.integration Related to the `optuna.integration` submodule. This is automatically labeled by github-actions. label Apr 9, 2023
@contramundum53
Copy link
Member

Changing the signature of candidates_func is considered a breaking change.

I personally think that it is OK because 1. BoTorchSampler itself is experimental, 2. not many people seem to be using customized candidates_func, and 3. for those people who do customize candidates_func, it is very easy to fix.

But it needs to be discussed.

It is also possible to avoid breaking change by adding a try/catch or a condition on calling candidates_func. (Although I think it's a bit of over-engineering.)

@kstoneriv3 kstoneriv3 marked this pull request as ready for review April 10, 2023 10:33
@kstoneriv3
Copy link
Contributor Author

Thank you for the preliminary review! I added a test so the PR is ready for review.

@codecov-commenter
Copy link

codecov-commenter commented Apr 10, 2023

Codecov Report

Merging #4591 (e178de8) into master (41045ce) will increase coverage by 0.01%.
The diff coverage is 95.23%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master    #4591      +/-   ##
==========================================
+ Coverage   90.88%   90.89%   +0.01%     
==========================================
  Files         184      184              
  Lines       13959    13983      +24     
==========================================
+ Hits        12686    12710      +24     
  Misses       1273     1273              
Impacted Files Coverage Δ
optuna/integration/botorch.py 96.01% <95.23%> (+0.37%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@kstoneriv3
Copy link
Contributor Author

kstoneriv3 commented Apr 10, 2023

Following the comment by @contramundum53, I added a commit that would ensure backward compatibility. As discussed above, it seems to be a bit of overengineering and makes sample_relative even bigger. Please let me know whether you would like to keep it or not.

If you are happy with the current implementation, I will add an additional test for checking the backward compatibility and warning.

Kei Ishikawa added 2 commits April 10, 2023 12:59
@github-actions
Copy link
Contributor

This pull request has not seen any recent activity.

@github-actions github-actions bot added the stale Exempt from stale bot labeling. label Apr 20, 2023
Copy link
Member

@HideakiImamura HideakiImamura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. I have several comments. PTAL.

optuna/integration/botorch.py Show resolved Hide resolved
tests/integration_tests/test_botorch.py Show resolved Hide resolved
Copy link
Member

@contramundum53 contramundum53 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for my late reply 🙇
I added some comments.

optuna/integration/botorch.py Outdated Show resolved Hide resolved
@kstoneriv3
Copy link
Contributor Author

Thank you for the review! I should have addressed all of your reviews. PTAL

@github-actions github-actions bot removed the stale Exempt from stale bot labeling. label Apr 23, 2023
kstoneriv3 and others added 2 commits May 2, 2023 21:24
Copy link
Member

@contramundum53 contramundum53 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the PR!

Copy link
Member

@HideakiImamura HideakiImamura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@HideakiImamura HideakiImamura merged commit 9cb6ea8 into optuna:master May 12, 2023
31 checks passed
@HideakiImamura HideakiImamura added the feature Change that does not break compatibility, but affects the public interfaces. label May 12, 2023
@HideakiImamura HideakiImamura added this to the v3.2.0 milestone May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Change that does not break compatibility, but affects the public interfaces. optuna.integration Related to the `optuna.integration` submodule. This is automatically labeled by github-actions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants