prepare removal of deprecated functionality in torch.testing (#87969)
_Redo of #86586 with all BC breaking changes granularly placed into separate commits._
---
Per title. Deprecation happened on Feb 25, 2022 in c6f1bbc0ac33be0c8ad9956e3fc15e78ddb6cb95, which made it into the 1.12 release. Since it is now 245 days later and the next release will be 1.14, the removals later in the stack comply with the [BC policy](https://github.com/pytorch/pytorch/wiki/PyTorch's-Python-Frontend-Backward-and-Forward-Compatibility-Policy#minimizing-the-disruption-of-bc-breaking-changes).
Pull Request resolved: https://github.com/pytorch/pytorch/pull/87969
Approved by: https://github.com/mruberry
diff --git a/test/test_mps.py b/test/test_mps.py
index c89a9d2..03410e2 100644
--- a/test/test_mps.py
+++ b/test/test_mps.py
@@ -65,7 +65,7 @@
return np.maximum(np_features, np.zeros(np_features.shape)).astype(np_features.dtype)
def testNpRelu(self):
- torch.testing.assert_allclose(
+ torch.testing.assert_close(
np.array([[0., 0.7, 0.0, 0.3, 0.0], [0.1, 0.0, 0.5, 0.0, 0.9]]),
self._npRelu(
np.array([[-0.9, 0.7, -0.5, 0.3, -0.1], [0.1, -0.3, 0.5, -0.7,
@@ -79,7 +79,7 @@
py_relu = torch.nn.ReLU(inplace=False)(py_tensor)
py_relu_cpu = py_relu.to("cpu")
- torch.testing.assert_allclose(np_relu, py_relu_cpu)
+ self.assertEqual(np_relu, py_relu_cpu)
def _testReluInPlace(self, np_features, device):
np_relu = self._npRelu(np_features)
@@ -89,9 +89,9 @@
py_relu = torch.nn.ReLU(inplace=True)(py_tensor)
py_relu_cpu = py_relu.to("cpu")
- torch.testing.assert_allclose(np_relu, py_relu_cpu)
+ self.assertEqual(np_relu, py_relu_cpu)
# Inplace Relu modifies the initial input and it should match the output of Relu
- torch.testing.assert_allclose(np_relu, py_tensor.to("cpu"))
+ self.assertEqual(np_relu, py_tensor.to("cpu"))
def testNumbersCPU(self):
for t in [np.int32]:
@@ -156,7 +156,7 @@
return np.maximum(np_features, negative_slope * np_features).astype(np_features.dtype)
def testNpLeakyRelu(self):
- torch.testing.assert_allclose(
+ torch.testing.assert_close(
np.array([[-0.09, 0.7, -0.05, 0.3, -0.01],
[0.1, -0.03, 0.5, -0.07, 0.9]]),
self._npLeakyRelu(
@@ -171,14 +171,14 @@
cpu_leaky_relu = relu_op(cpu_x)
mps_leaky_relu = relu_op(mps_x)
- torch.testing.assert_allclose(cpu_leaky_relu, mps_leaky_relu.to('cpu'))
+ torch.testing.assert_close(cpu_leaky_relu, mps_leaky_relu.to('cpu'))
# test backward pass
cpu_grad = torch.ones_like(cpu_leaky_relu)
mps_grad = cpu_grad.to('mps')
cpu_leaky_relu.backward(gradient=cpu_grad)
mps_leaky_relu.backward(gradient=mps_grad)
- torch.testing.assert_allclose(cpu_x.grad, mps_x.grad.to('cpu'))
+ torch.testing.assert_close(cpu_x.grad, mps_x.grad.to('cpu'))
def testNumbersCPU(self):
for t in [np.float32]:
@@ -257,14 +257,14 @@
cpu_leaky_relu = relu_op(cpu_x)
mps_leaky_relu = relu_op(mps_x)
- torch.testing.assert_allclose(cpu_leaky_relu, mps_leaky_relu.to('cpu'))
+ torch.testing.assert_close(cpu_leaky_relu, mps_leaky_relu.to('cpu'))
# test backward pass
cpu_grad = torch.ones_like(cpu_leaky_relu)
mps_grad = cpu_grad.to('mps')
cpu_leaky_relu.backward(gradient=cpu_grad)
mps_leaky_relu.backward(gradient=mps_grad)
- torch.testing.assert_allclose(cpu_x.grad, mps_x.grad.to('cpu'))
+ torch.testing.assert_close(cpu_x.grad, mps_x.grad.to('cpu'))
def testNumbersGPU(self):
for t in [np.float32]:
@@ -293,14 +293,14 @@
B = torch.ones(5, 6).to("mps")
C = torch.ones(6, 5).to("mps")
D = torch.mm(B, C).cpu()
- torch.testing.assert_allclose(D, torch.full((5, 5), 6.0))
+ torch.testing.assert_close(D, torch.full((5, 5), 6.0))
def test_addmm(self):
A = torch.ones(5, 5).to("mps")
B = torch.ones(5, 6).to("mps")
C = torch.ones(6, 5).to("mps")
D = torch.addmm(A, B, C).to("cpu")
- torch.testing.assert_allclose(D, torch.full((5, 5), 7.0))
+ torch.testing.assert_close(D, torch.full((5, 5), 7.0))
def test_bmm(self):
batch1_cpu = torch.randn(10, 3, 4)
@@ -355,7 +355,7 @@
def test_local_scalar_dense_mps(self):
x_cpu = torch.randn(1)
y_mps = x_cpu.to("mps")
- torch.testing.assert_allclose(x_cpu.item(), y_mps.item())
+ torch.testing.assert_close(x_cpu.item(), y_mps.item())
def test_linear_1d_weight(self):
device = 'cpu'