Skip to content

Commit

Permalink
Loosen a tolerance to stop test from failing with CUDA (#2512)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #2512

Context:

`botorch.test.mdoels.test_gpytorch.TestModelListGPyTorchModel.test_model_list_gpytorch_model` has been failing when run with CUDA for a couple days, with a numerical error slightly exceeding the set tolerance in single precision.

This PR:
* Slightly loosens the tolerance in single precision
* Updates a couple assertions to use `assertAllClose`
* Updates a couple assertions to use `assertWarns`

Reviewed By: Balandat

Differential Revision: D62343447

fbshipit-source-id: 17f054083f0dfec17b4e036e86c7d80c5ea434c1
  • Loading branch information
esantorella authored and facebook-github-bot committed Sep 9, 2024
1 parent 16853b4 commit 571fe66
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions test/models/test_gpytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,12 @@ def test_model_list_gpytorch_model(self):
m2 = SimpleGPyTorchModel(train_X2, train_Y2)
model = SimpleModelListGPyTorchModel(m1, m2)
self.assertEqual(model.num_outputs, 2)
with warnings.catch_warnings(record=True) as ws:
msg = (
"Component models of SimpleModelListGPyTorchModel have "
"different batch shapes"
)
with self.assertWarnsRegex(Warning, msg):
self.assertEqual(model.batch_shape, torch.Size([2]))
msg = (
"Component models of SimpleModelListGPyTorchModel have "
"different batch shapes"
)
self.assertTrue(any(msg in str(w.message) for w in ws))
# test different batch shapes (not broadcastable)
m2 = SimpleGPyTorchModel(
train_X2.expand(3, *train_X2.shape), train_Y2.expand(3, *train_Y2.shape)
Expand Down Expand Up @@ -491,17 +490,15 @@ def test_model_list_gpytorch_model(self):
),
dim=1,
)
self.assertTrue(torch.allclose(expected_mean, posterior2.mean))
self.assertAllClose(expected_mean, posterior2.mean)
expected_covariance = torch.block_diag(
posterior.covariance_matrix[:2, :2],
mt_posterior.covariance_matrix[:2, :2],
mt_posterior.covariance_matrix[-2:, -2:],
posterior.covariance_matrix[-2:, -2:],
)
self.assertTrue(
torch.allclose(
expected_covariance, posterior2.covariance_matrix, atol=1e-5
)
self.assertAllClose(
expected_covariance, posterior2.covariance_matrix, atol=1e-5
)
# test output indices
posterior = model.posterior(test_X)
Expand All @@ -521,7 +518,8 @@ def test_model_list_gpytorch_model(self):
self.assertAllClose(
posterior_subset.variance,
posterior.variance[..., output_indices],
atol=1e-6,
atol=2e-6 if dtype is torch.float else 1e-6,
rtol=3e-4 if dtype is torch.float else 1e-5,
)
# test observation noise
model = SimpleModelListGPyTorchModel(m1, m2)
Expand Down

0 comments on commit 571fe66

Please sign in to comment.