-
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.
Monotonic rejection model and generator (#458)
Summary: monotonic rejection model GPU support, since they're tied to the generator, we also ensure the generators are gpu ready as well. Differential Revision: D65638150
- Loading branch information
1 parent
d096c6a
commit 26ec708
Showing
11 changed files
with
283 additions
and
47 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
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,6 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Meta, 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. |
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,51 @@ | ||
#!/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.acquisition.monotonic_rejection import MonotonicMCLSE | ||
from aepsych.acquisition.objective import ProbitObjective | ||
from aepsych.models.derivative_gp import MixedDerivativeVariationalGP | ||
from botorch.acquisition.objective import IdentityMCObjective | ||
from botorch.utils.testing import BotorchTestCase | ||
|
||
|
||
class TestMonotonicAcq(BotorchTestCase): | ||
def test_monotonic_acq_gpu(self): | ||
# Init | ||
train_X_aug = torch.tensor( | ||
[[0.0, 0.0, 0.0], [1.0, 1.0, 0.0], [2.0, 2.0, 0.0]] | ||
).cuda() | ||
deriv_constraint_points = torch.tensor( | ||
[[0.0, 0.0, 1.0], [1.0, 1.0, 1.0], [2.0, 2.0, 1.0]] | ||
).cuda() | ||
train_Y = torch.tensor([[1.0], [2.0], [3.0]]).cuda() | ||
|
||
m = MixedDerivativeVariationalGP( | ||
train_x=train_X_aug, train_y=train_Y, inducing_points=train_X_aug | ||
).cuda() | ||
acq = MonotonicMCLSE( | ||
model=m, | ||
deriv_constraint_points=deriv_constraint_points, | ||
num_samples=5, | ||
num_rejection_samples=8, | ||
target=1.9, | ||
) | ||
self.assertTrue(isinstance(acq.objective, IdentityMCObjective)) | ||
acq = MonotonicMCLSE( | ||
model=m, | ||
deriv_constraint_points=deriv_constraint_points, | ||
num_samples=5, | ||
num_rejection_samples=8, | ||
target=1.9, | ||
objective=ProbitObjective(), | ||
).cuda() | ||
# forward | ||
acq(train_X_aug) | ||
Xfull = torch.cat((train_X_aug, acq.deriv_constraint_points), dim=0) | ||
posterior = m.posterior(Xfull) | ||
samples = acq.sampler(posterior) | ||
self.assertEqual(samples.shape, torch.Size([5, 6, 1])) |
Oops, something went wrong.