8000 Remove deprecated torch.cholesky by IvanYashchuk · Pull Request #70979 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content
10000

Remove deprecated torch.cholesky #70979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1d6b073
Remove deprecated torch.cholesky
IvanYashchuk Jan 7, 2022
4dc3fe1
Merge remote-tracking branch 'upstream/master' into remove-cholesky
IvanYashchuk Mar 11, 2022
df7ff65
Remove aten_interned_strings.h
IvanYashchuk Mar 11, 2022
615fd55
Merge remote-tracking branch 'upstream/master' into remove-cholesky
IvanYashchuk Feb 28, 2023
e9f72ce
Remove cholesky batching rule
IvanYashchuk Feb 28, 2023
967a8a1
Add RuntimeError when calling cholesky
IvanYashchuk Feb 28, 2023
5025b4a
Remove more cholesky mentiones in tests
IvanYashchuk Mar 1, 2023
a79855a
Merge remote-tracking branch 'upstream/viable/strict' into remove-cho…
IvanYashchuk Mar 1, 2023
aebf439
Remove unused import
IvanYashchuk Mar 6, 2023
99eebba
Formatting
IvanYashchuk Mar 6, 2023
ef38d8c
Remove cholesky opinfo mentions
IvanYashchuk Mar 6, 2023
8bfca94
Remove cholesky opinfo mentions
IvanYashchuk Mar 6, 2023
7395938
Remove cholesky opinfo mentions
IvanYashchuk Mar 7, 2023
bb9dba6
Remove cholesky opinfo mentions
IvanYashchuk Mar 7, 2023
ed66ff3
Remove cholesky opinfo mentions
IvanYashchuk Mar 7, 2023
1e60c87
Remove cholesky opinfo mentions
IvanYashchuk Mar 7, 2023
8610212
Add cholesky to overrides ignore list
IvanYashchuk Mar 9, 2023
f0c7eb6
Merge remote-tracking branch 'upstream/viable/strict' into remove-cho…
IvanYashchuk Mar 9, 2023
a9629f2
Merge remote-tracking branch 'upstream/viable/strict' into remove-cho…
IvanYashchuk Apr 5, 2023
5096611
Update xla pin
IvanYashchuk Apr 5, 2023
8a2a3e3
Update xla pin
IvanYashchuk Apr 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ci_commit_pins/xla.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5444e06e5b851211af8a83e024c6703acfc095eb
16d12d400cc3d0c42065c7291acbf03b8e696e89
1 change: 0 additions & 1 deletion aten/src/ATen/autocast_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ TORCH_LIBRARY_IMPL(aten, AutocastCPU, m) {
KERNEL_CPU(grid_sampler_3d, fp32)
KERNEL_CPU(trace, fp32)
KERNEL_CPU(view_as_complex, fp32)
KERNEL_CPU(cholesky, fp32)
KERNEL_CPU(cholesky_inverse, fp32)
KERNEL_CPU(cholesky_solve, fp32)
KERNEL_CPU(inverse, fp32)
Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/functorch/BatchRulesLinearAlgebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ pinv_batch_rule(
}

// These need to be outside. String constant must be declared outside of a macro to be used as template param
LINALG_CHECK_MATRIX_UNARY_ONE_OUT(cholesky, cholesky);
LINALG_CHECK_MATRIX_UNARY_ONE_OUT(cholesky_inverse, cholesky_inverse);
LINALG_CHECK_MATRIX_UNARY_TWO_OUT(linalg_cholesky_ex, linalg.cholesky);
LINALG_CHECK_MATRIX_UNARY_TWO_OUT(linalg_eig, linalg.eig);
Expand Down
58 changes: 0 additions & 58 deletions aten/src/ATen/native/BatchLinearAlgebra.cpp
57AE
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@
#include <ATen/ops/all.h>
#include <ATen/ops/arange.h>
#include <ATen/ops/cat.h>
#include <ATen/ops/cholesky.h>
#include <ATen/ops/cholesky_inverse.h>
#include <ATen/ops/cholesky_inverse_native.h>
#include <ATen/ops/cholesky_native.h>
#include <ATen/ops/cholesky_solve.h>
#include <ATen/ops/cholesky_solve_native.h>
#include <ATen/ops/clone.h>
Expand Down Expand Up @@ -1687,62 +1685,6 @@ Tensor& cholesky_solve_out(const Tensor& self, const Tensor& A, bool upper, Tens

DEFINE_DISPATCH(cholesky_stub);

Tensor cholesky(const Tensor &self, bool upper) {
TORCH_WARN_ONCE(
"torch.cholesky is deprecated in favor of torch.linalg.cholesky and will be ",
"removed in a future PyTorch release.\n",
"L = torch.cholesky(A)\n",
"should be replaced with\n",
"L = torch.linalg.cholesky(A)\n",
"and\n"
"U = torch.cholesky(A, upper=True)\n",
"should be replaced with\n",
"U = torch.linalg.cholesky(A).mH().\n"
"This transform will produce equivalent results for all valid (symmetric positive definite) inputs."
);
if (self.numel() == 0) {
return at::empty_like(self, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
}
squareCheckInputs(self, "cholesky");

auto raw_cholesky_output = cloneBatchedColumnMajor(self);
auto info_shape = IntArrayRef(
self.sizes().cbegin(), self.sizes().cend() - 2); // self.shape[:-2]
auto info = at::empty({info_shape}, self.options().dtype(kInt));

// fill the raw_cholesky_output with the result
cholesky_stub(self.device().type(), raw_cholesky_output, info, upper);

at::_linalg_check_errors(info, "cholesky", self.dim() == 2);

if (upper) {
return raw_cholesky_output.triu_();
} else {
return raw_cholesky_output.tril_();
}
}

Tensor& cholesky_out(const Tensor &self, bool upper, Tensor &result) {
TORCH_WARN_ONCE(
"torch.cholesky is deprecated in favor of torch.linalg.cholesky and will be ",
"removed in a future PyTorch release.\n",
"L = torch.cholesky(A)\n",
"should be replaced with\n",
"L = torch.linalg.cholesky(A)\n",
"and\n"
"U = torch.cholesky(A, upper=True)\n",
"should be replaced with\n",
"U = torch.linalg.cholesky(A).mH().\n"
"This transform will produce equivalent results for all valid (symmetric positive definite) inputs."
);
checkSameDevice("cholesky", result, self);
checkLinalgCompatibleDtype("cholesky", result, self);
Tensor result_tmp = at::cholesky(self, upper);
at::native::resize_output(result, result_tmp.sizes());
result.copy_(result_tmp);
return result;
}

TORCH_IMPL_FUNC(linalg_cholesky_ex_out)(const Tensor& A,
bool upper,
bool check_errors,
Expand Down
9 changes: 0 additions & 9 deletions aten/src/ATen/native/native_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8798,15 +8798,6 @@
device_guard: False
tags: inplace_view

- func: cholesky.out(Tensor self, bool upper=False, *, Tensor(a!) out) -> Tensor(a!)
dispatch:
CPU, CUDA: cholesky_out

- func: cholesky(Tensor self, bool upper=False) -> Tensor
variants: method, function
dispatch:
CPU, CUDA: cholesky

- func: cholesky_solve.out(Tensor self, Tensor input2, bool upper=False, *, Tensor(a!) out) -> Tensor(a!)
dispatch:
CompositeExplicitAutograd: cholesky_solve_out
Expand Down
1 change: 0 additions & 1 deletion docs/source/tensors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ Tensor class reference
Tensor.ceil
Tensor.ceil_
Tensor.char
Tensor.cholesky
Tensor.cholesky_inverse
Tensor.cholesky_solve
Tensor.chunk
Expand Down
1 change: 0 additions & 1 deletion docs/source/torch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,6 @@ BLAS and LAPACK Operations
baddbmm
bmm
chain_matmul
cholesky
cholesky_inverse
cholesky_solve
dot
Expand Down
21 changes: 0 additions & 21 deletions test/cpp/lazy/test_lazy_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,27 +1028,6 @@ TEST_F(LazyOpsTest, TestQR) {
}
}

TEST_F(LazyOpsTest, TestCholesky) {
static const int dims[] = {4, 7};
for (auto m : dims) {
for (bool upper : {true, false}) {
torch::Tensor a = torch::rand(
{3, m, m},
torch::TensorOptions(torch::kFloat).device(DefaultDevice()));
torch::Tensor pd_a =
torch::matmul(a, torch::transpose(a, 1, 2)) +
torch::eye(
m, torch::TensorOptions(torch::kFloat).device(DefaultDevice()));
auto b = torch::cholesky(pd_a, upper);
ForEachDevice([&](const torch::Device& device) {
torch::Tensor lazy_a = CopyToDevice(pd_a, device);
auto lazy_b = torch::cholesky(lazy_a, upper);
AllClose(b, lazy_b, /*rtol=*/1e-3, /*atol=*/1e-4);
});
}
}
}

TEST_F(LazyOpsTest, TestLogDet) {
static const int dims[] = {4, 7};
for (auto m : dims) {
Expand Down
1 change: 0 additions & 1 deletion test/distributed/_tensor/test_dtensor_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def wrapped(fn):
xfail("cauchy"),
xfail("cartesian_prod"),
xfail("cdist"),
xfail("cholesky"),
xfail("cholesky_inverse"),
xfail("cholesky_solve"),
xfail("chunk"),
Expand Down
2 changes: 0 additions & 2 deletions test/expect/HasDecompTest.test_has_decomposition.expect
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,6 @@ aten::ccol_indices_copy
aten::ccol_indices_copy.out
aten::channel_shuffle
aten::channel_shuffle.out
aten::cholesky
aten::cholesky.out
aten::cholesky_inverse
aten::cholesky_inverse.out
aten::cholesky_solve
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
# Internal, profiler-specific ops
("profiler::_call_end_callbacks_on_jit_fut*", datetime.date(9999, 1, 1)),
("profiler::_record_function_enter", datetime.date(9999, 1, 1)),
("aten::cholesky", datetime.date(9999, 1, 1)),
("aten::cholesky.out", datetime.date(9999, 1, 1)),
("aten::_sparse_addmm", datetime.date(2022, 6, 30)),
("aten::kl_div_backward", datetime.date(2022, 9, 1)),
("aten::_cholesky_helper", datetime.date(9999, 1, 1)),
Expand Down
1 change: 0 additions & 1 deletion test/functorch/test_aotdispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2471,7 +2471,6 @@ def forward(self, x):
skip('as_strided', 'partial_views'), # flaky

# Too annoying to generate random inputs
xfail('cholesky'),
xfail('linalg.cholesky'),

# Given input size: (s0xs1x2). Calculated output size: ...
Expand Down
2 changes: 0 additions & 2 deletions test/functorch/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,6 @@ def get_vjp(cotangents, *primals):
# this is not supported. Tensor is of size [5, 2, 3] while the given forward gradient is of size [1, 2, 3].
xfail('normal', ''),
xfail('cdist', ''), # NYI: forward-AD for _cdist_forward
xfail('cholesky', ''), # NYI: forward-AD for cholesky
xfail('logcumsumexp', ''), # NYI: forward-AD for logcumsumexp
xfail('nn.functional.embedding_bag', ''), # NYI: forward-AD for _embedding_bag
xfail('nn.functional.grid_sample', ''), # NYI: forward AD for grid_sampler_2d
Expand Down Expand Up @@ -1482,7 +1481,6 @@ def reference(primals, cotangents, primals_tangents, cotangents_tangents):
xfail('cdouble'), # required rank 4 tensor to use channels_last format
xfail('cfloat'), # required rank 4 tensor to use channels_last format
xfail('chalf'), # required rank 4 tensor to use channels_last format
xfail('cholesky'), # Forward AD not implemented and no decomposition
xfail('ormqr'), # Forward AD not implemented and no decomposition
xfail('double'), # required rank 4 tensor to use channels_last format
xfail('float'), # required rank 4 tensor to use channels_last format
Expand Down
2 changes: 0 additions & 2 deletions test/inductor/test_torchinductor_opinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ def process(device_type):
"bernoulli": {f32, f64},
"bincount": {i32, i64},
"bucketize": {b8, f16, f32, f64, i32, i64},
"cholesky": {f32, f64},
"combinations": {b8, f16, f32, f64, i32, i64},
"corrcoef": {f32, f64, i32, i64},
"cov": {f32, f64, i32, i64},
Expand Down Expand Up @@ -260,7 +259,6 @@ def process(device_type):
"bernoulli": {f16, f32, f64},
"bincount": {i32, i64},
"bucketize": {b8, f16, f32, f64, i32, i64},
"cholesky": {f32, f64},
"combinations": {b8, f16, f32, f64, i32, i64},
"corrcoef": {f16, f32, f64, i32, i64},
"cov": {f16, f32, f64, i32, i64},
Expand Down
106 changes: 8 additions & 98 deletions test/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ def run_test_case(a, b):
run_test_case(zero_strided, b)
run_test_case(a, zero_strided)

def test_cholesky_removed_error(self, device):
a = make_tensor(5, 5, device=device, dtype=torch.float32)
with self.assertRaisesRegex(RuntimeError, "This function was deprecated since version 1.9 and is now removed"):
torch.cholesky(a)
with self.assertRaisesRegex(RuntimeError, "This function was deprecated since version 1.9 and is now removed"):
a.cholesky()

def test_matrix_rank_removed_error(self, device):
a = make_tensor(5, 5, device=device, dtype=torch.float32)
with self.assertRaisesRegex(RuntimeError, "This function was deprecated since version 1.9 and is now removed"):
Expand Down Expand Up @@ -568,103 +575,6 @@ def test_cholesky_errors_and_warnings(self, device, dtype):
with self.assertRaisesRegex(RuntimeError, "Expected all tensors to be on the same device"):
torch.linalg.cholesky(A, out=out)

# NOTE: old_cholesky* tests were moved here from test_torch.py and test_autograd.py
@slowTest
@skipCUDAIfNoMagma
@skipCPUIfNoLapack
@dtypes(torch.double)
def test_old_cholesky_batched_many_batches(self, device, dtype):
from torch.testing._internal.common_utils import random_symmetric_pd_matrix

def cholesky_test_helper(n, batchsize, device, upper):
A = random_symmetric_pd_matrix(n, batchsize, dtype=dtype, device=device)
chol_fact = torch.cholesky(A, upper=upper)
if upper:
# Correctness check
self.assertEqual(A, chol_fact.mT.matmul(chol_fact))
# Upper triangular check
self.assertEqual(chol_fact, chol_fact.triu())
else:
# Correctness check
self.assertEqual(A, chol_fact.matmul(chol_fact.mT))
# Lower triangular check
self.assertEqual(chol_fact, chol_fact.tril())

for upper, batchsize in itertools.product([True, False], [262144, 524288]):
cholesky_test_helper(2, batchsize, device, upper)

@precisionOverride({torch.float32: 1e-4, torch.complex64: 1e-4})
@skipCUDAIfNoMagma
@skipCPUIfNoLapack
@dtypes(*floating_and_complex_types())
def test_old_cholesky_batched(self, device, dtype):
from torch.testing._internal.common_utils import random_hermitian_pd_matrix

def cholesky_test_helper(n, batch_dims, upper):
A = random_hermitian_pd_matrix(n, *batch_dims, dtype=dtype, device=device)
cholesky_exp = torch.stack([m.cholesky(upper=upper) for m in A.reshape(-1, n, n)])
cholesky_exp = cholesky_exp.reshape_as(A)
self.assertEqual(cholesky_exp, torch.cholesky(A, upper=upper))

for upper, batchsize in itertools.product([True, False], [(3,), (3, 4), (2, 3, 4)]):
cholesky_test_helper(3, batchsize, upper)

@precisionOverride({torch.float32: 1e-4, torch.complex64: 1e-4})
@skipCUDAIfNoMagma
@skipCPUIfNoLapack
@dtypes(*floating_and_complex_types())
@tf32_on_and_off(0.01)
def test_old_cholesky(self, device, dtype):
from torch.testing._internal.common_utils import random_hermitian_pd_matrix

A = random_hermitian_pd_matrix(10, dtype=dtype, device=device)

# default Case
C = torch.cholesky(A)
B = torch.mm(C, C.t().conj())
self.assertEqual(A, B, atol=1e-14, rtol=0)

# test Upper Triangular
U = torch.cholesky(A, True)
B = torch.mm(U.t().conj(), U)
self.assertEqual(A, B, atol=1e-14, rtol=0, msg='cholesky (upper) did not allow rebuilding the original matrix')

# test Lower Triangular
L = torch.cholesky(A, False)
B = torch.mm(L, L.t().conj())
self.assertEqual(A, B, atol=1e-14, rtol=0, msg='cholesky (lower) did not allow rebuilding the original matrix')

@skipCUDAIfNoMagma
@skipCPUIfNoLapack
@dtypes(*floating_and_complex_types())
def test_old_cholesky_empty(self, device, dtype):
def run_test(upper):
A = torch.empty(0, 0, dtype=dtype, device=device)
chol = torch.cholesky(A, upper)
chol_A = torch.matmul(chol, chol.t().conj())
self.assertEqual(A, chol_A)
for upper in [True, False]:
run_test(upper)

# Test for issue
# https://github.com/pytorch/pytorch/issues/57032
# torch.cholesky with upper=True for batched CUDA inputs was wrong
# it was using the lower triangular part instead of the upper one
@onlyCUDA
@skipCUDAIfNoMagma
@dtypes(*floating_and_complex_types())
def test_old_cholesky_batched_upper(self, device, dtype):
from torch.testing._internal.common_utils import random_hermitian_pd_matrix

batchsize = 2
A = random_hermitian_pd_matrix(3, batchsize, dtype=dtype, device=device)
A_triu = A.triu() # fill the lower triangular part with zero

U = torch.cholesky(A_triu, upper=True)

reconstruct_A = U.mH @ U
self.assertEqual(A, reconstruct_A)

@skipCUDAIfNoMagmaAndNoCusolver
@skipCPUIfNoLapack
@dtypes(*floating_and_complex_types())
Expand Down Expand Up @@ -2501,7 +2411,7 @@ def cholesky_solve_test_helper(self, A_dims, b_dims, upper, device, dtype):

b = torch.randn(*b_dims, dtype=dtype, device=device)
A = random_hermitian_pd_matrix(*A_dims, dtype=dtype, device=device)
L = torch.cholesky(A, upper=upper)
L = torch.linalg.cholesky(A, upper=upper)
return b, A, L

@skipCUDAIfNoMagma
Expand Down
3 changes: 0 additions & 3 deletions test/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,6 @@ def run_meta_crossref(
torch.polar : {f64, f32},
torch._segment_reduce : {f64, f16, bf16, f32},
torch.searchsorted : {f64, i32, i64, f16, u8, i16, bf16, i8, f32},
torch.cholesky : {f64, f32, c128, c64},
torch.cholesky_inverse : {f64, f32, c128, c64},
torch.cholesky_solve : {f64, f32, c128, c64},
torch.linalg.eig : {f64, f32, c128, c64},
Expand Down Expand Up @@ -822,8 +821,6 @@ def __torch_function__(self, func, types, args=(), kwargs=None):
# these always fail
meta_dispatch_expected_failures = {
aten.allclose.default: {f16, bf16, f32, f64, c64, c128}, # NotImplementedError: 'aten::_local_scalar_dense'
aten.cholesky.default : {c64, c128, f64, f32},
aten.cholesky.out : {c64, c128, f64, f32},
aten.cholesky_inverse.default : {c64, c128, f64, f32},
aten.cholesky_inverse.out : {c64, c128, f64, f32},
aten.cholesky_solve.default : {c64, c128, f64, f32},
Expand Down
2 changes: 0 additions & 2 deletions test/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1882,7 +1882,6 @@ def test_refs_are_in_decomp_table(self, op):

fake_skips = (
"aminmax", # failing input
"cholesky", # Could not run 'aten::cholesky' with arguments from the 'Meta' backend
"cholesky_inverse", # Could not run 'aten::cholesky' with arguments from the 'Meta' backend
"cov", # aweights cannot be negtaive
"istft", # window overlap add min: 0
Expand Down Expand Up @@ -1987,7 +1986,6 @@ def test_refs_are_in_decomp_table(self, op):
"roll",
"svd_lowrank",
"sgn",
"cholesky",
}

fake_backward_xfails = {xfail(stride_skip) for stride_skip in fake_backward_xfails} | {
Expand Down
1 change: 0 additions & 1 deletion test/test_proxy_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,6 @@ def f(a, b, c, d, e):
# FakeTensor fallback doesn't work
xfail('_segment_reduce', 'lengths'),
xfail('multinomial'),
xfail('cholesky'),
xfail('cholesky_inverse'),
# cannot do these as they rely on tensor data
xfail('repeat_interleave'),
Expand Down
3 changes: 0 additions & 3 deletions tools/autograd/derivatives.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,6 @@
self: zeros_like(grad)
result: auto_element_wise

- name: cholesky(Tensor self, bool upper=False) -> Tensor
self: cholesky_backward(grad, upper, result)

- name: linalg_cholesky_ex(Tensor self, *, bool upper=False, bool check_errors=False) -> (Tensor L, Tensor info)
self: cholesky_backward(grad, upper, L)
L: cholesky_jvp(self_t, L, upper)
Expand Down
Loading
0