Skip to content

Commit 452443a

Browse files
authored
Fix pytorch 1.10 warnings in test suite (#1835)
* Fix warnings in CG * Fix linalg deprication warnings * Fix __floordiv__ deprication warnings * Fix cholesky jitter value deprication warnigns * Fix ScaleToBounds deprication error * Fix meshgrid deprication warnings
1 parent 04c6c85 commit 452443a

15 files changed

+34
-31
lines changed

.conda/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ requirements:
1616
- python>=3.6
1717

1818
run:
19-
- pytorch>=1.8.1
19+
- pytorch>=1.9
2020
- scikit-learn
2121
- scipy
2222

.github/workflows/unittests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
if [[ ${{ matrix.pytorch-version }} = "master" ]]; then
2929
pip install --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html;
3030
else
31-
pip install torch==1.8.1+cpu -f https://download.pytorch.org/whl/torch_stable.html;
31+
pip install torch==1.9+cpu -f https://download.pytorch.org/whl/torch_stable.html;
3232
fi
3333
if [[ ${{ matrix.pyro }} == "with-pyro" ]]; then
3434
pip install git+https://github.com/pyro-ppl/pyro@master;

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ See our numerous [**examples and tutorials**](https://gpytorch.readthedocs.io/en
1919

2020
**Requirements**:
2121
- Python >= 3.6
22-
- PyTorch >= 1.8.1
22+
- PyTorch >= 1.9
2323

2424
Install GPyTorch using pip or conda:
2525

gpytorch/lazy/block_diag_lazy_tensor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def _cholesky_solve(self, rhs, upper: bool = False):
5252

5353
def _get_indices(self, row_index, col_index, *batch_indices):
5454
# Figure out what block the row/column indices belong to
55-
row_index_block = row_index // self.base_lazy_tensor.size(-2)
56-
col_index_block = col_index // self.base_lazy_tensor.size(-1)
55+
row_index_block = torch.div(row_index, self.base_lazy_tensor.size(-2), rounding_mode="floor")
56+
col_index_block = torch.div(col_index, self.base_lazy_tensor.size(-1), rounding_mode="floor")
5757

5858
# Find the row/col index within each block
5959
row_index = row_index.fmod(self.base_lazy_tensor.size(-2))

gpytorch/lazy/block_interleaved_lazy_tensor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def _get_indices(self, row_index, col_index, *batch_indices):
5353
col_index_block = col_index.fmod(self.base_lazy_tensor.size(-3))
5454

5555
# Find the row/col index within each block
56-
row_index = row_index // self.base_lazy_tensor.size(-3)
57-
col_index = col_index // self.base_lazy_tensor.size(-3)
56+
row_index = torch.div(row_index, self.base_lazy_tensor.size(-3), rounding_mode="floor")
57+
col_index = torch.div(col_index, self.base_lazy_tensor.size(-3), rounding_mode="floor")
5858

5959
# If the row/column blocks do not agree, then we have off diagonal elements
6060
# These elements should be zeroed out

gpytorch/lazy/kronecker_product_lazy_tensor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ def _get_indices(self, row_index, col_index, *batch_indices):
175175
row_factor //= sub_row_size
176176
col_factor //= sub_col_size
177177
sub_res = lazy_tensor._get_indices(
178-
(row_index // row_factor).fmod(sub_row_size),
179-
(col_index // col_factor).fmod(sub_col_size),
178+
torch.div(row_index, row_factor, rounding_mode="floor").fmod(sub_row_size),
179+
torch.div(col_index, col_factor, rounding_mode="floor").fmod(sub_col_size),
180180
*batch_indices,
181181
)
182182
res = sub_res if res is None else (sub_res * res)

gpytorch/models/exact_prediction_strategies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ def covar_cache(self):
676676
torch.eye(train_factor.size(-1), dtype=train_factor.dtype, device=train_factor.device)
677677
- (train_factor.transpose(-1, -2) @ train_train_covar.inv_matmul(train_factor)) * constant
678678
)
679-
return psd_safe_cholesky(inner_term, jitter=settings.cholesky_jitter.value())
679+
return psd_safe_cholesky(inner_term)
680680

681681
def exact_prediction(self, joint_mean, joint_covar):
682682
# Find the components of the distribution that contain test data

gpytorch/test/lazy_tensor_test_case.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class LazyTensorTestCase(RectangularLazyTensorTestCase):
297297
"root_decomposition": {"rtol": 0.05},
298298
"root_inv_decomposition": {"rtol": 0.05, "atol": 0.02},
299299
"sample": {"rtol": 0.3, "atol": 0.3},
300-
"sqrt_inv_matmul": {"rtol": 1e-4, "atol": 1e-3},
300+
"sqrt_inv_matmul": {"rtol": 1e-2, "atol": 1e-3},
301301
"symeig": {"double": {"rtol": 1e-4, "atol": 1e-3}, "float": {"rtol": 1e-3, "atol": 1e-2}},
302302
"svd": {"rtol": 1e-4, "atol": 1e-3},
303303
}
@@ -706,7 +706,7 @@ def test_sqrt_inv_matmul(self):
706706
# Perform forward pass
707707
with gpytorch.settings.max_cg_iterations(200):
708708
sqrt_inv_matmul_res, inv_quad_res = lazy_tensor.sqrt_inv_matmul(rhs, lhs)
709-
evals, evecs = evaluated.symeig(eigenvectors=True)
709+
evals, evecs = torch.linalg.eigh(evaluated)
710710
matrix_inv_root = evecs @ (evals.sqrt().reciprocal().unsqueeze(-1) * evecs.transpose(-1, -2))
711711
sqrt_inv_matmul_actual = lhs_copy @ matrix_inv_root @ rhs_copy
712712
inv_quad_actual = (lhs_copy @ matrix_inv_root).pow(2).sum(dim=-1)
@@ -744,7 +744,7 @@ def test_sqrt_inv_matmul_no_lhs(self):
744744
# Perform forward pass
745745
with gpytorch.settings.max_cg_iterations(200):
746746
sqrt_inv_matmul_res = lazy_tensor.sqrt_inv_matmul(rhs)
747-
evals, evecs = evaluated.symeig(eigenvectors=True)
747+
evals, evecs = torch.linalg.eigh(evaluated)
748748
matrix_inv_root = evecs @ (evals.sqrt().reciprocal().unsqueeze(-1) * evecs.transpose(-1, -2))
749749
sqrt_inv_matmul_actual = matrix_inv_root @ rhs_copy
750750

gpytorch/utils/contour_integral_quad.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def sqrt_precond_matmul(rhs):
7171
)
7272
lanczos_mat = lanczos_mat.squeeze(0) # We have an extra singleton batch dimension from the Lanczos init
7373

74-
"""
74+
r"""
7575
K^{-1/2} b = 2/pi \int_0^\infty (K - t^2 I)^{-1} dt
7676
We'll approximate this integral as a sum using quadrature
7777
We'll determine the appropriate values of t, as well as their weights using elliptical integrals
@@ -81,9 +81,11 @@ def sqrt_precond_matmul(rhs):
8181
# We'll do this with Lanczos
8282
try:
8383
if settings.verbose_linalg.on():
84-
settings.verbose_linalg.logger.debug(f"Running symeig on a matrix of size {lanczos_mat.shape}.")
84+
settings.verbose_linalg.logger.debug(
85+
f"Running torch.linalg.eigvalsh on a matrix of size {lanczos_mat.shape}."
86+
)
8587

86-
approx_eigs = lanczos_mat.symeig()[0]
88+
approx_eigs = torch.linalg.eigvalsh(lanczos_mat)
8789
if approx_eigs.min() <= 0:
8890
raise RuntimeError
8991
except RuntimeError:

gpytorch/utils/linear_cg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ def linear_cg(
292292

293293
# Update tridiagonal matrices, if applicable
294294
if n_tridiag and k < n_tridiag_iter and update_tridiag:
295-
alpha_tridiag = alpha.squeeze_(-2).narrow(-1, 0, n_tridiag)
296-
beta_tridiag = beta.squeeze_(-2).narrow(-1, 0, n_tridiag)
295+
alpha_tridiag = alpha.squeeze(-2).narrow(-1, 0, n_tridiag)
296+
beta_tridiag = beta.squeeze(-2).narrow(-1, 0, n_tridiag)
297297
torch.eq(alpha_tridiag, 0, out=alpha_tridiag_is_zero)
298298
alpha_tridiag.masked_fill_(alpha_tridiag_is_zero, 1)
299299
torch.reciprocal(alpha_tridiag, out=alpha_reciprocal)

0 commit comments

Comments
 (0)