From b6ca73331a61d60b6724f539c8dfc7c5242831de Mon Sep 17 00:00:00 2001 From: yangxiaoyu14 Date: Tue, 28 Nov 2023 08:08:39 +0000 Subject: [PATCH] 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'))