Skip to content

Commit fcbf685

Browse files
authored
Fix flaky SVGP classification test (#2495)
1 parent e150496 commit fcbf685

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

gpytorch/test/base_keops_test_case.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_forward_x1_neq_x2(self, use_keops=True, ard=False, **kwargs):
6666
# The patch makes sure that we're actually using KeOps
6767
k1 = kern1(x1, x2).to_dense()
6868
k2 = kern2(x1, x2).to_dense()
69-
self.assertLess(torch.norm(k1 - k2), 1e-4)
69+
self.assertLess(torch.norm(k1 - k2), 1e-3)
7070

7171
if use_keops:
7272
self.assertTrue(keops_mock.called)
@@ -86,7 +86,7 @@ def test_batch_matmul(self, use_keops=True, **kwargs):
8686
# The patch makes sure that we're actually using KeOps
8787
res1 = kern1(x1, x1).matmul(rhs)
8888
res2 = kern2(x1, x1).matmul(rhs)
89-
self.assertLess(torch.norm(res1 - res2), 1e-4)
89+
self.assertLess(torch.norm(res1 - res2), 1e-3)
9090

9191
if use_keops:
9292
self.assertTrue(keops_mock.called)
@@ -115,7 +115,7 @@ def test_gradient(self, use_keops=True, ard=False, **kwargs):
115115
# stack all gradients into a tensor
116116
grad_s1 = torch.vstack(torch.autograd.grad(s1, [*kern1.hyperparameters()]))
117117
grad_s2 = torch.vstack(torch.autograd.grad(s2, [*kern2.hyperparameters()]))
118-
self.assertAllClose(grad_s1, grad_s2, rtol=1e-4, atol=1e-5)
118+
self.assertAllClose(grad_s1, grad_s2, rtol=1e-3, atol=1e-3)
119119

120120
if use_keops:
121121
self.assertTrue(keops_mock.called)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def find_version(*file_paths):
3939

4040
torch_min = "1.11"
4141
install_requires = [
42+
"mpmath>=0.19,<=1.3", # avoid incompatibiltiy with torch+sympy with mpmath 1.4
4243
"scikit-learn",
4344
"scipy",
4445
"linear_operator>=0.5.2",

test/examples/test_svgp_gp_classification.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
def train_data(cuda=False):
19-
train_x = torch.linspace(0, 1, 260)
19+
train_x = torch.linspace(0, 1, 150)
2020
train_y = torch.cos(train_x * (2 * math.pi)).gt(0).float()
2121
if cuda:
2222
return train_x.cuda(), train_y.cuda()
@@ -49,7 +49,7 @@ class TestSVGPClassification(BaseTestCase, unittest.TestCase):
4949
def test_classification_error(self, cuda=False, mll_cls=gpytorch.mlls.VariationalELBO):
5050
train_x, train_y = train_data(cuda=cuda)
5151
likelihood = BernoulliLikelihood()
52-
model = SVGPClassificationModel(torch.linspace(0, 1, 25))
52+
model = SVGPClassificationModel(torch.linspace(0, 1, 64))
5353
mll = mll_cls(likelihood, model, num_data=len(train_y))
5454
if cuda:
5555
likelihood = likelihood.cuda()
@@ -59,12 +59,12 @@ def test_classification_error(self, cuda=False, mll_cls=gpytorch.mlls.Variationa
5959
# Find optimal model hyperparameters
6060
model.train()
6161
likelihood.train()
62-
optimizer = optim.Adam([{"params": model.parameters()}, {"params": likelihood.parameters()}], lr=0.1)
62+
optimizer = optim.Adam([{"params": model.parameters()}, {"params": likelihood.parameters()}], lr=0.03)
6363

6464
_wrapped_cg = MagicMock(wraps=linear_operator.utils.linear_cg)
6565
_cg_mock = patch("linear_operator.utils.linear_cg", new=_wrapped_cg)
6666
with _cg_mock as cg_mock:
67-
for _ in range(400):
67+
for _ in range(100):
6868
optimizer.zero_grad()
6969
output = model(train_x)
7070
loss = -mll(output, train_y)

0 commit comments

Comments
 (0)