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 b14d27e605ba33d1800650708e3559f9177ea4b0..58bcbdc8c0035ad243f8ddd3d8a10e892463db28 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)