Fix batch svgp test
@@ -69,21 +69,23 @@ class TestSVGPRegression(unittest.TestCase):
def test_regression_error(self):
train_x, train_y = train_data()
likelihood = GaussianLikelihood()
- model = SVGPRegressionModel(train_x[:, :25, :])
+ inducing_points = torch.linspace(0, 1, 25).unsqueeze(-1).repeat(2, 1, 1)
+ model = SVGPRegressionModel(inducing_points)
mll = gpytorch.mlls.VariationalELBO(likelihood, model, num_data=train_y.size(-1))
# Find optimal model hyperparameters
model.train()
likelihood.train()
- optimizer = optim.Adam([{'params': model.parameters()}, {'params': likelihood.parameters()}], lr=0.1)
- optimizer.n_iter = 0
- for _ in range(250):
+ optimizer = optim.Adam([
+ {'params': model.parameters()},
+ {'params': likelihood.parameters()},
+ ], lr=0.01)
+ for _ in range(150):
optimizer.zero_grad()
output = model(train_x)
loss = -mll(output, train_y)
loss = loss.sum()
loss.backward()
- optimizer.n_iter += 1
optimizer.step()
for param in model.parameters():
@@ -106,21 +108,23 @@ class TestSVGPRegression(unittest.TestCase):
if torch.cuda.is_available():
train_x, train_y = train_data(cuda=True)
likelihood = GaussianLikelihood().cuda()
- model = SVGPRegressionModel(train_x[:, :25, :]).cuda()
+ inducing_points = torch.linspace(0, 1, 25).unsqueeze(-1).repeat(2, 1, 1)
+ model = SVGPRegressionModel(inducing_points).cuda()
mll = gpytorch.mlls.VariationalELBO(likelihood, model, num_data=train_y.size(-1))
# Find optimal model hyperparameters
model.train()
likelihood.train()
- optimizer = optim.Adam([{'params': model.parameters()}, {'params': likelihood.parameters()}], lr=0.1)
- optimizer.n_iter = 0
- for _ in range(250):
+ optimizer = optim.Adam([
+ {'params': model.parameters()},
+ {'params': likelihood.parameters()},
+ ], lr=0.01)
+ for _ in range(150):
optimizer.zero_grad()
output = model(train_x)
loss = -mll(output, train_y)
loss = loss.sum()
loss.backward()
- optimizer.n_iter += 1
optimizer.step()
for param in model.parameters():
