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

BAxUS tutorial #1559

Closed
wants to merge 24 commits into from
Closed

BAxUS tutorial #1559

wants to merge 24 commits into from

Conversation

LeoIV
Copy link
Contributor

@LeoIV LeoIV commented Dec 12, 2022

Motivation

This pull request adds a tutorial for BAxUS (published at NeurIPS 2022), a novel BO method for high-dimensional problems. BAxUS allows for sample-efficient BO by using nested random embeddings that preserve observations.

Including BAxUS as a tutorial in Botorch helps other researchers to build on our work and makes it accessible for practitioners.

Have you read the Contributing Guidelines on pull requests?

Yes.

Test Plan

This PR does not add any core functionality, therefore no tests were added.

Related PRs

No new functionality.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Dec 12, 2022
@LeoIV LeoIV marked this pull request as ready for review December 12, 2022 17:27
@dme65 dme65 self-requested a review December 12, 2022 18:27
@dme65
Copy link
Contributor

dme65 commented Dec 12, 2022

Hi Leonard, thank you for the PR! I'll review this in the next few days.

@codecov
Copy link

codecov bot commented Dec 13, 2022

Codecov Report

Merging #1559 (c132685) into main (e5f4d14) will not change coverage.
The diff coverage is n/a.

❗ Current head c132685 differs from pull request most recent head 6c1e66b. Consider uploading reports for the commit 6c1e66b to get more accurate results

@@            Coverage Diff            @@
##              main     #1559   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          170       170           
  Lines        14610     14610           
=========================================
  Hits         14610     14610           

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

Copy link
Contributor

@dme65 dme65 left a comment

Choose a reason for hiding this comment

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

Thank you for contributing this tutorial and sorry for the delayed review! This looks great to me overall.

On a high level there is plenty of overlap between this tutorial and the TuRBO and SCBO tutorials. This is outside the scope of this diff, but we should probably get some of the core trust region functionality checked into BoTorch so we can cut some of the code in these tutorials. cc @Balandat .

  • Can you run isort and flake8 on the notebook? Some of the lines are quite long which makes the code hard to read.
  • Why are you using a domain of [-5, 15]^500? This is a bit non-standard for Branin which is usually optimized over [-5, 10] x [0, 15]. You can do something similar to https://github.com/pytorch/botorch/blob/main/tutorials/saasbo.ipynb in which case you can avoid having to define DummyBranin.
  • Why are you learning the GP hyperparameters using Adam instead of calling fit_gpytorch_mll which will use L-BFGS-B? We generally find that fit_gpytorch_mll works better and you can see how this is done in https://botorch.org/tutorials/turbo_1.
  • Can you rename X_turbo, Y_turbo, etc. to X_baxus, Y_baxus, … ?
  • Dummy Branin -> Embedded Branin

@LeoIV
Copy link
Contributor Author

LeoIV commented Jan 13, 2023

Thank you for the review! I agree that there's a lot of overlap, but I think it's better to use similar code than to implement it differently if we cannot share code between the tutorials.

  • I switched to fit_gpytorch_mll. I changed it originally because I ran into errors with that before. I guess the reason is that when I increase the target space, all observations are constrained to a linear subspace. But I switched back and have yet to face problems.
  • I now use [-5, 10] and [0, 15] (same method as Saasbo)
  • Renamed "Dummy" to ``Embedded'' and X_turbo to `X_baxus` etc.
  • I ran isort and black on the notebook

Please let me know if I need to make additional changes!

@facebook-github-bot
Copy link
Contributor

@dme65 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@Balandat Balandat left a comment

Choose a reason for hiding this comment

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

thanks, there are a few places in which things can be cleaned up but overall this lgtm.

@Balandat
Copy link
Contributor

Thanks @LeoIV for making the edits. @dme65 is currently out - let's wait for him to get back to merge this in.

@facebook-github-bot
Copy link
Contributor

@dme65 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@saitcakmak
Copy link
Contributor

Looks like the model fitting occasionally fails in the smoke test mode.
First attempt failed: https://github.com/pytorch/botorch/actions/runs/4239527520/attempts/1
Re-run succeeded: https://github.com/pytorch/botorch/actions/runs/4239527520/attempts/2

Would you mind setting the seed so that this doesn't lead to CI failures? If you have other ideas for having it deterministically succeed, that'd also be great.

@LeoIV
Copy link
Contributor Author

LeoIV commented Feb 24, 2023

Thanks, I fixed the seed. When the embedding is increased, the previous observations lie in a lower-dimensional subspace of that higher-dimensional embedding. This seems to cause problems with LBFGS in some cases. What I do in my work is to catch the ModelFittingError and revert to Adam-based MLE. I could add that but it would increase the notebook length by ~10-20 lines.

@saitcakmak
Copy link
Contributor

What I do in my work is to catch the ModelFittingError and revert to Adam-based MLE. I could add that but it would increase the notebook length by ~10-20 lines.

I think that could be helpful for someone else that's using this tutorial to optimize their problem and runs into a similar issue. Let's add it with a simple comment explaining why this is needed.

…nings:

We scale the input data but to a different domain due to the BAxUS embedding
@LeoIV
Copy link
Contributor Author

LeoIV commented Feb 27, 2023

I added the fallback optimization and a comment about that. Also, I added a context manager to suppress the input data validation. The data is normalized but to [-1, 1] instead of [0, 1] due to the choice of the embedding.

@facebook-github-bot
Copy link
Contributor

@dme65 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@dme65 merged this pull request in 23d1a3b.

facebook-github-bot pushed a commit that referenced this pull request Jan 17, 2024
…lt BoTorch kernel for BAxUS. (#2165)

Summary:
This commit does two things:

First, it fixes a bug that occurs when trying to split a bin with a single element.

Also, we now use the default BoTorch Matern kernel instead of using MLE and lengthscale constraints.

<!--
Thank you for sending the PR! We appreciate you spending the time to make BoTorch better.

Help us understand your motivation by explaining why you decided to make this change.

You can learn more about contributing to BoTorch here: https://github.com/pytorch/botorch/blob/main/CONTRIBUTING.md
-->

## Motivation

I received a bug report via email for a slightly different benchmark setup that affects the code in the BAxUS tutorial. The bug occurs in cases when, after splitting, a bin contains only a single element, but other bins contain more than one element. In that case, the previous code attempted to split that bin which later caused an error. This commit fixes this bug and, at the same time, removes the custom Matern kernel we used in the previous version. The kernel does not improve performance but adds overhead to the tutorial.

### Have you read the [Contributing Guidelines on pull requests](https://github.com/pytorch/botorch/blob/main/CONTRIBUTING.md#pull-requests)?

Yes

Pull Request resolved: #2165

Test Plan:
I tested this version on multiple benchmark setups to ensure this bug is fixed.

## Related PRs

Initial PR for BAxUS tutorial: #1559

Reviewed By: SebastianAment

Differential Revision: D52718499

Pulled By: saitcakmak

fbshipit-source-id: 7b2af5ec988406b3e482baa3ddf9f0becc17e45c
stefanpricopie pushed a commit to stefanpricopie/botorch that referenced this pull request Feb 27, 2024
…lt BoTorch kernel for BAxUS. (pytorch#2165)

Summary:
This commit does two things:

First, it fixes a bug that occurs when trying to split a bin with a single element.

Also, we now use the default BoTorch Matern kernel instead of using MLE and lengthscale constraints.

<!--
Thank you for sending the PR! We appreciate you spending the time to make BoTorch better.

Help us understand your motivation by explaining why you decided to make this change.

You can learn more about contributing to BoTorch here: https://github.com/pytorch/botorch/blob/main/CONTRIBUTING.md
-->

## Motivation

I received a bug report via email for a slightly different benchmark setup that affects the code in the BAxUS tutorial. The bug occurs in cases when, after splitting, a bin contains only a single element, but other bins contain more than one element. In that case, the previous code attempted to split that bin which later caused an error. This commit fixes this bug and, at the same time, removes the custom Matern kernel we used in the previous version. The kernel does not improve performance but adds overhead to the tutorial.

### Have you read the [Contributing Guidelines on pull requests](https://github.com/pytorch/botorch/blob/main/CONTRIBUTING.md#pull-requests)?

Yes

Pull Request resolved: pytorch#2165

Test Plan:
I tested this version on multiple benchmark setups to ensure this bug is fixed.

## Related PRs

Initial PR for BAxUS tutorial: pytorch#1559

Reviewed By: SebastianAment

Differential Revision: D52718499

Pulled By: saitcakmak

fbshipit-source-id: 7b2af5ec988406b3e482baa3ddf9f0becc17e45c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants