Skip to content

Conversation

@saitcakmak
Copy link
Contributor

Motivation

The current behavior of fit_gpytorch_model is to error out when it receives a NotPSDError and to count hitting maxiter during optimization as an optimization failure.

Labeling maxiter as an optimization failure leads to retrying the model fit, and likely reaching maxiter in each try and labeling all tries as failures. This ends up using more effort than the user intended to (by passing in maxiter in the first place), while offering no real benefit. The proposed solution here is to simply count hitting maxiter as a successful model fit and to return the fit obtained with the given budget.

The NotPSDError during model fit is one of the most common reasons that leads to me having to restart an experiment. What I observed is that when the first try raises NotPSDError, a second try starting from initial parameters sampled from the priors will most of the time produce a successful model fit. So, this proposes to catch the NotPSDError and retry the model fit with new initial parameter values.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Unittests.

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/pytorch/botorch, and link to your PR here.)

cc @sdaulton

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Dec 1, 2021
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, this makes a lot of sense to me! A few comments inline, but this looks good overall.

@codecov
Copy link

codecov bot commented Dec 2, 2021

Codecov Report

Merging #1007 (9fd8ed4) into main (d0326cb) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #1007   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          110       110           
  Lines         8562      8570    +8     
=========================================
+ Hits          8562      8570    +8     
Impacted Files Coverage Δ
botorch/fit.py 100.00% <100.00%> (ø)
botorch/utils/sampling.py 100.00% <0.00%> (ø)
botorch/acquisition/multi_objective/monte_carlo.py 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d0326cb...9fd8ed4. Read the comment docs.

@facebook-github-bot
Copy link
Contributor

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

@Balandat
Copy link
Contributor

Balandat commented Dec 2, 2021

Looks like we lost a tiny bit of test coverage since we don't actually fail fitting anymore other than with the NonPSDError. Would you mind adding a test for that (e.g.. fail with some other exception)?

@facebook-github-bot
Copy link
Contributor

@saitcakmak has updated the pull request. You must reimport the pull request before landing.

@saitcakmak
Copy link
Contributor Author

I didn't realize we needed settings.debug(True) for warnings to work. I spent some time wondering why my warning wasn't being caught...
Also, I can't find a way to use mock to produce warnings. I was looking for something like side_effect but it doesn't seem to support warnings. If you know of a way of wrapping a function with a warning, I'd love to learn!

@facebook-github-bot
Copy link
Contributor

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

saitcakmak added a commit to saitcakmak/botorch that referenced this pull request Dec 7, 2021
…torch#1007)

Summary:
<!--
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

The current behavior of `fit_gpytorch_model` is to error out when it receives a `NotPSDError` and to count hitting `maxiter` during optimization as an optimization failure.

Labeling `maxiter` as an optimization failure leads to retrying the model fit, and likely reaching `maxiter` in each try and labeling all tries as failures. This ends up using more effort than the user intended to (by passing in `maxiter` in the first place), while offering no real benefit. The proposed solution here is to simply count hitting `maxiter` as a successful model fit and to return the fit obtained with the given budget.

The `NotPSDError` during model fit is one of the most common reasons that leads to me having to restart an experiment. What I observed is that when the first try raises `NotPSDError`, a second try starting from initial parameters sampled from the priors will most of the time produce a successful model fit. So, this proposes to catch the `NotPSDError` and retry the model fit with new initial parameter values.

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

Yes

Pull Request resolved: meta-pytorch#1007

Test Plan:
Unittests.

## Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/pytorch/botorch, and link to your PR here.)

cc sdaulton

Reviewed By: sdaulton

Differential Revision: D32798598

Pulled By: Balandat

fbshipit-source-id: fa70b5c9b4d12673441f2a1842d1c9a3807687a1
@saitcakmak saitcakmak deleted the fit_gpytorch branch December 8, 2021 22:41
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants