From 4ff8fca52c7bb2507aba4c21cefae3f09de2a527 Mon Sep 17 00:00:00 2001 From: umiswing Date: Mon, 24 Jul 2023 11:07:22 +0800 Subject: [PATCH] Fix test_sparse_norm_op failure. (#55405) * Fix test failed on cudnn. * Fix codestyle. --- test/legacy_test/test_sparse_norm_op.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/legacy_test/test_sparse_norm_op.py b/test/legacy_test/test_sparse_norm_op.py index c17a252ee75..25a253d9787 100644 --- a/test/legacy_test/test_sparse_norm_op.py +++ b/test/legacy_test/test_sparse_norm_op.py @@ -100,19 +100,23 @@ class TestSparseBatchNorm(unittest.TestCase): else: bn = paddle.nn.BatchNorm3D(shape[-1], data_format=data_format) y = bn(x) - y.backward() + np.random.seed(5) + loss_data = np.random.uniform(-0.01, 0.01, y.shape).astype("float32") + loss = paddle.to_tensor(loss_data) + y.backward(loss) sp_x = paddle.to_tensor(data).to_sparse_coo(dim - 1) sp_x.stop_gradient = False sp_bn = paddle.sparse.nn.BatchNorm(shape[-1], data_format=data_format) sp_y = sp_bn(sp_x) - sp_y.backward() + sp_loss = loss.to_sparse_coo(dim - 1) + sp_y.backward(sp_loss) np.testing.assert_allclose( - y.numpy(), sp_y.to_dense().numpy(), rtol=1e-5 + sp_y.to_dense().numpy(), y.numpy(), rtol=1e-5 ) np.testing.assert_allclose( - x.grad.numpy(), sp_x.grad.to_dense().numpy(), rtol=1e-5 + sp_x.grad.to_dense().numpy(), x.grad.numpy(), rtol=1e-5 ) def test_nd(self): -- GitLab