diff --git a/test/legacy_test/test_stack_op.py b/test/legacy_test/test_stack_op.py index 0b9a5cfb84344c..82b7b4023280b0 100644 --- a/test/legacy_test/test_stack_op.py +++ b/test/legacy_test/test_stack_op.py @@ -465,8 +465,8 @@ def test_dygraph_cpu(self): out.backward() np.testing.assert_equal(out.shape, [2, 1, 0]) - # np.testing.assert_equal(x1.grad, None) - # np.testing.assert_equal(x2.grad, None) + np.testing.assert_equal(x1.grad.shape, [1, 0]) + np.testing.assert_equal(x2.grad.shape, [1, 0]) np.testing.assert_equal(out, np.ones([2, 1, 0])) paddle.enable_static() @@ -485,8 +485,8 @@ def test_dygraph_gpu(self): out.backward() np.testing.assert_equal(out.shape, [2, 1, 0]) - np.testing.assert_equal(x1.grad, None) - np.testing.assert_equal(x2.grad, None) + np.testing.assert_equal(x1.grad.shape, [1, 0]) + np.testing.assert_equal(x2.grad.shape, [1, 0]) np.testing.assert_equal(out, np.ones([2, 1, 0])) paddle.enable_static() @@ -604,6 +604,7 @@ def test_all(self): np.testing.assert_allclose(out.numpy(), out_std.numpy(), rtol=1e-20) for g, g_std in zip(grads, grads_std): np.testing.assert_allclose(g.numpy(), g_std.numpy(), rtol=1e-20) + paddle.enable_static() if __name__ == '__main__':