Skip to content

Commit

Permalink
Fix flaky VariationalGP unit test (#1836)
Browse files Browse the repository at this point in the history
Summary:
## Motivation

A newly-added test in `TestSingleTaskVariationalGP` is flaky; a numerical check can fail depending on the seed. The failure is not surprising because the test is asserting that the mean posterior mean over the train data equals the mean of the `y` data.

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

Yes

Pull Request resolved: #1836

Test Plan: Ran it with 100 different seeds

Reviewed By: Balandat

Differential Revision: D45885496

Pulled By: esantorella

fbshipit-source-id: c5f48aa67f72ebd86219f741bf84a29e2faf5b07
  • Loading branch information
esantorella authored and facebook-github-bot committed May 15, 2023
1 parent 0ad879c commit be1a1b3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions test/models/test_approximate_gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# LICENSE file in the root directory of this source tree.

import itertools
import warnings

import torch
from botorch.fit import fit_gpytorch_mll
Expand Down Expand Up @@ -315,12 +316,16 @@ def test_input_transform(self) -> None:

for input_transform in [None, Normalize(1)]:
with self.subTest(input_transform=input_transform):
model = SingleTaskVariationalGP(
train_X=train_X, train_Y=y, input_transform=input_transform
)
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", message="Input data is not contained"
)
model = SingleTaskVariationalGP(
train_X=train_X, train_Y=y, input_transform=input_transform
)
mll = VariationalELBO(
model.likelihood, model.model, num_data=train_X.shape[-2]
)
fit_gpytorch_mll(mll)
post = model.posterior(torch.tensor([train_X.mean()]))
self.assertAllClose(post.mean[0][0], y.mean(), atol=1e-4)
self.assertAllClose(post.mean[0][0], y.mean(), atol=1e-3, rtol=1e-3)

0 comments on commit be1a1b3

Please sign in to comment.