diff --git a/op_acc_stable_run.py b/op_acc_stable_run.py index 4f6d2b9..2546371 100644 --- a/op_acc_stable_run.py +++ b/op_acc_stable_run.py @@ -82,7 +82,7 @@ def convert_framework( inputs = torch.tensor(inputs) inputs = inputs.cuda() if requires_grad: - inputs.requires_grad_(True) + inputs.requires_grad_(False) return inputs raise TypeError(str(type(inputs))) @@ -92,10 +92,10 @@ def check_tensor_aadiff(x, y): assert x.dtype == y.dtype assert x.shape == y.shape - if x.dtype == paddle.bfloat16: + if x.dtype in [paddle.bool, 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): diff --git a/tests/all_test.py b/tests/all_test.py new file mode 100644 index 0000000..69e722c --- /dev/null +++ b/tests/all_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 +import numpy as np + +class AllTest: + def __init__(self, shape): + self.shape = shape + + def set_configs(self, paddle): + self.tmp_cache_path = "." + sample_arr = [True, False] + self.inputs = { + "x": paddle.to_tensor(np.random.choice(sample_arr, size=self.shape)), + } + + def run_paddle(self, paddle): + x = self.inputs["x"] + y = paddle.all(x) + return y + + def run_torch(self, torch): + x = self.inputs["x"] + y = torch.all(x) + return y + + 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(AllTest(shape = [1, 8192]))