nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: cornellius-gp/gpytorch
Pull request #613 (2019-04-03 01:40:35)

Fix warning in psd_safe_cholesky
This was never reachable due to recent changes. This makes sure it is and adds the appropriate test.


Patch:
diff --git a/gpytorch/utils/cholesky.py b/gpytorch/utils/cholesky.py
index ed01b2db..99666359 100644
--- a/gpytorch/utils/cholesky.py
+++ b/gpytorch/utils/cholesky.py
@@ -38,11 +38,11 @@ def psd_safe_cholesky(A, upper=False, out=None, jitter=None):
                 if A.dim() > 2 and A.is_cuda:
                     if torch.isnan(L if out is None else out).any():
                         raise RuntimeError("singular")
+                warnings.warn(f"A not p.d., added jitter of {jitter} to the diagonal", RuntimeWarning)
                 return L
             except RuntimeError:
                 continue
 
-        warnings.warn("A not p.d., added jitter of {} to the diagonal".format(jitter), RuntimeWarning)
         raise e
 
 


Test patch:
diff --git a/test/utils/test_cholesky.py b/test/utils/test_cholesky.py
index 931dd719..396753e8 100644
--- a/test/utils/test_cholesky.py
+++ b/test/utils/test_cholesky.py
@@ -1,6 +1,7 @@
 #!/usr/bin/env python3
 
 import unittest
+import warnings
 from test._utils import least_used_cuda_device
 
 import torch
@@ -63,13 +64,21 @@ class TestPSDSafeCholesky(unittest.TestCase):
                 Aprime = A.clone()
                 Aprime[..., idx, idx] += 1e-6 if A.dtype == torch.float32 else 1e-8
                 L_exp = torch.cholesky(Aprime)
-                L_safe = psd_safe_cholesky(A)
+                with warnings.catch_warnings(record=True) as w:
+                    L_safe = psd_safe_cholesky(A)
+                    self.assertEqual(len(w), 1)
+                    self.assertTrue(issubclass(w[-1].category, RuntimeWarning))
+                    self.assertTrue("A not p.d., added jitter" in str(w[-1].message))
                 self.assertTrue(torch.allclose(L_exp, L_safe))
                 # user-defined value
                 Aprime = A.clone()
                 Aprime[..., idx, idx] += 1e-2
                 L_exp = torch.cholesky(Aprime)
-                L_safe = psd_safe_cholesky(A, jitter=1e-2)
+                with warnings.catch_warnings(record=True) as w:
+                    L_safe = psd_safe_cholesky(A, jitter=1e-2)
+                    self.assertEqual(len(w), 1)
+                    self.assertTrue(issubclass(w[-1].category, RuntimeWarning))
+                    self.assertTrue("A not p.d., added jitter" in str(w[-1].message))
                 self.assertTrue(torch.allclose(L_exp, L_safe))
 
     def test_psd_safe_cholesky_psd_cuda(self, cuda=False):
Repository: cornellius-gp/gpytorch
Pull request #707 (2019-05-28 21:17:14)

Add prior_mode context manager for Exact GP models
Implements #696.

Usage:

```
with gpytorch.settings.prior_mode(True):
     model(test_input)
```


Patch:
diff --git a/gpytorch/models/exact_gp.py b/gpytorch/models/exact_gp.py
index 65c4244d..261d3a89 100644
--- a/gpytorch/models/exact_gp.py
+++ b/gpytorch/models/exact_gp.py
@@ -231,7 +231,7 @@ class ExactGP(GP):
             return res
 
         # Prior mode
-        elif self.train_inputs is None or self.train_targets is None:
+        elif settings.prior_mode.on() or self.train_inputs is None or self.train_targets is None:
             full_inputs = args
             full_output = super(ExactGP, self).__call__(*full_inputs, **kwargs)
             if settings.debug().on():
diff --git a/gpytorch/settings.py b/gpytorch/settings.py
index a0cf4823..86fd940b 100644
--- a/gpytorch/settings.py
+++ b/gpytorch/settings.py
@@ -435,6 +435,15 @@ class num_trace_samples(_value_context):
     _global_value = 10
 
 
+class prior_mode(_feature_flag):
+    """
+    If set to true, GP models will be evaluated in prior mode.
+    This allows evaluating any Exact GP model in prior mode, even it if has training data / targets.
+    """
+
+    _state = False
+
+
 class skip_logdet_forward(_feature_flag):
     """
     .. warning:


Test patch:
diff --git a/test/models/test_exact_gp.py b/test/models/test_exact_gp.py
index 1888d799..8784eea2 100644
--- a/test/models/test_exact_gp.py
+++ b/test/models/test_exact_gp.py
@@ -140,6 +140,21 @@ class TestExactGP(_ModelTestCase, unittest.TestCase):
         self.assertTrue(output.lazy_covariance_matrix.size(-1) == batch_data.size(-2))
         self.assertTrue(output.lazy_covariance_matrix.size(-2) == batch_data.size(-2))
 
+    def test_prior_mode(self):
+        train_data = self.create_test_data()
+        likelihood, labels = self.create_likelihood_and_labels()
+        prior_model = self.create_model(None, None, likelihood)
+        model = self.create_model(train_data, labels, likelihood)
+        prior_model.eval()
+        model.eval()
+
+        test_data = self.create_test_data()
+        prior_out = prior_model(test_data)
+        with gpytorch.settings.prior_mode(True):
+            prior_out_cm = model(test_data)
+        self.assertTrue(torch.allclose(prior_out.mean, prior_out_cm.mean))
+        self.assertTrue(torch.allclose(prior_out.covariance_matrix, prior_out_cm.covariance_matrix))
+
 
 class TestInterpolatedExactGP(TestExactGP):
     def create_model(self, train_x, train_y, likelihood):
Repository: cornellius-gp/gpytorch
Pull request #751 (2019-06-23 15:45:32)

Fix Interval class upper bound transform for bug #744
Fix Interval class upper bound transform for bug #744. The new code multiplies the tensor by (upper_bound - lower_bound) before adding lower_bound, thus keeping the tensor between bounds.


Patch:
diff --git a/gpytorch/constraints/constraints.py b/gpytorch/constraints/constraints.py
index 30b5b4af..6853f15e 100644
--- a/gpytorch/constraints/constraints.py
+++ b/gpytorch/constraints/constraints.py
@@ -94,7 +94,7 @@ class Interval(Module):
                     "GreaterThan or LessThan instead."
                 )
 
-        transformed_tensor = (self._transform(tensor) * self.upper_bound) + self.lower_bound
+        transformed_tensor = (self._transform(tensor) * (self.upper_bound - self.lower_bound)) + self.lower_bound
 
         return transformed_tensor
 
@@ -115,7 +115,7 @@ class Interval(Module):
                     "GreaterThan or LessThan instead."
                 )
 
-        tensor = self._inv_transform((transformed_tensor - self.lower_bound) / self.upper_bound)
+        tensor = self._inv_transform((transformed_tensor - self.lower_bound) / (self.upper_bound - self.lower_bound))
 
         return tensor
 


Test patch:
diff --git a/test/constraints/test_constraints.py b/test/constraints/test_constraints.py
index 611c0ac4..1d47a5f5 100644
--- a/test/constraints/test_constraints.py
+++ b/test/constraints/test_constraints.py
@@ -28,7 +28,7 @@ class TestInterval(unittest.TestCase, BaseTestCase):
         v = torch.tensor(-3.0)
 
         value = constraint.transform(v)
-        actual_value = (5.0 * sigmoid(v)) + 1.0
+        actual_value = ((5.0 - 1.0) * sigmoid(v)) + 1.0
 
         self.assertAllClose(value, actual_value)
 
@@ -48,8 +48,8 @@ class TestInterval(unittest.TestCase, BaseTestCase):
 
         value = constraint.transform(v)
         actual_value = v.clone()
-        actual_value[0] = 3.0 * sigmoid(v[0]) + 1.0
-        actual_value[1] = 4.0 * sigmoid(v[1]) + 2.0
+        actual_value[0] = (3.0 - 1.0) * sigmoid(v[0]) + 1.0
+        actual_value[1] = (4.0 - 2.0) * sigmoid(v[1]) + 2.0
 
         self.assertAllClose(value, actual_value)