Skip to content

Commit

Permalink
Fix broken cuda tests (#1115)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #1115

See title

Reviewed By: saitcakmak

Differential Revision: D34761452

fbshipit-source-id: b29f6d86d3aaa8b8b16e6c660d8d8d7dac65758d
  • Loading branch information
dme65 authored and facebook-github-bot committed Mar 9, 2022
1 parent 21b4616 commit 18a3b26
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion botorch/models/multitask.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def __init__(
if task_covar_prior is None:
task_covar_prior = LKJCovariancePrior(
n=num_tasks,
eta=kwargs.get("eta", 1.5),
eta=torch.tensor(kwargs.get("eta", 1.5)).to(train_X),
sd_prior=kwargs.get(
"sd_prior",
SmoothedBoxPrior(math.exp(-6), math.exp(1.25), 0.05),
Expand Down
4 changes: 3 additions & 1 deletion test/acquisition/multi_objective/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ def test_prune_inferior_points_multi_objective(self):
)
if self.device.type == "cuda":
# sorting has different order on cuda
self.assertTrue(torch.equal(X_pruned, torch.stack([X[2], X[1]], dim=0)))
self.assertTrue(
torch.equal(X_pruned, X[[2, 1]]) or torch.equal(X_pruned, X[[1, 2]])
)
else:
self.assertTrue(torch.equal(X_pruned, X[:2]))
# test that zero-probability is in fact pruned
Expand Down
24 changes: 17 additions & 7 deletions test/acquisition/test_max_value_entropy_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ def test_q_max_value_entropy(self):

# Test with multi-output model w/ transform.
mm = MESMockModel(num_outputs=2)
pt = ScalarizedPosteriorTransform(weights=torch.ones(2, dtype=dtype))
pt = ScalarizedPosteriorTransform(
weights=torch.ones(2, device=self.device, dtype=dtype)
)
for gumbel in (True, False):
qMVE = qMaxValueEntropy(
mm,
Expand Down Expand Up @@ -225,7 +227,9 @@ def test_q_lower_bound_max_value_entropy(self):

# Test with multi-output model w/ transform.
mm = MESMockModel(num_outputs=2)
pt = ScalarizedPosteriorTransform(weights=torch.ones(2, dtype=dtype))
pt = ScalarizedPosteriorTransform(
weights=torch.ones(2, device=self.device, dtype=dtype)
)
qGIBBON = qLowerBoundMaxValueEntropy(
mm,
candidate_set,
Expand Down Expand Up @@ -270,7 +274,9 @@ def test_q_multi_fidelity_max_value_entropy(self):

# Test with multi-output model w/ transform.
mm = MESMockModel(num_outputs=2)
pt = ScalarizedPosteriorTransform(weights=torch.ones(2, dtype=dtype))
pt = ScalarizedPosteriorTransform(
weights=torch.ones(2, device=self.device, dtype=dtype)
)
qMF_MVE = qMultiFidelityMaxValueEntropy(
model=mm,
candidate_set=candidate_set,
Expand All @@ -284,13 +290,15 @@ def test_sample_max_value_Gumbel(self):
for dtype in (torch.float, torch.double):
torch.manual_seed(7)
mm = MESMockModel()
candidate_set = torch.rand(3, 10, 2, dtype=dtype)
candidate_set = torch.rand(3, 10, 2, device=self.device, dtype=dtype)
samples = _sample_max_value_Gumbel(mm, candidate_set, 5)
self.assertEqual(samples.shape, torch.Size([5, 3]))

# Test with multi-output model w/ transform.
mm = MESMockModel(num_outputs=2)
pt = ScalarizedPosteriorTransform(weights=torch.ones(2, dtype=dtype))
pt = ScalarizedPosteriorTransform(
weights=torch.ones(2, device=self.device, dtype=dtype)
)
samples = _sample_max_value_Gumbel(
mm, candidate_set, 5, posterior_transform=pt
)
Expand All @@ -300,13 +308,15 @@ def test_sample_max_value_Thompson(self):
for dtype in (torch.float, torch.double):
torch.manual_seed(7)
mm = MESMockModel()
candidate_set = torch.rand(3, 10, 2, dtype=dtype)
candidate_set = torch.rand(3, 10, 2, device=self.device, dtype=dtype)
samples = _sample_max_value_Thompson(mm, candidate_set, 5)
self.assertEqual(samples.shape, torch.Size([5, 3]))

# Test with multi-output model w/ transform.
mm = MESMockModel(num_outputs=2)
pt = ScalarizedPosteriorTransform(weights=torch.ones(2, dtype=dtype))
pt = ScalarizedPosteriorTransform(
weights=torch.ones(2, device=self.device, dtype=dtype)
)
samples = _sample_max_value_Thompson(
mm, candidate_set, 5, posterior_transform=pt
)
Expand Down
2 changes: 1 addition & 1 deletion test/models/test_multitask.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def test_KroneckerMultiTaskGP_custom(self):
)
task_covar_prior = LKJCovariancePrior(
n=2,
eta=0.5,
eta=torch.tensor(0.5, **tkwargs),
sd_prior=SmoothedBoxPrior(math.exp(-3), math.exp(2), 0.1),
)
model_kwargs = {
Expand Down

0 comments on commit 18a3b26

Please sign in to comment.