From 660065547dd65a27b0c03bcf87736eb51b309ee0 Mon Sep 17 00:00:00 2001 From: Elizabeth Santorella Date: Thu, 9 May 2024 14:37:46 -0700 Subject: [PATCH] Fix pathwise sampler bug (#2337) Summary: Pull Request resolved: https://github.com/pytorch/botorch/pull/2337 `_draw_matheron_paths_ExactGP` calls `_gaussian_update_ExactGP` (as the update_strategy argument). It was passing an incorrect argument `train_targets` in place of `target_values`. This led the `Y` values to being silently ignored. Reviewed By: saitcakmak Differential Revision: D57175013 fbshipit-source-id: f3a1c304ee221d1460284b51f423af894c7c6a9f --- .../sampling/pathwise/posterior_samplers.py | 2 +- botorch/sampling/pathwise/update_strategies.py | 1 - .../pathwise/test_update_strategies.py | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/botorch/sampling/pathwise/posterior_samplers.py b/botorch/sampling/pathwise/posterior_samplers.py index 04223d63af..64f8831394 100644 --- a/botorch/sampling/pathwise/posterior_samplers.py +++ b/botorch/sampling/pathwise/posterior_samplers.py @@ -139,7 +139,7 @@ def _draw_matheron_paths_ExactGP( update_paths = update_strategy( model=model, sample_values=sample_values, - train_targets=train_Y, + target_values=train_Y, ) return MatheronPath( diff --git a/botorch/sampling/pathwise/update_strategies.py b/botorch/sampling/pathwise/update_strategies.py index d1e49985bf..ac760f9d44 100644 --- a/botorch/sampling/pathwise/update_strategies.py +++ b/botorch/sampling/pathwise/update_strategies.py @@ -112,7 +112,6 @@ def _gaussian_update_ExactGP( points: Optional[Tensor] = None, noise_covariance: Optional[Union[Tensor, LinearOperator]] = None, scale_tril: Optional[Union[Tensor, LinearOperator]] = None, - **ignore: Any, ) -> GeneralizedLinearPath: if points is None: (points,) = get_train_inputs(model, transformed=True) diff --git a/test/sampling/pathwise/test_update_strategies.py b/test/sampling/pathwise/test_update_strategies.py index 1e85bac474..7a4d7ad334 100644 --- a/test/sampling/pathwise/test_update_strategies.py +++ b/test/sampling/pathwise/test_update_strategies.py @@ -26,6 +26,7 @@ from botorch.utils.testing import BotorchTestCase from gpytorch.kernels import MaternKernel, RBFKernel, ScaleKernel from gpytorch.likelihoods import BernoulliLikelihood +from gpytorch.models import ExactGP from linear_operator.operators import ZeroLinearOperator from linear_operator.utils.cholesky import psd_safe_cholesky from torch import Size @@ -204,3 +205,20 @@ def _test_gaussian_updates(self, model): with patch.object(model, "likelihood", new=BernoulliLikelihood()): with self.assertRaises(NotImplementedError): gaussian_update(model=model, sample_values=sample_values) + + with self.subTest("Exact models with `None` target_values"): + assert isinstance(model, ExactGP) + torch.manual_seed(0) + path_none_target_values = gaussian_update( + model=model, + sample_values=sample_values, + ) + torch.manual_seed(0) + path_with_target_values = gaussian_update( + model=model, + sample_values=sample_values, + target_values=get_train_targets(model, transformed=True), + ) + self.assertAllClose( + path_none_target_values.weight, path_with_target_values.weight + )