diff --git a/test/cinn/test_computation.py b/test/cinn/test_computation.py index 43fc04033115d109cb1fdf9eec8507cb47944782..945ad417e2ba6960f522aa3e7f0cc0b8d07fbecf 100755 --- a/test/cinn/test_computation.py +++ b/test/cinn/test_computation.py @@ -92,7 +92,7 @@ class TestNetBuilder(unittest.TestCase): edata_paddle = self.get_paddle_result([A_data, B_data, D_data]) - self.assertTrue(np.allclose(edata_cinn, edata_paddle, atol=1e-5)) + np.testing.assert_allclose(edata_cinn, edata_paddle, atol=1e-5) class TestCompilePaddleModel(unittest.TestCase): @@ -125,7 +125,7 @@ class TestCompilePaddleModel(unittest.TestCase): paddle_out = paddle_predictor.run([data]) res_paddle = paddle_out[0].as_ndarray() - self.assertTrue(np.allclose(res_cinn, res_paddle, atol=1e-5)) + np.testing.assert_allclose(res_cinn, res_paddle, atol=1e-5) if __name__ == "__main__": diff --git a/test/cinn/test_efficientnet.py b/test/cinn/test_efficientnet.py index 29dc601d7157d1858b4f436ee9def81793beb038..e7e0c4ffb063df97399c4f7d31076bc5baa8e16b 100755 --- a/test/cinn/test_efficientnet.py +++ b/test/cinn/test_efficientnet.py @@ -105,7 +105,7 @@ class TestLoadEfficientNetModel(unittest.TestCase): ". Diff is: ", out[i] - target_result[i], ) - self.assertTrue(np.allclose(out, target_result, atol=1e-3)) + np.testing.assert_allclose(out, target_result, atol=1e-3) def test_model(self): self.apply_test() diff --git a/test/cinn/test_facedet.py b/test/cinn/test_facedet.py index 2a25084c277ddd1f41e6ceb2f083d39560c60336..0afef60b003ef2cfc2acd1296a8704d4985d4d5e 100755 --- a/test/cinn/test_facedet.py +++ b/test/cinn/test_facedet.py @@ -109,7 +109,7 @@ class TestLoadFaceDetModel(unittest.TestCase): ". Diff is: ", out[i] - target_result[i], ) - self.assertTrue(np.allclose(out, target_result, atol=1e-3)) + np.testing.assert_allclose(out, target_result, atol=1e-3) def test_model(self): self.apply_test() diff --git a/test/cinn/test_frontend.py b/test/cinn/test_frontend.py index 7470fc348ead0cd2dfc974e8a989866a50b1fab3..257da984708a3dff58671e904da38e304ae86338 100755 --- a/test/cinn/test_frontend.py +++ b/test/cinn/test_frontend.py @@ -147,7 +147,7 @@ class TestLoadPaddleModel_FC(unittest.TestCase): out_np = out.numpy(self.target) print("cinn data's shape is: ", out_np.shape) - self.assertTrue(np.allclose(out_np, target_data, atol=1e-4)) + np.testing.assert_allclose(out_np, target_data, atol=1e-4) class TestLoadPaddleModel_MultiFC(unittest.TestCase): @@ -184,7 +184,7 @@ class TestLoadPaddleModel_MultiFC(unittest.TestCase): out = self.executor.get_tensor("fc_5.tmp_2") target = self.get_paddle_inference_result(self.model_dir, x_data) - self.assertTrue(np.allclose(out.numpy(self.target), target, atol=1e-4)) + np.testing.assert_allclose(out.numpy(self.target), target, atol=1e-4) if __name__ == "__main__": diff --git a/test/cinn/test_hlir_framework.py b/test/cinn/test_hlir_framework.py index cb200802eae3a0038c9c8ee47264a0d5b2dacfc1..1e7d36cacac50dff98555d3682767af5afd12c7e 100644 --- a/test/cinn/test_hlir_framework.py +++ b/test/cinn/test_hlir_framework.py @@ -28,7 +28,7 @@ class TensorTest(unittest.TestCase): data = np.random.random([10, 5]) tensor.from_numpy(data, target) - self.assertTrue(np.allclose(tensor.numpy(), data)) + np.testing.assert_allclose(tensor.numpy(), data) if __name__ == "__main__": diff --git a/test/cinn/test_matmul.py b/test/cinn/test_matmul.py index da96434ed002e41bc474bfc0983f31ad5fc59ef3..8deac2bb701afe6aa615e824907d2f4462f1e89e 100755 --- a/test/cinn/test_matmul.py +++ b/test/cinn/test_matmul.py @@ -47,7 +47,7 @@ class TestMamul(unittest.TestCase): matmul(args) cd = c.numpy() cd_target = c_target.numpy() - self.assertTrue(np.allclose(cd, cd_target, atol=1e-4)) + np.testing.assert_allclose(cd, cd_target, atol=1e-4, rtol=1e-5) print(utils.HostEventRecorder.table()) def test_matmul_tile(self): @@ -59,7 +59,7 @@ class TestMamul(unittest.TestCase): matmul(args) cd = c.numpy() cd_target = c_target.numpy() - self.assertTrue(np.allclose(cd, cd_target, atol=1e-4)) + np.testing.assert_allclose(cd, cd_target, atol=1e-4, rtol=1e-5) def create_matmul_basic(target, m, n, k): diff --git a/test/cinn/test_mobilenetv1.py b/test/cinn/test_mobilenetv1.py index 4058df24b7fa2f7b26f68b81a385d95f4da23112..e6cf251bd19eabb432f95aed29c9e57fec7c8249 100644 --- a/test/cinn/test_mobilenetv1.py +++ b/test/cinn/test_mobilenetv1.py @@ -108,7 +108,7 @@ class TestLoadMobilenetV1Model(unittest.TestCase): out[i] - target_result[i], ) # TODO(thisjiang): revert atol to 1e-3 after fix inference mul problem - self.assertTrue(np.allclose(out, target_result, atol=1e-1)) + np.testing.assert_allclose(out, target_result, atol=1e-1) def test_model(self): self.apply_test() diff --git a/test/cinn/test_mobilenetv2.py b/test/cinn/test_mobilenetv2.py index f96c333a8a0c2c12685e686082b1ef1360082dbc..6ca646823ea58aaca016d7020c22f26d4b0cb19a 100755 --- a/test/cinn/test_mobilenetv2.py +++ b/test/cinn/test_mobilenetv2.py @@ -110,7 +110,7 @@ class TestLoadResnetModel(unittest.TestCase): out[i] - target_result[i], ) # TODO(thisjiang): revert atol to 1e-3 after fix inference mul problem - self.assertTrue(np.allclose(out, target_result, atol=1e-1)) + np.testing.assert_allclose(out, target_result, atol=1e-1) def test_model(self): self.apply_test() diff --git a/test/cinn/test_netbuilder.py b/test/cinn/test_netbuilder.py index 526b325bf24a13137cabe17ec9b0306d96c30e72..8e1787824ac0cafbf56c2c31a65904c8dfe76db0 100755 --- a/test/cinn/test_netbuilder.py +++ b/test/cinn/test_netbuilder.py @@ -76,7 +76,7 @@ class TestNetBuilder(unittest.TestCase): ". Diff is: ", output[i] - result[len(result) - 1][i], ) - self.assertTrue(np.allclose(result[len(result) - 1], output, atol=1e-4)) + np.testing.assert_allclose(result[len(result) - 1], output, atol=1e-4) def test_basic(self): builder = NetBuilder("test_basic") diff --git a/test/cinn/test_op_benchmark.py b/test/cinn/test_op_benchmark.py index ce63e4e4f69e0733ecd5910ff73ac3bf3c69187e..119ca6af153ad90d59853f2cbb7317e45af385a5 100755 --- a/test/cinn/test_op_benchmark.py +++ b/test/cinn/test_op_benchmark.py @@ -74,7 +74,7 @@ class TestBenchmark(unittest.TestCase): ". Diff is: ", output[i] - result[len(result) - 1][i], ) - self.assertTrue(np.allclose(result[len(result) - 1], output, atol=1e-4)) + np.testing.assert_allclose(result[len(result) - 1], output, atol=1e-4) def atest_conv2d_cinn(self): prog = Program() @@ -414,10 +414,8 @@ typedef char int8_t; "TESTING [elementwise_add] time cost with shape [64, 64]...", ) result = result.numpy(self.target).reshape(-1) - self.assertTrue( - np.allclose( - (tensor_data[0] + tensor_data[1]).reshape(-1), result, atol=1e-4 - ) + np.testing.assert_allclose( + (tensor_data[0] + tensor_data[1]).reshape(-1), result, atol=1e-4 ) def atest_elementwise2(self): @@ -438,10 +436,8 @@ typedef char int8_t; "TESTING [elementwise_add] time cost with shape [2, 512, 112, 112]...", ) result = result.numpy(self.target).reshape(-1) - self.assertTrue( - np.allclose( - (tensor_data[0] + tensor_data[1]).reshape(-1), result, atol=1e-4 - ) + np.testing.assert_allclose( + (tensor_data[0] + tensor_data[1]).reshape(-1), result, atol=1e-4 ) def atest_elementwise2(self): diff --git a/test/cinn/test_pe_reduction.py b/test/cinn/test_pe_reduction.py index d8d4a8b6f0135ca2284c0212acd78cd4ad90cd4e..946983496884d45aa54b248648cd7978497ddffc 100644 --- a/test/cinn/test_pe_reduction.py +++ b/test/cinn/test_pe_reduction.py @@ -125,12 +125,10 @@ class TestPEReduction(unittest.TestCase): x_data, x_buf, out_buf, *args = self.create_data(axes, keep_dims) fn(args) - self.assertTrue( - np.allclose( - out_buf.numpy(), - self.create_target_data(x_data, np_fn, axes, keep_dims), - atol=1e-4, - ) + np.testing.assert_allclose( + out_buf.numpy(), + self.create_target_data(x_data, np_fn, axes, keep_dims), + atol=1e-4, ) def create_target_data(self, x_data, np_target_fn, axes, keep_dims): diff --git a/test/cinn/test_pe_transform.py b/test/cinn/test_pe_transform.py index bc78bc66ddec33bd0574d5d58258d78ab7605afc..becf4aa02e25baf45bf216fff9bfc51d0393b6d7 100644 --- a/test/cinn/test_pe_transform.py +++ b/test/cinn/test_pe_transform.py @@ -87,14 +87,12 @@ class TestPETransform(unittest.TestCase): ) fn(args) - self.assertTrue( - np.allclose( - out_buf.numpy(), - self.create_target_data( - np_fn, x_data, y_data, trans_a, trans_b, alpha - ), - atol=1e-4, - ) + np.testing.assert_allclose( + out_buf.numpy(), + self.create_target_data( + np_fn, x_data, y_data, trans_a, trans_b, alpha + ), + atol=1e-4, ) def create_target_data( diff --git a/test/cinn/test_resnet.py b/test/cinn/test_resnet.py index 69c3d256cc9297e3d126e6ef0d5b1c2fe36ecd27..3b9b7f1b88e81c76f9f50eeba800003ea4e4cf5a 100755 --- a/test/cinn/test_resnet.py +++ b/test/cinn/test_resnet.py @@ -83,7 +83,7 @@ class TestLoadResnetModel(unittest.TestCase): ". Diff is: ", out[i] - target_result[i], ) - self.assertTrue(np.allclose(out, target_result, atol=1e-3)) + np.testing.assert_allclose(out, target_result, atol=1e-3) def test_model(self): self.apply_test() diff --git a/test/cinn/test_resnet18.py b/test/cinn/test_resnet18.py index 2d9b227ab55ecfb7294d72bbebbe368640662c9e..9bb0c210a32d5a5baf2c3ec2bf92dd762579ffcb 100755 --- a/test/cinn/test_resnet18.py +++ b/test/cinn/test_resnet18.py @@ -110,7 +110,7 @@ class TestLoadResnetModel(unittest.TestCase): out[i] - target_result[i], ) # TODO(thisjiang): revert atol to 1e-3 after fix inference mul problem - self.assertTrue(np.allclose(out, target_result, atol=1.0)) + np.testing.assert_allclose(out, target_result, atol=1.0) def test_model(self): self.apply_test() diff --git a/test/cinn/test_resnet50.py b/test/cinn/test_resnet50.py index 9ecf60c22ebe59514eef8bf82473fefc5fd707be..554553d62d6f02e7a5560a764a9e8ceffb466a4c 100755 --- a/test/cinn/test_resnet50.py +++ b/test/cinn/test_resnet50.py @@ -113,7 +113,7 @@ class TestLoadResnet50Model(unittest.TestCase): ". Diff is: ", out[i] - target_result[i], ) - self.assertTrue(np.allclose(out, target_result, atol=1e-3)) + np.testing.assert_allclose(out, target_result, atol=1e-3) def test_model(self): self.apply_test() diff --git a/test/cinn/test_squeezenet.py b/test/cinn/test_squeezenet.py index 65a6576915fc3f0e83568093090aea2e50f729cb..3983716036f96fb8fa13ce376e7a16e5a3954b4b 100644 --- a/test/cinn/test_squeezenet.py +++ b/test/cinn/test_squeezenet.py @@ -107,7 +107,7 @@ class TestLoadSqueezeNetModel(unittest.TestCase): ". Diff is: ", out[i] - target_result[i], ) - self.assertTrue(np.allclose(out, target_result, atol=1e-3)) + np.testing.assert_allclose(out, target_result, atol=1e-3) def test_model(self): self.apply_test() diff --git a/test/cinn/test_utils.py b/test/cinn/test_utils.py index f97caaab28862a418560e037bb01d296d28617df..ec29b28f9a1f3da9283c855ee0f17c6a5064c6fe 100755 --- a/test/cinn/test_utils.py +++ b/test/cinn/test_utils.py @@ -144,7 +144,7 @@ class SingleOpTester(unittest.TestCase): out_result = out[len(out) - 1].numpy() if out_index != None: out_result = out[out_index].numpy() - self.assertTrue(np.allclose(out_result, correct_result, atol=1e-4)) + np.testing.assert_allclose(out_result, correct_result, atol=1e-4) def __lower(self, op_name, inputs, output_shapes, attrs): types = [common.Float(32)]