From d43c972cd64a5c43b9388a0658753720c8c1057c Mon Sep 17 00:00:00 2001 From: OccupyMars2025 <31559413+OccupyMars2025@users.noreply.github.com> Date: Mon, 17 Oct 2022 18:04:49 +0800 Subject: [PATCH] [hidden trouble] Update test_sparse_transpose_op.py to get rid of a hidden trouble. (#47017) * Update test_sparse_transpose_op.py * Update test_sparse_transpose_op.py --- .../paddle/fluid/tests/unittests/test_sparse_transpose_op.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/paddle/fluid/tests/unittests/test_sparse_transpose_op.py b/python/paddle/fluid/tests/unittests/test_sparse_transpose_op.py index b14d27e605..58bcbdc8c0 100644 --- a/python/paddle/fluid/tests/unittests/test_sparse_transpose_op.py +++ b/python/paddle/fluid/tests/unittests/test_sparse_transpose_op.py @@ -23,7 +23,9 @@ class TestTranspose(unittest.TestCase): def check_result(self, x_shape, dims, format): with _test_eager_guard(): mask = paddle.randint(0, 2, x_shape).astype("float32") - origin_x = paddle.rand(x_shape, dtype='float32') * mask + # "+ 1" to make sure that all zero elements in "origin_x" is caused by multiplying by "mask", + # or the backward checks may fail. + origin_x = (paddle.rand(x_shape, dtype='float32') + 1) * mask dense_x = origin_x.detach() dense_x.stop_gradient = False dense_out = paddle.transpose(dense_x, dims) -- GitLab