optimizer.n_iter = 0
for i in range(50):
optimizer.zero_grad()
output = model.forward(train_x)
loss = -model.marginal_log_likelihood(output, train_y)
loss.backward()
optimizer.n_iter += 1
optimizer.step()
After Change
// Set back to eval mode
model.eval()
test_preds = likelihood(model(train_x)).mean().ge(0.5).float().mul(2).sub(1).squeeze()
mean_abs_error = torch.mean(torch.abs(train_y - test_preds) / 2)
assert(mean_abs_error.data.squeeze()[0] < 1e-5)