From b6ca73331a61d60b6724f539c8dfc7c5242831de Mon Sep 17 00:00:00 2001 From: yangxiaoyu14 Date: Tue, 28 Nov 2023 08:08:39 +0000 Subject: [PATCH 1/3] softmax_test --- op_acc_stable_run.py | 5 +++-- tests/softmax_test.py | 13 +++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/op_acc_stable_run.py b/op_acc_stable_run.py index 4f6d2b9..179daa2 100644 --- a/op_acc_stable_run.py +++ b/op_acc_stable_run.py @@ -1,3 +1,4 @@ + # Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -95,7 +96,7 @@ def check_tensor_aadiff(x, y): if x.dtype == paddle.bfloat16: x = x.astype(paddle.float32) y = y.astype(paddle.float32) - assert paddle.max(paddle.abs(x - y)).numpy()[0] == 0, "aadiff check failed" + assert paddle.max(paddle.abs(x - y)).numpy() == 0, "aadiff check failed" def check_aadiff(x, y): @@ -227,4 +228,4 @@ def check_tensor_diff(x, y, *, atol, rtol, err_msg=""): y = y.astype(paddle.float32) x = x.numpy() y = y.numpy() - np.testing.assert_allclose(x, y, atol=atol, rtol=rtol, err_msg=err_msg) + np.testing.assert_allclose(x, y, atol=atol, rtol=rtol, err_msg=err_msg) \ No newline at end of file diff --git a/tests/softmax_test.py b/tests/softmax_test.py index 3da9663..baaa5be 100644 --- a/tests/softmax_test.py +++ b/tests/softmax_test.py @@ -15,12 +15,14 @@ from op_acc_stable_run import check_tensor_diff, op_acc_stable_run - class SoftmaxTest: + def __init__(self, shape, axis, dtype): + self.shape = shape + self.axis = axis + self.dtype = dtype + def set_configs(self, paddle): - self.shape = [4096, 128] - self.dtype = "float32" - self.axis = -1 + self.tmp_cache_path = "." self.inputs = { "x": paddle.randn(self.shape, dtype=self.dtype), "y_grad": paddle.randn(self.shape, dtype=self.dtype), @@ -43,6 +45,5 @@ def check_diff(self, paddle, pd_ret, th_ret): for pd, th in zip(pd_ret, th_ret): check_tensor_diff(pd, th, atol=1e-6, rtol=1e-6) - if __name__ == "__main__": - op_acc_stable_run(SoftmaxTest) + op_acc_stable_run(SoftmaxTest(shape = [1, 1024, 254208], axis=-1, dtype ='float32')) From 5e73c9e05e9147305102d3b76c8c2138f2e3739f Mon Sep 17 00:00:00 2001 From: yangxiaoyu14 Date: Wed, 29 Nov 2023 11:11:03 +0000 Subject: [PATCH 2/3] clip_test --- op_acc_stable_run.py | 3 +-- tests/clip_test.py | 45 +++++++++++++++++++++++++++++++++++++++++++ tests/softmax_test.py | 13 ++++++------- 3 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 tests/clip_test.py diff --git a/op_acc_stable_run.py b/op_acc_stable_run.py index 179daa2..bbe3aaa 100644 --- a/op_acc_stable_run.py +++ b/op_acc_stable_run.py @@ -1,4 +1,3 @@ - # Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -96,7 +95,7 @@ def check_tensor_aadiff(x, y): if x.dtype == paddle.bfloat16: x = x.astype(paddle.float32) y = y.astype(paddle.float32) - assert paddle.max(paddle.abs(x - y)).numpy() == 0, "aadiff check failed" + assert paddle.max(paddle.abs(x - y)).numpy()[0] == 0, "aadiff check failed" def check_aadiff(x, y): diff --git a/tests/clip_test.py b/tests/clip_test.py new file mode 100644 index 0000000..51b87be --- /dev/null +++ b/tests/clip_test.py @@ -0,0 +1,45 @@ +# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from op_acc_stable_run import check_tensor_diff, op_acc_stable_run + +class ClipTest: + def __init__(self, x_shape, dtype): + self.x_shape = x_shape + self.dtype = dtype + + def set_configs(self, paddle): + self.tmp_cache_path = "." + self.inputs = { + "x": paddle.randn(self.x_shape, dtype=self.dtype) , + } + + def run_paddle(self, paddle): + x = self.inputs["x"] + y = paddle.clip(x, min=-0.1, max=-0.1) + return y + + def run_torch(self, torch): + x = self.inputs["x"] + y = torch.clip(x, min=-0.1, max=-0.1) + return y + + def check_diff(self, paddle, pd_ret, th_ret): + assert len(pd_ret) == len(th_ret) + for pd, th in zip(pd_ret, th_ret): + check_tensor_diff(pd, th, atol=1e-6, rtol=1e-6) + +if __name__ == "__main__": + op_acc_stable_run(ClipTest(x_shape = [1, 8192], dtype ='float32')) diff --git a/tests/softmax_test.py b/tests/softmax_test.py index baaa5be..6728cca 100644 --- a/tests/softmax_test.py +++ b/tests/softmax_test.py @@ -15,14 +15,12 @@ from op_acc_stable_run import check_tensor_diff, op_acc_stable_run -class SoftmaxTest: - def __init__(self, shape, axis, dtype): - self.shape = shape - self.axis = axis - self.dtype = dtype +class SoftmaxTest: def set_configs(self, paddle): - self.tmp_cache_path = "." + self.shape = [4096, 128] + self.dtype = "float32" + self.axis = -1 self.inputs = { "x": paddle.randn(self.shape, dtype=self.dtype), "y_grad": paddle.randn(self.shape, dtype=self.dtype), @@ -45,5 +43,6 @@ def check_diff(self, paddle, pd_ret, th_ret): for pd, th in zip(pd_ret, th_ret): check_tensor_diff(pd, th, atol=1e-6, rtol=1e-6) + if __name__ == "__main__": - op_acc_stable_run(SoftmaxTest(shape = [1, 1024, 254208], axis=-1, dtype ='float32')) + op_acc_stable_run(SoftmaxTest) \ No newline at end of file From 3da00552f67bcbb80cb48618425ad22a9b64fb23 Mon Sep 17 00:00:00 2001 From: yangxiaoyu14 Date: Wed, 29 Nov 2023 11:12:50 +0000 Subject: [PATCH 3/3] clip_test --- tests/clip_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/clip_test.py b/tests/clip_test.py index 51b87be..8bcfda6 100644 --- a/tests/clip_test.py +++ b/tests/clip_test.py @@ -28,12 +28,12 @@ def set_configs(self, paddle): def run_paddle(self, paddle): x = self.inputs["x"] - y = paddle.clip(x, min=-0.1, max=-0.1) + y = paddle.clip(x, min=-0.1, max=0.1) return y def run_torch(self, torch): x = self.inputs["x"] - y = torch.clip(x, min=-0.1, max=-0.1) + y = torch.clip(x, min=-0.1, max=0.1) return y def check_diff(self, paddle, pd_ret, th_ret):