-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Add gpu support for derivative GP. I noticed that this model isn’t actually like a normal model that can show up in a live experiment with a config, but we should still make it work for GPU. I did most of that but it did require some pretty arcane shenanigans with overriding GPyTorch’s underlying handling of train_inputs. This in turn made me do some arcane mypy stuff. Differential Revision: D65515631
- Loading branch information
1 parent
3406cbe
commit 6fdc918
Showing
6 changed files
with
59 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# All rights reserved. | ||
|
||
# This source code is licensed under the license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
import torch | ||
from aepsych import Config, SequentialStrategy | ||
from aepsych.models.derivative_gp import MixedDerivativeVariationalGP | ||
from botorch.fit import fit_gpytorch_mll | ||
from botorch.utils.testing import BotorchTestCase | ||
from gpytorch.likelihoods import BernoulliLikelihood | ||
from gpytorch.mlls.variational_elbo import VariationalELBO | ||
|
||
|
||
class TestDerivativeGP(BotorchTestCase): | ||
def test_MixedDerivativeVariationalGP_gpu(self): | ||
train_x = torch.cat( | ||
(torch.tensor([1.0, 2.0, 3.0, 4.0]).unsqueeze(1), torch.zeros(4, 1)), dim=1 | ||
) | ||
train_y = torch.tensor([1.0, 2.0, 3.0, 4.0]) | ||
m = MixedDerivativeVariationalGP( | ||
train_x=train_x, | ||
train_y=train_y, | ||
inducing_points=train_x, | ||
fixed_prior_mean=0.5, | ||
).cuda() | ||
|
||
self.assertEqual(m.mean_module.constant.item(), 0.5) | ||
self.assertEqual( | ||
m.covar_module.base_kernel.raw_lengthscale.shape, torch.Size([1, 1]) | ||
) | ||
mll = VariationalELBO( | ||
likelihood=BernoulliLikelihood(), model=m, num_data=train_y.numel() | ||
).cuda() | ||
mll = fit_gpytorch_mll(mll) | ||
test_x = torch.tensor([[1.0, 0], [3.0, 1.0]]).cuda() | ||
m(test_x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,5 @@ def test_gpu_no_model_generator_warn(self): | |
) | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |