From f459dd96342ede227c810081c9b4fff4abe805db Mon Sep 17 00:00:00 2001 From: Zhong Hui Date: Wed, 9 Dec 2020 16:13:44 +0800 Subject: [PATCH] fix abs double grad unittest (#29478) fix abs double grad unittest & define the data range for the abs double grad --- .../paddle/fluid/tests/unittests/test_activation_nn_grad.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/paddle/fluid/tests/unittests/test_activation_nn_grad.py b/python/paddle/fluid/tests/unittests/test_activation_nn_grad.py index 6c4834b84f9..f6c55588790 100644 --- a/python/paddle/fluid/tests/unittests/test_activation_nn_grad.py +++ b/python/paddle/fluid/tests/unittests/test_activation_nn_grad.py @@ -161,6 +161,10 @@ class TestAbsDoubleGradCheck(unittest.TestCase): x.persistable = True y = layers.abs(x) x_arr = np.random.uniform(-1, 1, shape).astype(dtype) + # Because we set delta = 0.005 in calculating numeric gradient, + # if x is too small, the numeric gradient is inaccurate. + # we should avoid this + x_arr[np.abs(x_arr) < 0.005] = 0.02 gradient_checker.double_grad_check( [x], y, x_init=x_arr, place=place, eps=eps) -- GitLab