From 22ea1ceba41ebf3848a427e76f66a93425cd38c2 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Fri, 21 Apr 2023 08:46:29 +0000 Subject: [PATCH 01/33] add test cases, test=allcase --- .../tests/unittests/test_zero_dim_tensor.py | 102 ++++++++++++++++++ python/paddle/tensor/einsum.py | 4 +- 2 files changed, 104 insertions(+), 2 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index f3bea4cf2467b6..2e0a82ee26536f 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -17,6 +17,7 @@ # 0D Tensor's shape is always [], numel is 1 # which can be created by paddle.rand([]) +import os import unittest import numpy as np @@ -1585,6 +1586,71 @@ def test_gather_xD_axis_1(self): self.assertEqual(x.grad.shape, [2, 3]) self.assertEqual(out.grad.shape, [2]) + def test_gather_nd(self): + x1 = paddle.to_tensor([1.0, 3.0, 5.0, 7.0, 9.0], stop_gradient=False) + x2 = paddle.to_tensor( + [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], stop_gradient=False + ) + + index1 = paddle.full([1], 1, 'int64') + index2 = paddle.full([2], 1, 'int64') + + out1 = paddle.gather_nd(x1, index1) + out2 = paddle.gather_nd(x2, index2) + + out1.retain_grads() + out2.retain_grads() + + out1.backward() + out2.backward() + + self.assertEqual(out1.shape, []) + self.assertEqual(out2.shape, []) + np.testing.assert_array_equal(out1, np.array(3.0)) + np.testing.assert_array_equal(out2, np.array(5.0)) + self.assertEqual(x1.grad.shape, [5]) + self.assertEqual(x2.grad.shape, [2, 3]) + self.assertEqual(out1.grad.shape, []) + self.assertEqual(out2.grad.shape, []) + + def test_einsum(self): + os.environ['FLAGS_new_einsum'] = "0" + x = paddle.rand([5]) + # sum + out1 = paddle.einsum('i->', x) + # dot + out2 = paddle.einsum('i,i->', x, x) + + out1.retain_grads() + out2.retain_grads() + + out1.backward() + out2.backward() + + self.assertEqual(out1.shape, []) + self.assertEqual(out2.shape, []) + np.testing.assert_array_equal(out1, np.array(3.0)) + np.testing.assert_array_equal(out2, np.array(5.0)) + + def test_einsum_V2(self): + os.environ['FLAGS_new_einsum'] = "1" + x = paddle.rand([5]) + # sum + out1 = paddle.einsum('i->', x) + # dot + out2 = paddle.einsum('i,i->', x, x) + + out1.retain_grads() + out2.retain_grads() + + out1.backward() + out2.backward() + + self.assertEqual(out1.shape, []) + self.assertEqual(out2.shape, []) + np.testing.assert_array_equal(out1, np.einsum('i->', x)) + np.testing.assert_array_equal(out2, np.einsum('i,i->', x, x)) + def test_scatter_1D(self): x = paddle.to_tensor([1.0, 3.0, 5.0, 7.0, 9.0], stop_gradient=False) index = paddle.full([], 2, 'int64') @@ -3355,6 +3421,42 @@ def test_gather_XD_axis_1(self): self.assertEqual(res[1].shape, (2, 3)) self.assertEqual(res[2].shape, (2,)) + @prog_scope() + def test_gather_nd(self): + x1 = paddle.full([10], 1.0, 'float32') + x1.stop_gradient = False + x2 = paddle.to_tensor([2, 3], 1.0, stop_gradient=False) + x2.stop_gradient = False + + index1 = paddle.full([1], 1, 'int64') + index2 = paddle.full([2], 1, 'int64') + + out1 = paddle.gather_nd(x1, index1) + out2 = paddle.gather_nd(x2, index2) + paddle.static.append_backward(out1.sum()) + paddle.static.append_backward(out2.sum()) + + prog = paddle.static.default_main_program() + res = self.exe.run( + prog, + fetch_list=[ + out1, + out2, + x1.grad_name, + x2.grad_name, + out1.grad_name, + out2.grad_name, + ], + ) + self.assertEqual(res[0].shape, ()) + self.assertEqual(res[1].shape, ()) + np.testing.assert_array_equal(res[0], 1.0) + np.testing.assert_array_equal(res[1], 1.0) + self.assertEqual(res[2].shape, (10,)) + self.assertEqual(res[3].shape, (2, 3)) + self.assertEqual(res[4].shape, ()) + self.assertEqual(res[5].shape, ()) + @prog_scope() def test_scatter_1D(self): x = paddle.full([10], 1.0, 'float32') diff --git a/python/paddle/tensor/einsum.py b/python/paddle/tensor/einsum.py index 7ab104dde94b0e..082300763740a0 100644 --- a/python/paddle/tensor/einsum.py +++ b/python/paddle/tensor/einsum.py @@ -966,8 +966,8 @@ def einsum(equation, *operands): # dot print(paddle.einsum('i,i->', x, x)) - # Tensor(shape=[1], dtype=float32, place=CUDAPlace(0), stop_gradient=True, - # [1.45936954]) + # Tensor(shape=[], dtype=float32, place=CUDAPlace(0), stop_gradient=True, + # 1.45936954) # outer print(paddle.einsum("i,j->ij", x, y)) From a0e3ad315e7539bc64fbfaf4c50196ff3fce8577 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Fri, 21 Apr 2023 09:43:00 +0000 Subject: [PATCH 02/33] fix test cases, test=allcase --- .../fluid/tests/unittests/test_zero_dim_tensor.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 2e0a82ee26536f..e902c2479ddb42 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -1618,8 +1618,10 @@ def test_einsum(self): x = paddle.rand([5]) # sum out1 = paddle.einsum('i->', x) + expect1 = np.einsum('i->', x) # dot out2 = paddle.einsum('i,i->', x, x) + expect2 = np.einsum('i,i->', x, x) out1.retain_grads() out2.retain_grads() @@ -1629,16 +1631,18 @@ def test_einsum(self): self.assertEqual(out1.shape, []) self.assertEqual(out2.shape, []) - np.testing.assert_array_equal(out1, np.array(3.0)) - np.testing.assert_array_equal(out2, np.array(5.0)) + np.testing.assert_array_equal(out1, expect1) + np.testing.assert_array_equal(out2, expect2) def test_einsum_V2(self): os.environ['FLAGS_new_einsum'] = "1" x = paddle.rand([5]) # sum out1 = paddle.einsum('i->', x) + expect1 = np.einsum('i->', x) # dot out2 = paddle.einsum('i,i->', x, x) + expect2 = np.einsum('i,i->', x, x) out1.retain_grads() out2.retain_grads() @@ -1648,8 +1652,8 @@ def test_einsum_V2(self): self.assertEqual(out1.shape, []) self.assertEqual(out2.shape, []) - np.testing.assert_array_equal(out1, np.einsum('i->', x)) - np.testing.assert_array_equal(out2, np.einsum('i,i->', x, x)) + np.testing.assert_array_equal(out1, expect1) + np.testing.assert_array_equal(out2, expect2) def test_scatter_1D(self): x = paddle.to_tensor([1.0, 3.0, 5.0, 7.0, 9.0], stop_gradient=False) @@ -3425,7 +3429,7 @@ def test_gather_XD_axis_1(self): def test_gather_nd(self): x1 = paddle.full([10], 1.0, 'float32') x1.stop_gradient = False - x2 = paddle.to_tensor([2, 3], 1.0, stop_gradient=False) + x2 = paddle.to_tensor([2, 3], 1.0, 'float32') x2.stop_gradient = False index1 = paddle.full([1], 1, 'int64') From b9b1c00300fcf3c86b1f6a396632717b54179602 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Sun, 23 Apr 2023 02:36:47 +0000 Subject: [PATCH 03/33] fix test cases, test=allcase --- python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index e902c2479ddb42..582fa5825c3780 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -3429,7 +3429,7 @@ def test_gather_XD_axis_1(self): def test_gather_nd(self): x1 = paddle.full([10], 1.0, 'float32') x1.stop_gradient = False - x2 = paddle.to_tensor([2, 3], 1.0, 'float32') + x2 = paddle.full([2, 3], 1.0, 'float32') x2.stop_gradient = False index1 = paddle.full([1], 1, 'int64') From b4cdbdad88b37f402615b4b5619734c3e4be899e Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Sun, 23 Apr 2023 10:05:31 +0000 Subject: [PATCH 04/33] assert_allclose, test=allcase --- .../paddle/fluid/tests/unittests/test_zero_dim_tensor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 582fa5825c3780..10878190292b72 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -1631,8 +1631,8 @@ def test_einsum(self): self.assertEqual(out1.shape, []) self.assertEqual(out2.shape, []) - np.testing.assert_array_equal(out1, expect1) - np.testing.assert_array_equal(out2, expect2) + np.testing.assert_allclose(out1, expect1, rtol=1e-05) + np.testing.assert_allclose(out2, expect2, rtol=1e-05) def test_einsum_V2(self): os.environ['FLAGS_new_einsum'] = "1" @@ -1652,8 +1652,8 @@ def test_einsum_V2(self): self.assertEqual(out1.shape, []) self.assertEqual(out2.shape, []) - np.testing.assert_array_equal(out1, expect1) - np.testing.assert_array_equal(out2, expect2) + np.testing.assert_allclose(out1, expect1, rtol=1e-05) + np.testing.assert_allclose(out2, expect2, rtol=1e-05) def test_scatter_1D(self): x = paddle.to_tensor([1.0, 3.0, 5.0, 7.0, 9.0], stop_gradient=False) From 7547df975f6eeacc413807beafb51bbd0ae49a62 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Mon, 24 Apr 2023 02:39:18 +0000 Subject: [PATCH 05/33] 1e-5 to 1e-4, test=allcase --- .../paddle/fluid/tests/unittests/test_zero_dim_tensor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 10878190292b72..a79fc9e71b2fbc 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -1631,8 +1631,8 @@ def test_einsum(self): self.assertEqual(out1.shape, []) self.assertEqual(out2.shape, []) - np.testing.assert_allclose(out1, expect1, rtol=1e-05) - np.testing.assert_allclose(out2, expect2, rtol=1e-05) + np.testing.assert_allclose(out1, expect1, rtol=1e-04) + np.testing.assert_allclose(out2, expect2, rtol=1e-04) def test_einsum_V2(self): os.environ['FLAGS_new_einsum'] = "1" @@ -1652,8 +1652,8 @@ def test_einsum_V2(self): self.assertEqual(out1.shape, []) self.assertEqual(out2.shape, []) - np.testing.assert_allclose(out1, expect1, rtol=1e-05) - np.testing.assert_allclose(out2, expect2, rtol=1e-05) + np.testing.assert_allclose(out1, expect1, rtol=1e-04) + np.testing.assert_allclose(out2, expect2, rtol=1e-04) def test_scatter_1D(self): x = paddle.to_tensor([1.0, 3.0, 5.0, 7.0, 9.0], stop_gradient=False) From 112acc8f347e19c69edff48ec768125a82632edd Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Mon, 24 Apr 2023 12:49:29 +0000 Subject: [PATCH 06/33] change rtol from 1e-4 to 1e-3, test=allcase --- .../paddle/fluid/tests/unittests/test_zero_dim_tensor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index a79fc9e71b2fbc..5fcc3bac0b6d5f 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -1631,8 +1631,8 @@ def test_einsum(self): self.assertEqual(out1.shape, []) self.assertEqual(out2.shape, []) - np.testing.assert_allclose(out1, expect1, rtol=1e-04) - np.testing.assert_allclose(out2, expect2, rtol=1e-04) + np.testing.assert_allclose(out1, expect1, rtol=1e-03) + np.testing.assert_allclose(out2, expect2, rtol=1e-03) def test_einsum_V2(self): os.environ['FLAGS_new_einsum'] = "1" @@ -1652,8 +1652,8 @@ def test_einsum_V2(self): self.assertEqual(out1.shape, []) self.assertEqual(out2.shape, []) - np.testing.assert_allclose(out1, expect1, rtol=1e-04) - np.testing.assert_allclose(out2, expect2, rtol=1e-04) + np.testing.assert_allclose(out1, expect1, rtol=1e-03) + np.testing.assert_allclose(out2, expect2, rtol=1e-03) def test_scatter_1D(self): x = paddle.to_tensor([1.0, 3.0, 5.0, 7.0, 9.0], stop_gradient=False) From 060930a07e51999d0b0e7193982e1f370199e646 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Wed, 12 Apr 2023 11:54:41 +0000 Subject: [PATCH 07/33] test=allcase --- .../tests/unittests/test_zero_dim_tensor.py | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 5fcc3bac0b6d5f..7783b828c53a97 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -2267,6 +2267,48 @@ def test_upsample(self): self.assertEqual(out1.shape, [2, 3, 12, 12]) self.assertEqual(input_x.grad.shape, [2, 3, 6, 6]) + def test_unstack(self): + x1 = paddle.full([1], 0) + x2 = paddle.full([2], 2) + x1.retain_grads() + x2.retain_grads() + x1.stop_gradient = False + x2.stop_gradient = False + out1 = paddle.unstack(x1, 0) + out1.retain_grads() + out1.backward() + [out2_1, out2_2] = paddle.unstack(x2, 0) + self.assertEqual(out1.shape, []) + self.assertEqual(out1.numpy(), 0) + self.assertEqual(out1.grad.shape, []) + self.assertEqual(out2_1.shape, []) + self.assertEqual(out2_1.numpy(), 2) + self.assertEqual(out2_1.grad.shape, []) + self.assertEqual(out2_2.shape, []) + self.assertEqual(out2_2.numpy(), 2) + self.assertEqual(out2_2.grad.shape, []) + + def test_unbind(self): + x1 = paddle.full([1], 0) + x2 = paddle.full([2], 2) + x1.retain_grads() + x2.retain_grads() + x1.stop_gradient = False + x2.stop_gradient = False + out1 = paddle.unbind(x1, 0) + out1.retain_grads() + out1.backward() + [out2_1, out2_2] = paddle.unstack(x2, 0) + self.assertEqual(out1.shape, []) + self.assertEqual(out1.numpy(), 0) + self.assertEqual(out1.grad.shape, []) + self.assertEqual(out2_1.shape, []) + self.assertEqual(out2_1.numpy(), 2) + self.assertEqual(out2_1.grad.shape, []) + self.assertEqual(out2_2.shape, []) + self.assertEqual(out2_2.numpy(), 2) + self.assertEqual(out2_2.grad.shape, []) + def test_maseked_select(self): x = paddle.rand([]) x.stop_gradient = False @@ -2281,6 +2323,23 @@ def test_maseked_select(self): self.assertEqual(x.grad.shape, []) self.assertEqual(x.grad.numpy(), 1) + def test_squeeze(self): + x1 = paddle.full([], 2) + x1.stop_gradient = False + x1.retain_grads() + out1 = paddle.squeeze(x1, axis=0) + out1.retain_grads() + out1.backward() + self.assertEqual(out1.shape, []) + self.assertEqual(x1.grad.shape, []) + + x2 = paddle.full([], 0, dtype='int32') + out2 = paddle.squeeze(x1, axis=x2) + out2.retain_grads() + out2.backward() + self.assertEqual(out2.shape, []) + self.assertEqual(x1.grad.shape, []) + def test_unsqueeze(self): x1 = paddle.full([], 2) x1.stop_gradient = False From 799b247e95ec3dad3f4b16195fdc06a6c6dd0836 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Thu, 13 Apr 2023 06:27:48 +0000 Subject: [PATCH 08/33] test=allcase --- .../tests/unittests/test_zero_dim_tensor.py | 80 ++++++++++++++++++- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 7783b828c53a97..bb12a8661fac0a 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -2274,10 +2274,14 @@ def test_unstack(self): x2.retain_grads() x1.stop_gradient = False x2.stop_gradient = False - out1 = paddle.unstack(x1, 0) + [out1] = paddle.unstack(x1, 0) out1.retain_grads() out1.backward() [out2_1, out2_2] = paddle.unstack(x2, 0) + out2_1.retain_grads() + out2_1.backward() + out2_2.retain_grads() + out2_2.backward() self.assertEqual(out1.shape, []) self.assertEqual(out1.numpy(), 0) self.assertEqual(out1.grad.shape, []) @@ -2295,10 +2299,14 @@ def test_unbind(self): x2.retain_grads() x1.stop_gradient = False x2.stop_gradient = False - out1 = paddle.unbind(x1, 0) + [out1] = paddle.unbind(x1, 0) out1.retain_grads() out1.backward() - [out2_1, out2_2] = paddle.unstack(x2, 0) + [out2_1, out2_2] = paddle.unbind(x2, 0) + out2_1.retain_grads() + out2_1.backward() + out2_2.retain_grads() + out2_2.backward() self.assertEqual(out1.shape, []) self.assertEqual(out1.numpy(), 0) self.assertEqual(out1.grad.shape, []) @@ -4136,6 +4144,44 @@ def test_upsample(self): self.assertEqual(res1[0].shape, (2, 3, 12, 12)) self.assertEqual(res1[1].shape, (2, 3, 6, 6)) + @prog_scope() + def test_unstack(self): + x1 = paddle.full([], 0, 'float32') + x2 = paddle.full([2], 2, 'float32') + x1.stop_gradient = False + x2.stop_gradient = False + [out] = paddle.unstack(x1, 0) + paddle.static.append_backward(out) + [out2_1, out2_2] = paddle.unstack(x2, 0) + paddle.static.append_backward(out2_1) + paddle.static.append_backward(out2_2) + + prog = paddle.static.default_main_program() + res = self.exe.run(prog, feed={}, fetch_list=[out, out2_1, out2_2]) + + self.assertEqual(res[0].shape, ()) + self.assertEqual(res[1].shape, ()) + self.assertEqual(res[2].shape, ()) + + @prog_scope() + def test_unbind(self): + x1 = paddle.full([], 0, 'float32') + x2 = paddle.full([2], 2, 'float32') + x1.stop_gradient = False + x2.stop_gradient = False + [out] = paddle.unbind(x1, 0) + paddle.static.append_backward(out) + [out2_1, out2_2] = paddle.unstack(x2, 0) + paddle.static.append_backward(out2_1) + paddle.static.append_backward(out2_2) + + prog = paddle.static.default_main_program() + res = self.exe.run(prog, feed={}, fetch_list=[out, out2_1, out2_2]) + + self.assertEqual(res[0].shape, ()) + self.assertEqual(res[1].shape, ()) + self.assertEqual(res[2].shape, ()) + @prog_scope() def test_maseked_select(self): x = paddle.rand([]) @@ -4152,6 +4198,34 @@ def test_maseked_select(self): self.assertEqual(res[3].shape, ()) self.assertEqual(res[3], 1) + @prog_scope() + def test_squeeze(self): + x1 = paddle.full([], 2) + x1.stop_gradient = False + out1 = paddle.squeeze(x1, axis=0) + paddle.static.append_backward(out1.sum()) + + x2 = paddle.full([], 3) + x3 = paddle.full([], 0, dtype='int32') + x2.stop_gradient = False + out2 = paddle.squeeze(x2, axis=x3) + paddle.static.append_backward(out2.sum()) + + prog = paddle.static.default_main_program() + res = self.exe.run( + prog, + fetch_list=[ + out1, + out2, + x1.grad_name, + x2.grad_name, + ], + ) + self.assertEqual(res[0].shape, ()) + self.assertEqual(res[1].shape, ()) + self.assertEqual(res[2].shape, ()) + self.assertEqual(res[3].shape, ()) + @prog_scope() def test_unsqueeze(self): x1 = paddle.full([], 2) From 477d0a94d1413fc6c576d7e64791f384e4539250 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Thu, 13 Apr 2023 08:09:29 +0000 Subject: [PATCH 09/33] test=allcase --- .../tests/unittests/test_zero_dim_tensor.py | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index bb12a8661fac0a..fbc3a1c335a1b0 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4147,40 +4147,40 @@ def test_upsample(self): @prog_scope() def test_unstack(self): x1 = paddle.full([], 0, 'float32') - x2 = paddle.full([2], 2, 'float32') x1.stop_gradient = False - x2.stop_gradient = False - [out] = paddle.unstack(x1, 0) - paddle.static.append_backward(out) - [out2_1, out2_2] = paddle.unstack(x2, 0) - paddle.static.append_backward(out2_1) - paddle.static.append_backward(out2_2) - + out1 = paddle.unstack(x1, 0) + paddle.static.append_backward(out1) prog = paddle.static.default_main_program() - res = self.exe.run(prog, feed={}, fetch_list=[out, out2_1, out2_2]) + res = self.exe.run(prog, feed={}, fetch_list=[out1]) + self.assertEqual(res[0][0].shape, ()) - self.assertEqual(res[0].shape, ()) - self.assertEqual(res[1].shape, ()) - self.assertEqual(res[2].shape, ()) + x2 = paddle.full([2], 2, 'float32') + x2.stop_gradient = False + out2 = paddle.unstack(x2, 0) + paddle.static.append_backward(out2) + prog = paddle.static.default_main_program() + res = self.exe.run(prog, feed={}, fetch_list=[out2]) + self.assertEqual(res[0][0].shape, ()) + self.assertEqual(res[0][1].shape, ()) @prog_scope() def test_unbind(self): x1 = paddle.full([], 0, 'float32') - x2 = paddle.full([2], 2, 'float32') x1.stop_gradient = False - x2.stop_gradient = False - [out] = paddle.unbind(x1, 0) - paddle.static.append_backward(out) - [out2_1, out2_2] = paddle.unstack(x2, 0) - paddle.static.append_backward(out2_1) - paddle.static.append_backward(out2_2) - + out1 = paddle.unbind(x1, 0) + paddle.static.append_backward(out1) prog = paddle.static.default_main_program() - res = self.exe.run(prog, feed={}, fetch_list=[out, out2_1, out2_2]) + res = self.exe.run(prog, feed={}, fetch_list=[out1]) + self.assertEqual(res[0][0].shape, ()) - self.assertEqual(res[0].shape, ()) - self.assertEqual(res[1].shape, ()) - self.assertEqual(res[2].shape, ()) + x2 = paddle.full([2], 2, 'float32') + x2.stop_gradient = False + out2 = paddle.unbind(x2, 0) + paddle.static.append_backward(out2) + prog = paddle.static.default_main_program() + res = self.exe.run(prog, feed={}, fetch_list=[out2]) + self.assertEqual(res[0][0].shape, ()) + self.assertEqual(res[0][1].shape, ()) @prog_scope() def test_maseked_select(self): From 4913c91e9d615cc1aa75f934945c8d215a0be49a Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Thu, 13 Apr 2023 11:02:51 +0000 Subject: [PATCH 10/33] test=allcase --- .../fluid/tests/unittests/test_zero_dim_tensor.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index fbc3a1c335a1b0..216120c24e5508 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4204,6 +4204,16 @@ def test_squeeze(self): x1.stop_gradient = False out1 = paddle.squeeze(x1, axis=0) paddle.static.append_backward(out1.sum()) + prog = paddle.static.default_main_program() + res = self.exe.run( + prog, + fetch_list=[ + out1, + x1.grad_name, + ], + ) + self.assertEqual(res[0].shape, ()) + self.assertEqual(res[1].shape, ()) x2 = paddle.full([], 3) x3 = paddle.full([], 0, dtype='int32') @@ -4215,16 +4225,12 @@ def test_squeeze(self): res = self.exe.run( prog, fetch_list=[ - out1, out2, - x1.grad_name, x2.grad_name, ], ) self.assertEqual(res[0].shape, ()) self.assertEqual(res[1].shape, ()) - self.assertEqual(res[2].shape, ()) - self.assertEqual(res[3].shape, ()) @prog_scope() def test_unsqueeze(self): From 30812f9a93d8efa2e1a60a26f6cef44c9dc60b91 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Mon, 17 Apr 2023 12:05:26 +0000 Subject: [PATCH 11/33] test=allcase --- .../tests/unittests/test_zero_dim_tensor.py | 26 +++++-------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 216120c24e5508..eb97d053a1f8fa 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4146,18 +4146,14 @@ def test_upsample(self): @prog_scope() def test_unstack(self): - x1 = paddle.full([], 0, 'float32') - x1.stop_gradient = False + x1 = paddle.full([1], 0, 'float32') out1 = paddle.unstack(x1, 0) - paddle.static.append_backward(out1) prog = paddle.static.default_main_program() res = self.exe.run(prog, feed={}, fetch_list=[out1]) self.assertEqual(res[0][0].shape, ()) x2 = paddle.full([2], 2, 'float32') - x2.stop_gradient = False out2 = paddle.unstack(x2, 0) - paddle.static.append_backward(out2) prog = paddle.static.default_main_program() res = self.exe.run(prog, feed={}, fetch_list=[out2]) self.assertEqual(res[0][0].shape, ()) @@ -4165,18 +4161,14 @@ def test_unstack(self): @prog_scope() def test_unbind(self): - x1 = paddle.full([], 0, 'float32') - x1.stop_gradient = False + x1 = paddle.full([1], 0, 'float32') out1 = paddle.unbind(x1, 0) - paddle.static.append_backward(out1) prog = paddle.static.default_main_program() res = self.exe.run(prog, feed={}, fetch_list=[out1]) self.assertEqual(res[0][0].shape, ()) x2 = paddle.full([2], 2, 'float32') - x2.stop_gradient = False out2 = paddle.unbind(x2, 0) - paddle.static.append_backward(out2) prog = paddle.static.default_main_program() res = self.exe.run(prog, feed={}, fetch_list=[out2]) self.assertEqual(res[0][0].shape, ()) @@ -4204,16 +4196,6 @@ def test_squeeze(self): x1.stop_gradient = False out1 = paddle.squeeze(x1, axis=0) paddle.static.append_backward(out1.sum()) - prog = paddle.static.default_main_program() - res = self.exe.run( - prog, - fetch_list=[ - out1, - x1.grad_name, - ], - ) - self.assertEqual(res[0].shape, ()) - self.assertEqual(res[1].shape, ()) x2 = paddle.full([], 3) x3 = paddle.full([], 0, dtype='int32') @@ -4225,12 +4207,16 @@ def test_squeeze(self): res = self.exe.run( prog, fetch_list=[ + out1, out2, + x1.grad_name, x2.grad_name, ], ) self.assertEqual(res[0].shape, ()) self.assertEqual(res[1].shape, ()) + self.assertEqual(res[2].shape, ()) + self.assertEqual(res[3].shape, ()) @prog_scope() def test_unsqueeze(self): From 53cc56a801e377620668213b79ae9d878cc7763a Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Sun, 23 Apr 2023 07:43:19 +0000 Subject: [PATCH 12/33] fix test cases, test=allcase --- .../tests/unittests/test_zero_dim_tensor.py | 32 ++++--------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index eb97d053a1f8fa..0a0c3cf2120415 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -2270,52 +2270,32 @@ def test_upsample(self): def test_unstack(self): x1 = paddle.full([1], 0) x2 = paddle.full([2], 2) - x1.retain_grads() - x2.retain_grads() - x1.stop_gradient = False - x2.stop_gradient = False + [out1] = paddle.unstack(x1, 0) - out1.retain_grads() - out1.backward() [out2_1, out2_2] = paddle.unstack(x2, 0) - out2_1.retain_grads() - out2_1.backward() - out2_2.retain_grads() - out2_2.backward() + self.assertEqual(out1.shape, []) self.assertEqual(out1.numpy(), 0) - self.assertEqual(out1.grad.shape, []) + self.assertEqual(out2_1.shape, []) self.assertEqual(out2_1.numpy(), 2) - self.assertEqual(out2_1.grad.shape, []) self.assertEqual(out2_2.shape, []) self.assertEqual(out2_2.numpy(), 2) - self.assertEqual(out2_2.grad.shape, []) def test_unbind(self): x1 = paddle.full([1], 0) x2 = paddle.full([2], 2) - x1.retain_grads() - x2.retain_grads() - x1.stop_gradient = False - x2.stop_gradient = False + [out1] = paddle.unbind(x1, 0) - out1.retain_grads() - out1.backward() [out2_1, out2_2] = paddle.unbind(x2, 0) - out2_1.retain_grads() - out2_1.backward() - out2_2.retain_grads() - out2_2.backward() + self.assertEqual(out1.shape, []) self.assertEqual(out1.numpy(), 0) - self.assertEqual(out1.grad.shape, []) + self.assertEqual(out2_1.shape, []) self.assertEqual(out2_1.numpy(), 2) - self.assertEqual(out2_1.grad.shape, []) self.assertEqual(out2_2.shape, []) self.assertEqual(out2_2.numpy(), 2) - self.assertEqual(out2_2.grad.shape, []) def test_maseked_select(self): x = paddle.rand([]) From e0aa371881d465d5444431888ca45a314bdc535c Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Sun, 23 Apr 2023 10:00:32 +0000 Subject: [PATCH 13/33] fix test cases, test=allcase --- .../fluid/tests/unittests/test_zero_dim_tensor.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 0a0c3cf2120415..1dc9936a0995f6 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4130,14 +4130,14 @@ def test_unstack(self): out1 = paddle.unstack(x1, 0) prog = paddle.static.default_main_program() res = self.exe.run(prog, feed={}, fetch_list=[out1]) - self.assertEqual(res[0][0].shape, ()) + self.assertEqual(res[0].shape, ()) x2 = paddle.full([2], 2, 'float32') out2 = paddle.unstack(x2, 0) prog = paddle.static.default_main_program() res = self.exe.run(prog, feed={}, fetch_list=[out2]) - self.assertEqual(res[0][0].shape, ()) - self.assertEqual(res[0][1].shape, ()) + self.assertEqual(res[0].shape, ()) + self.assertEqual(res[1].shape, ()) @prog_scope() def test_unbind(self): @@ -4145,14 +4145,14 @@ def test_unbind(self): out1 = paddle.unbind(x1, 0) prog = paddle.static.default_main_program() res = self.exe.run(prog, feed={}, fetch_list=[out1]) - self.assertEqual(res[0][0].shape, ()) + self.assertEqual(res[0].shape, ()) x2 = paddle.full([2], 2, 'float32') out2 = paddle.unbind(x2, 0) prog = paddle.static.default_main_program() res = self.exe.run(prog, feed={}, fetch_list=[out2]) - self.assertEqual(res[0][0].shape, ()) - self.assertEqual(res[0][1].shape, ()) + self.assertEqual(res[0].shape, ()) + self.assertEqual(res[1].shape, ()) @prog_scope() def test_maseked_select(self): From 322a8afd26d69c86153927f0093721e99031bb14 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Mon, 24 Apr 2023 03:58:44 +0000 Subject: [PATCH 14/33] modify the test_squeeze to not use Tensor type axis, test=allcase --- .../fluid/tests/unittests/test_zero_dim_tensor.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 1dc9936a0995f6..afcea7893ff970 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -2321,12 +2321,14 @@ def test_squeeze(self): self.assertEqual(out1.shape, []) self.assertEqual(x1.grad.shape, []) - x2 = paddle.full([], 0, dtype='int32') - out2 = paddle.squeeze(x1, axis=x2) + x2 = paddle.full([1, 1], 1, dtype='int32') + x2.stop_gradient = False + x2.retain_grads() + out2 = paddle.squeeze(x2, axis=[0, 1]) out2.retain_grads() out2.backward() self.assertEqual(out2.shape, []) - self.assertEqual(x1.grad.shape, []) + self.assertEqual(x2.grad.shape, [1, 1]) def test_unsqueeze(self): x1 = paddle.full([], 2) @@ -4177,10 +4179,9 @@ def test_squeeze(self): out1 = paddle.squeeze(x1, axis=0) paddle.static.append_backward(out1.sum()) - x2 = paddle.full([], 3) - x3 = paddle.full([], 0, dtype='int32') + x2 = paddle.full([1, 1], 1, dtype='int32') x2.stop_gradient = False - out2 = paddle.squeeze(x2, axis=x3) + out2 = paddle.squeeze(x2, axis=[0, 1]) paddle.static.append_backward(out2.sum()) prog = paddle.static.default_main_program() @@ -4196,7 +4197,7 @@ def test_squeeze(self): self.assertEqual(res[0].shape, ()) self.assertEqual(res[1].shape, ()) self.assertEqual(res[2].shape, ()) - self.assertEqual(res[3].shape, ()) + self.assertEqual(res[3].shape, (1, 1)) @prog_scope() def test_unsqueeze(self): From 1d7ee5fd33f65c358d5ebe9111a7e7bcac3b4b27 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Mon, 24 Apr 2023 10:23:01 +0000 Subject: [PATCH 15/33] add grad check for unbind and unstack, test=allcase --- .../tests/unittests/test_zero_dim_tensor.py | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index afcea7893ff970..d6836f6c1c9720 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -2270,9 +2270,18 @@ def test_upsample(self): def test_unstack(self): x1 = paddle.full([1], 0) x2 = paddle.full([2], 2) + x1.retain_grads() + x2.retain_grads() + x1.stop_gradient = False + x2.stop_gradient = False [out1] = paddle.unstack(x1, 0) + out1.retain_grads() + out1.backward() [out2_1, out2_2] = paddle.unstack(x2, 0) + out2 = paddle.add_n([out2_1, out2_2]) + out2.retain_grads() + out2.backward() self.assertEqual(out1.shape, []) self.assertEqual(out1.numpy(), 0) @@ -2281,13 +2290,23 @@ def test_unstack(self): self.assertEqual(out2_1.numpy(), 2) self.assertEqual(out2_2.shape, []) self.assertEqual(out2_2.numpy(), 2) + self.assertEqual(x2.grad.shape, [2]) def test_unbind(self): x1 = paddle.full([1], 0) x2 = paddle.full([2], 2) + x1.retain_grads() + x2.retain_grads() + x1.stop_gradient = False + x2.stop_gradient = False [out1] = paddle.unbind(x1, 0) + out1.retain_grads() + out1.backward() [out2_1, out2_2] = paddle.unbind(x2, 0) + out2 = paddle.add_n([out2_1, out2_2]) + out2.retain_grads() + out2.backward() self.assertEqual(out1.shape, []) self.assertEqual(out1.numpy(), 0) @@ -2296,6 +2315,7 @@ def test_unbind(self): self.assertEqual(out2_1.numpy(), 2) self.assertEqual(out2_2.shape, []) self.assertEqual(out2_2.numpy(), 2) + self.assertEqual(x2.grad.shape, [2]) def test_maseked_select(self): x = paddle.rand([]) @@ -4129,32 +4149,46 @@ def test_upsample(self): @prog_scope() def test_unstack(self): x1 = paddle.full([1], 0, 'float32') + x1.stop_gradient = False out1 = paddle.unstack(x1, 0) + out1 = paddle.add_n(out1) + paddle.static.append_backward(out1) prog = paddle.static.default_main_program() - res = self.exe.run(prog, feed={}, fetch_list=[out1]) + res = self.exe.run(prog, feed={}, fetch_list=[out1, x1.grad_name]) self.assertEqual(res[0].shape, ()) + self.assertEqual(res[1].shape, (1,)) x2 = paddle.full([2], 2, 'float32') + x2.stop_gradient = False out2 = paddle.unstack(x2, 0) + out2_sum = paddle.add_n(out2) + paddle.static.append_backward(out2_sum) prog = paddle.static.default_main_program() - res = self.exe.run(prog, feed={}, fetch_list=[out2]) + res = self.exe.run(prog, feed={}, fetch_list=[out2_sum, x2.grad_name]) self.assertEqual(res[0].shape, ()) - self.assertEqual(res[1].shape, ()) + self.assertEqual(res[1].shape, (2,)) @prog_scope() def test_unbind(self): x1 = paddle.full([1], 0, 'float32') + x1.stop_gradient = False out1 = paddle.unbind(x1, 0) + out1 = paddle.add_n(out1) + paddle.static.append_backward(out1) prog = paddle.static.default_main_program() - res = self.exe.run(prog, feed={}, fetch_list=[out1]) + res = self.exe.run(prog, feed={}, fetch_list=[out1, x1.grad_name]) self.assertEqual(res[0].shape, ()) + self.assertEqual(res[1].shape, (1,)) x2 = paddle.full([2], 2, 'float32') + x2.stop_gradient = False out2 = paddle.unbind(x2, 0) + out2_sum = paddle.add_n(out2) + paddle.static.append_backward(out2_sum) prog = paddle.static.default_main_program() - res = self.exe.run(prog, feed={}, fetch_list=[out2]) + res = self.exe.run(prog, feed={}, fetch_list=[out2_sum, x2.grad_name]) self.assertEqual(res[0].shape, ()) - self.assertEqual(res[1].shape, ()) + self.assertEqual(res[1].shape, (2,)) @prog_scope() def test_maseked_select(self): From a367e3c0bea29c0d4ed58f4d07b7e52adb451fe3 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Mon, 24 Apr 2023 12:11:10 +0000 Subject: [PATCH 16/33] check for squeeze axis tensor type, test=allcase --- .../fluid/tests/unittests/test_zero_dim_tensor.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index d6836f6c1c9720..7d7cec67c22ae2 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -2341,14 +2341,15 @@ def test_squeeze(self): self.assertEqual(out1.shape, []) self.assertEqual(x1.grad.shape, []) - x2 = paddle.full([1, 1], 1, dtype='int32') + x2 = paddle.full([], 3) + x3 = paddle.full([], 0, dtype='int32') x2.stop_gradient = False x2.retain_grads() - out2 = paddle.squeeze(x2, axis=[0, 1]) + out2 = paddle.squeeze(x2, axis=x3) out2.retain_grads() out2.backward() self.assertEqual(out2.shape, []) - self.assertEqual(x2.grad.shape, [1, 1]) + self.assertEqual(x2.grad.shape, []) def test_unsqueeze(self): x1 = paddle.full([], 2) @@ -4213,9 +4214,10 @@ def test_squeeze(self): out1 = paddle.squeeze(x1, axis=0) paddle.static.append_backward(out1.sum()) - x2 = paddle.full([1, 1], 1, dtype='int32') + x2 = paddle.full([], 3) + x3 = paddle.full([], 0, dtype='int32') x2.stop_gradient = False - out2 = paddle.squeeze(x2, axis=[0, 1]) + out2 = paddle.squeeze(x2, axis=x3) paddle.static.append_backward(out2.sum()) prog = paddle.static.default_main_program() @@ -4231,7 +4233,7 @@ def test_squeeze(self): self.assertEqual(res[0].shape, ()) self.assertEqual(res[1].shape, ()) self.assertEqual(res[2].shape, ()) - self.assertEqual(res[3].shape, (1, 1)) + self.assertEqual(res[3].shape, ()) @prog_scope() def test_unsqueeze(self): From a66ea6d3a7de736883c752b2bb8162bcc2b81764 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Thu, 27 Apr 2023 08:19:43 +0000 Subject: [PATCH 17/33] fix bug, test=allcase --- paddle/phi/infermeta/unary.cc | 3 +++ python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/paddle/phi/infermeta/unary.cc b/paddle/phi/infermeta/unary.cc index 14ae02246babb5..202ba2c7c69798 100644 --- a/paddle/phi/infermeta/unary.cc +++ b/paddle/phi/infermeta/unary.cc @@ -3761,6 +3761,9 @@ void SqueezeInferMeta(const MetaTensor& x, if (!config.is_runtime && axes.FromTensor()) { // compile time infershape, set all elements to -1. int output_size = x.dims().size() - axes.GetData().size(); + if (x.dims().size() == 0 && output_size == -1) { + output_size = 0; + } std::vector vec_out_dims(output_size, -1); out->set_dims(phi::make_ddim(vec_out_dims)); } else { diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 7d7cec67c22ae2..3d437b31313c7d 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -2342,7 +2342,7 @@ def test_squeeze(self): self.assertEqual(x1.grad.shape, []) x2 = paddle.full([], 3) - x3 = paddle.full([], 0, dtype='int32') + x3 = paddle.full([1], 0, dtype='int32') x2.stop_gradient = False x2.retain_grads() out2 = paddle.squeeze(x2, axis=x3) From 47270d2806d2aea218b36927c189908308c5ebb5 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Tue, 11 Apr 2023 08:50:41 +0000 Subject: [PATCH 18/33] test=allcase --- .../paddle/fluid/tests/unittests/test_data.py | 10 ++++++++++ .../tests/unittests/test_zero_dim_tensor.py | 20 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/python/paddle/fluid/tests/unittests/test_data.py b/python/paddle/fluid/tests/unittests/test_data.py index 51f01ed8bef330..15f4ed0c477a32 100644 --- a/python/paddle/fluid/tests/unittests/test_data.py +++ b/python/paddle/fluid/tests/unittests/test_data.py @@ -31,6 +31,16 @@ def test_dtype(self): x3 = paddle.static.data(name="x3", shape=[2, 25]) self.assertEqual(x3.dtype, core.VarDesc.VarType.FP64) + def test_0D(self): + with program_guard(Program(), Program()): + x1 = paddle.static.data(name="x1_0D", shape=[]) + self.assertEqual(x1.dtype, core.VarDesc.VarType.FP32) + x2 = paddle.static.data(name="x2_0D", shape=(), dtype="bool") + self.assertEqual(x2.dtype, core.VarDesc.VarType.BOOL) + paddle.set_default_dtype("float64") + x3 = paddle.static.data(name="x3_0D", shape=[]) + self.assertEqual(x3.dtype, core.VarDesc.VarType.FP64) + def test_error(self): with program_guard(Program(), Program()): diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 3d437b31313c7d..4d1bd443e62782 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4293,6 +4293,26 @@ def test_sequence_pad(self): res = self.exe.run(prog, feed={"x": x_tensor}, fetch_list=[out]) self.assertEqual(res[0].shape, (3, 4, 2)) + @prog_scope() + def test_static_data(self): + x1 = paddle.static.data(name="x1", shape=[]) + x2 = paddle.static.data(name="x2", shape=(), dtype="bool") + paddle.set_default_dtype("float64") + x3 = paddle.static.data(name="x3", shape=[]) + + prog = paddle.static.default_main_program() + res = self.exe.run( + prog, + fetch_list=[ + x1, + x2, + x3, + ], + ) + self.assertEqual(res[0].shape, []) + self.assertEqual(res[1].shape, ()) + self.assertEqual(res[2].shape, []) + @prog_scope() def test_prelu(self): x1 = paddle.full([], 1.0, 'float32') From 9c3f76c140e1d25ef2836fd6754c2053efeb7fba Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Tue, 11 Apr 2023 12:22:52 +0000 Subject: [PATCH 19/33] test=allcase --- python/paddle/fluid/tests/unittests/test_data.py | 3 --- python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py | 4 ---- 2 files changed, 7 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_data.py b/python/paddle/fluid/tests/unittests/test_data.py index 15f4ed0c477a32..763637fd0edb7d 100644 --- a/python/paddle/fluid/tests/unittests/test_data.py +++ b/python/paddle/fluid/tests/unittests/test_data.py @@ -37,9 +37,6 @@ def test_0D(self): self.assertEqual(x1.dtype, core.VarDesc.VarType.FP32) x2 = paddle.static.data(name="x2_0D", shape=(), dtype="bool") self.assertEqual(x2.dtype, core.VarDesc.VarType.BOOL) - paddle.set_default_dtype("float64") - x3 = paddle.static.data(name="x3_0D", shape=[]) - self.assertEqual(x3.dtype, core.VarDesc.VarType.FP64) def test_error(self): with program_guard(Program(), Program()): diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 4d1bd443e62782..46bfda18cc9e90 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4297,8 +4297,6 @@ def test_sequence_pad(self): def test_static_data(self): x1 = paddle.static.data(name="x1", shape=[]) x2 = paddle.static.data(name="x2", shape=(), dtype="bool") - paddle.set_default_dtype("float64") - x3 = paddle.static.data(name="x3", shape=[]) prog = paddle.static.default_main_program() res = self.exe.run( @@ -4306,12 +4304,10 @@ def test_static_data(self): fetch_list=[ x1, x2, - x3, ], ) self.assertEqual(res[0].shape, []) self.assertEqual(res[1].shape, ()) - self.assertEqual(res[2].shape, []) @prog_scope() def test_prelu(self): From 5dd52d6ed0a442a2e870aad7fc9ae132cc644e3f Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Wed, 12 Apr 2023 02:44:06 +0000 Subject: [PATCH 20/33] test=allcase --- python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 46bfda18cc9e90..4b5140a15982fd 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4295,7 +4295,7 @@ def test_sequence_pad(self): @prog_scope() def test_static_data(self): - x1 = paddle.static.data(name="x1", shape=[]) + x1 = paddle.static.data(name="x1", shape=[1]) x2 = paddle.static.data(name="x2", shape=(), dtype="bool") prog = paddle.static.default_main_program() From 1b66e5b18233aa42b8553ee84d3f0326d843f072 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Wed, 12 Apr 2023 03:54:24 +0000 Subject: [PATCH 21/33] test=allcase --- .../fluid/tests/unittests/test_zero_dim_tensor.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 4b5140a15982fd..21d5f86599a3ef 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4295,19 +4295,25 @@ def test_sequence_pad(self): @prog_scope() def test_static_data(self): - x1 = paddle.static.data(name="x1", shape=[1]) + x1 = paddle.static.data(name="x1", shape=[]) x2 = paddle.static.data(name="x2", shape=(), dtype="bool") prog = paddle.static.default_main_program() res = self.exe.run( prog, + feed={ + "x1": np.array(1.0, dtype='float32'), + "x2": np.array(True, dtype='bool'), + }, fetch_list=[ - x1, - x2, + x1.grad_name, + x2.grad_name, ], ) self.assertEqual(res[0].shape, []) + np.testing.assert_allclose(res[0], np.array(1.0)) self.assertEqual(res[1].shape, ()) + np.testing.assert_allclose(res[1], np.array(True)) @prog_scope() def test_prelu(self): From 2f4966a62b568f79f43dc00fc056304e811a303a Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Wed, 12 Apr 2023 06:50:34 +0000 Subject: [PATCH 22/33] test=allcase --- python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 21d5f86599a3ef..68bfb7bb5595a6 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4311,9 +4311,9 @@ def test_static_data(self): ], ) self.assertEqual(res[0].shape, []) - np.testing.assert_allclose(res[0], np.array(1.0)) + self.assertEqual(res[0], np.array(1.0)) self.assertEqual(res[1].shape, ()) - np.testing.assert_allclose(res[1], np.array(True)) + self.assertEqual(res[1], np.array(True)) @prog_scope() def test_prelu(self): From d663661ea0f6e0260b17bfbca76b3c8b2c1086f9 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Wed, 12 Apr 2023 08:43:36 +0000 Subject: [PATCH 23/33] test=allcase --- python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 68bfb7bb5595a6..d39244a9d48aa5 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4296,14 +4296,14 @@ def test_sequence_pad(self): @prog_scope() def test_static_data(self): x1 = paddle.static.data(name="x1", shape=[]) - x2 = paddle.static.data(name="x2", shape=(), dtype="bool") + x2 = paddle.static.data(name="x2", shape=()) prog = paddle.static.default_main_program() res = self.exe.run( prog, feed={ "x1": np.array(1.0, dtype='float32'), - "x2": np.array(True, dtype='bool'), + "x2": np.array(100.5, dtype='float32'), }, fetch_list=[ x1.grad_name, @@ -4313,7 +4313,7 @@ def test_static_data(self): self.assertEqual(res[0].shape, []) self.assertEqual(res[0], np.array(1.0)) self.assertEqual(res[1].shape, ()) - self.assertEqual(res[1], np.array(True)) + self.assertEqual(res[1], np.array(100.5)) @prog_scope() def test_prelu(self): From 2a8c93af277faaae15420d2583f959554eabf33c Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Wed, 12 Apr 2023 13:12:27 +0000 Subject: [PATCH 24/33] test=allcase --- python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index d39244a9d48aa5..02a72b79058c67 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4296,7 +4296,7 @@ def test_sequence_pad(self): @prog_scope() def test_static_data(self): x1 = paddle.static.data(name="x1", shape=[]) - x2 = paddle.static.data(name="x2", shape=()) + x2 = paddle.static.data(name="x2", shape=[]) prog = paddle.static.default_main_program() res = self.exe.run( From 5a3ae839e9a9ac51dd4661ed965b2057159b6207 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Thu, 13 Apr 2023 02:39:14 +0000 Subject: [PATCH 25/33] test=allcase --- python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 02a72b79058c67..85a2799abcf28f 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4306,8 +4306,8 @@ def test_static_data(self): "x2": np.array(100.5, dtype='float32'), }, fetch_list=[ - x1.grad_name, - x2.grad_name, + x1.name, + x2.name, ], ) self.assertEqual(res[0].shape, []) From 40b1ae77c458299a27d181382da5b8eb5c13ea8b Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Thu, 13 Apr 2023 06:32:47 +0000 Subject: [PATCH 26/33] test=allcase --- python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 85a2799abcf28f..373f7b3e1893be 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4310,7 +4310,7 @@ def test_static_data(self): x2.name, ], ) - self.assertEqual(res[0].shape, []) + self.assertEqual(res[0].shape, ()) self.assertEqual(res[0], np.array(1.0)) self.assertEqual(res[1].shape, ()) self.assertEqual(res[1], np.array(100.5)) From a166df9761e86e4264a0aa7d9a7c1ed9e2ff01a4 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Fri, 14 Apr 2023 06:35:57 +0000 Subject: [PATCH 27/33] test=allcase --- python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 373f7b3e1893be..574cc0512a7889 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4303,7 +4303,7 @@ def test_static_data(self): prog, feed={ "x1": np.array(1.0, dtype='float32'), - "x2": np.array(100.5, dtype='float32'), + "x2": 100.5, }, fetch_list=[ x1.name, @@ -4313,7 +4313,7 @@ def test_static_data(self): self.assertEqual(res[0].shape, ()) self.assertEqual(res[0], np.array(1.0)) self.assertEqual(res[1].shape, ()) - self.assertEqual(res[1], np.array(100.5)) + self.assertEqual(res[1], 100.5) @prog_scope() def test_prelu(self): From c7c53079d91ca641e75d2acfbf1c412257827889 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Fri, 14 Apr 2023 09:22:50 +0000 Subject: [PATCH 28/33] test=allcase --- .../tests/unittests/test_zero_dim_tensor.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 574cc0512a7889..69dbfc1ef4b827 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4303,17 +4303,26 @@ def test_static_data(self): prog, feed={ "x1": np.array(1.0, dtype='float32'), - "x2": 100.5, }, fetch_list=[ x1.name, - x2.name, ], ) self.assertEqual(res[0].shape, ()) self.assertEqual(res[0], np.array(1.0)) - self.assertEqual(res[1].shape, ()) - self.assertEqual(res[1], 100.5) + + prog = paddle.static.default_main_program() + res = self.exe.run( + prog, + feed={ + "x2": 100.5, + }, + fetch_list=[ + x2.name, + ], + ) + self.assertEqual(res[0].shape, ()) + self.assertEqual(res[0], 100.5) @prog_scope() def test_prelu(self): From 9f3a5dc8205ae05b2cacc4469d28154305ed971a Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Tue, 18 Apr 2023 03:33:25 +0000 Subject: [PATCH 29/33] test=allcase --- .../fluid/tests/unittests/test_zero_dim_tensor.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 69dbfc1ef4b827..2a50a1d97a1fb7 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -4296,8 +4296,6 @@ def test_sequence_pad(self): @prog_scope() def test_static_data(self): x1 = paddle.static.data(name="x1", shape=[]) - x2 = paddle.static.data(name="x2", shape=[]) - prog = paddle.static.default_main_program() res = self.exe.run( prog, @@ -4311,18 +4309,22 @@ def test_static_data(self): self.assertEqual(res[0].shape, ()) self.assertEqual(res[0], np.array(1.0)) + x2 = paddle.static.data(name="x2", shape=[]) + x3 = paddle.static.data(name="x3", shape=[]) + y = x2 + x3 prog = paddle.static.default_main_program() res = self.exe.run( prog, feed={ "x2": 100.5, + "x3": 200.5, }, fetch_list=[ - x2.name, + y.name, ], ) self.assertEqual(res[0].shape, ()) - self.assertEqual(res[0], 100.5) + self.assertEqual(res[0], 301.0) @prog_scope() def test_prelu(self): From 14f071864f0488a9bcb4048a7100177a75e7fcd9 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Tue, 18 Apr 2023 07:39:52 +0000 Subject: [PATCH 30/33] test=allcase --- python/paddle/fluid/executor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/fluid/executor.py b/python/paddle/fluid/executor.py index 37718c25c6c1f1..1b45c73973ba34 100755 --- a/python/paddle/fluid/executor.py +++ b/python/paddle/fluid/executor.py @@ -580,7 +580,7 @@ def _as_lodtensor(data, place, dtype=None): else dtype ) if np.isscalar(data): - data = np.array([data]).astype(dtype) + data = np.array(data).astype(dtype) elif isinstance(data, (list, tuple)): data = np.array(data) if data.dtype == np.object_: From f80c8d3c4b9ba5f4d5301d960ac0ba8ce4e096c5 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Wed, 19 Apr 2023 04:14:14 +0000 Subject: [PATCH 31/33] test=allcase --- .../fluid/tests/unittests/test_compare_op.py | 2 +- .../paddle/fluid/tests/unittests/test_deg2rad.py | 2 +- .../unittests/test_executor_feed_non_tensor.py | 2 +- python/paddle/fluid/tests/unittests/test_gcd.py | 16 ++++++++-------- python/paddle/fluid/tests/unittests/test_lcm.py | 16 ++++++++-------- .../tests/unittests/test_put_along_axis_op.py | 6 +++--- .../paddle/fluid/tests/unittests/test_rad2deg.py | 4 ++-- .../fluid/tests/unittests/test_trapezoid.py | 2 +- .../fluid/tests/unittests/test_unbind_op.py | 4 ++-- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_compare_op.py b/python/paddle/fluid/tests/unittests/test_compare_op.py index 9765ebda405b80..0b8c4aa8eae421 100755 --- a/python/paddle/fluid/tests/unittests/test_compare_op.py +++ b/python/paddle/fluid/tests/unittests/test_compare_op.py @@ -96,7 +96,7 @@ def test_api_float(self): paddle.enable_static() with program_guard(Program(), Program()): x = paddle.static.data(name='x', shape=[4], dtype='int64') - y = paddle.static.data(name='y', shape=[1], dtype='int64') + y = paddle.static.data(name='y', shape=[], dtype='int64') op = eval("paddle.%s" % (self.op_type)) out = op(x, y) exe = fluid.Executor(self.place) diff --git a/python/paddle/fluid/tests/unittests/test_deg2rad.py b/python/paddle/fluid/tests/unittests/test_deg2rad.py index 25800356abcac6..8c99bbfdc8b8bd 100644 --- a/python/paddle/fluid/tests/unittests/test_deg2rad.py +++ b/python/paddle/fluid/tests/unittests/test_deg2rad.py @@ -67,7 +67,7 @@ class TestDeg2radAPI2(TestDeg2radAPI): # Test input data type is int def setUp(self): self.x_np = 180 - self.x_shape = [1] + self.x_shape = [] self.out_np = np.pi self.x_dtype = 'int64' diff --git a/python/paddle/fluid/tests/unittests/test_executor_feed_non_tensor.py b/python/paddle/fluid/tests/unittests/test_executor_feed_non_tensor.py index eaf8857f6acf48..c1389ac2e1a674 100644 --- a/python/paddle/fluid/tests/unittests/test_executor_feed_non_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_executor_feed_non_tensor.py @@ -22,7 +22,7 @@ class TestExecutor(unittest.TestCase): def net(self): - lr = paddle.static.data(name="lr", shape=[1], dtype='float32') + lr = paddle.static.data(name="lr", shape=[], dtype='float32') x = paddle.static.data(name="x", shape=[None, 1], dtype='float32') y = paddle.static.data(name="y", shape=[None, 1], dtype='float32') y_predict = paddle.static.nn.fc(x, size=1) diff --git a/python/paddle/fluid/tests/unittests/test_gcd.py b/python/paddle/fluid/tests/unittests/test_gcd.py index 2ed8438ee56835..738c040ea98908 100644 --- a/python/paddle/fluid/tests/unittests/test_gcd.py +++ b/python/paddle/fluid/tests/unittests/test_gcd.py @@ -25,8 +25,8 @@ class TestGcdAPI(unittest.TestCase): def setUp(self): - self.x_np = 12 - self.y_np = 20 + self.x_np = [12] + self.y_np = [20] self.x_shape = [1] self.y_shape = [1] @@ -81,14 +81,14 @@ class TestGcdAPI3(TestGcdAPI): def setUp(self): self.x_np = 0 self.y_np = 20 - self.x_shape = [1] - self.y_shape = [1] + self.x_shape = [] + self.y_shape = [] class TestGcdAPI4(TestGcdAPI): def setUp(self): - self.x_np = 0 - self.y_np = 0 + self.x_np = [0] + self.y_np = [0] self.x_shape = [1] self.y_shape = [1] @@ -97,5 +97,5 @@ class TestGcdAPI5(TestGcdAPI): def setUp(self): self.x_np = 12 self.y_np = -20 - self.x_shape = [1] - self.y_shape = [1] + self.x_shape = [] + self.y_shape = [] diff --git a/python/paddle/fluid/tests/unittests/test_lcm.py b/python/paddle/fluid/tests/unittests/test_lcm.py index bb846a80d6ab27..478853d8bab8ff 100644 --- a/python/paddle/fluid/tests/unittests/test_lcm.py +++ b/python/paddle/fluid/tests/unittests/test_lcm.py @@ -27,8 +27,8 @@ class TestLcmAPI(unittest.TestCase): def setUp(self): self.x_np = 12 self.y_np = 20 - self.x_shape = [1] - self.y_shape = [1] + self.x_shape = [] + self.y_shape = [] def test_static_graph(self): startup_program = fluid.Program() @@ -81,14 +81,14 @@ class TestLcmAPI3(TestLcmAPI): def setUp(self): self.x_np = 0 self.y_np = 20 - self.x_shape = [1] - self.y_shape = [1] + self.x_shape = [] + self.y_shape = [] class TestLcmAPI4(TestLcmAPI): def setUp(self): - self.x_np = 0 - self.y_np = 0 + self.x_np = [0] + self.y_np = [0] self.x_shape = [1] self.y_shape = [1] @@ -97,5 +97,5 @@ class TestLcmAPI5(TestLcmAPI): def setUp(self): self.x_np = 12 self.y_np = -20 - self.x_shape = [1] - self.y_shape = [1] + self.x_shape = [] + self.y_shape = [] diff --git a/python/paddle/fluid/tests/unittests/test_put_along_axis_op.py b/python/paddle/fluid/tests/unittests/test_put_along_axis_op.py index a2085cc416a195..2834cda0be6966 100644 --- a/python/paddle/fluid/tests/unittests/test_put_along_axis_op.py +++ b/python/paddle/fluid/tests/unittests/test_put_along_axis_op.py @@ -141,7 +141,7 @@ def setUp(self): self.place = [paddle.CPUPlace()] self.axis = 0 self.value_np = 99.0 - self.value_shape = [1] + self.value_shape = [] self.x_feed = copy.deepcopy(self.x_np) if core.is_compiled_with_cuda(): self.place.append(paddle.CUDAPlace(0)) @@ -240,7 +240,7 @@ def setUp(self): self.place = [paddle.CPUPlace()] self.axis = 0 self.value_np = 99.0 - self.value_shape = [1] + self.value_shape = [] self.x_feed = copy.deepcopy(self.x_np) if core.is_compiled_with_cuda(): self.place.append(paddle.CUDAPlace(0)) @@ -258,7 +258,7 @@ def setUp(self): self.place = [paddle.CPUPlace()] self.axis = 0 self.value_np = 99.0 - self.value_shape = [1] + self.value_shape = [] self.x_feed = copy.deepcopy(self.x_np) if core.is_compiled_with_cuda(): self.place.append(paddle.CUDAPlace(0)) diff --git a/python/paddle/fluid/tests/unittests/test_rad2deg.py b/python/paddle/fluid/tests/unittests/test_rad2deg.py index 4013a6568e8226..d2468bd4a0662e 100644 --- a/python/paddle/fluid/tests/unittests/test_rad2deg.py +++ b/python/paddle/fluid/tests/unittests/test_rad2deg.py @@ -66,7 +66,7 @@ def test_dygraph(self): class TestRad2degAPI2(TestRad2degAPI): def setUp(self): self.x_np = np.pi / 2 - self.x_shape = [1] + self.x_shape = [] self.out_np = 90 self.x_dtype = 'float32' @@ -84,7 +84,7 @@ class TestRad2degAPI3(TestRad2degAPI): # Test input data type is int def setUp(self): self.x_np = 1 - self.x_shape = [1] + self.x_shape = [] self.out_np = 180 / np.pi self.x_dtype = 'int64' diff --git a/python/paddle/fluid/tests/unittests/test_trapezoid.py b/python/paddle/fluid/tests/unittests/test_trapezoid.py index 226f40db91ab3d..de18e75512717c 100644 --- a/python/paddle/fluid/tests/unittests/test_trapezoid.py +++ b/python/paddle/fluid/tests/unittests/test_trapezoid.py @@ -83,7 +83,7 @@ def test_static(self): ) if self.dx is not None: dx = paddle.static.data( - name="dx", shape=[1], dtype='float32' + name="dx", shape=[], dtype='float32' ) exe = paddle.static.Executor(place) diff --git a/python/paddle/fluid/tests/unittests/test_unbind_op.py b/python/paddle/fluid/tests/unittests/test_unbind_op.py index 4d5c4f9beefae3..989eb43b0504d0 100644 --- a/python/paddle/fluid/tests/unittests/test_unbind_op.py +++ b/python/paddle/fluid/tests/unittests/test_unbind_op.py @@ -29,7 +29,7 @@ def test_unbind(self): x_1 = paddle.static.data(shape=[2, 3], dtype='float32', name='x_1') [out_0, out_1] = tensor.unbind(input=x_1, axis=0) input_1 = np.random.random([2, 3]).astype("float32") - axis = paddle.static.data(shape=[1], dtype='int32', name='axis') + axis = paddle.static.data(shape=[], dtype='int32', name='axis') exe = fluid.Executor(place=fluid.CPUPlace()) [res_1, res_2] = exe.run( @@ -87,7 +87,7 @@ def test_layers_unbind(self): x_1 = paddle.static.data(shape=[2, 3], dtype='float32', name='x_1') [out_0, out_1] = paddle.unbind(input=x_1, axis=0) input_1 = np.random.random([2, 3]).astype("float32") - axis = paddle.static.data(shape=[1], dtype='int32', name='axis') + axis = paddle.static.data(shape=[], dtype='int32', name='axis') exe = fluid.Executor(place=fluid.CPUPlace()) [res_1, res_2] = exe.run( From 662baab7ef9db4f084b098457de63f7264f4befa Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Wed, 19 Apr 2023 06:30:54 +0000 Subject: [PATCH 32/33] test=allcase --- python/paddle/fluid/tests/unittests/test_deg2rad.py | 4 ++-- python/paddle/fluid/tests/unittests/test_rad2deg.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_deg2rad.py b/python/paddle/fluid/tests/unittests/test_deg2rad.py index 8c99bbfdc8b8bd..77dce311a939d6 100644 --- a/python/paddle/fluid/tests/unittests/test_deg2rad.py +++ b/python/paddle/fluid/tests/unittests/test_deg2rad.py @@ -66,8 +66,8 @@ def test_dygraph(self): class TestDeg2radAPI2(TestDeg2radAPI): # Test input data type is int def setUp(self): - self.x_np = 180 - self.x_shape = [] + self.x_np = [180] + self.x_shape = [1] self.out_np = np.pi self.x_dtype = 'int64' diff --git a/python/paddle/fluid/tests/unittests/test_rad2deg.py b/python/paddle/fluid/tests/unittests/test_rad2deg.py index d2468bd4a0662e..3188444ca0bbb2 100644 --- a/python/paddle/fluid/tests/unittests/test_rad2deg.py +++ b/python/paddle/fluid/tests/unittests/test_rad2deg.py @@ -83,8 +83,8 @@ def test_dygraph(self): class TestRad2degAPI3(TestRad2degAPI): # Test input data type is int def setUp(self): - self.x_np = 1 - self.x_shape = [] + self.x_np = [1] + self.x_shape = [1] self.out_np = 180 / np.pi self.x_dtype = 'int64' From 2106c26442d6e280fbac175d3b4c6be4533b5f18 Mon Sep 17 00:00:00 2001 From: zhengqiwen1997 Date: Wed, 19 Apr 2023 09:02:52 +0000 Subject: [PATCH 33/33] test=allcase --- python/paddle/fluid/tests/unittests/test_rad2deg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_rad2deg.py b/python/paddle/fluid/tests/unittests/test_rad2deg.py index 3188444ca0bbb2..8629d7dcd37f28 100644 --- a/python/paddle/fluid/tests/unittests/test_rad2deg.py +++ b/python/paddle/fluid/tests/unittests/test_rad2deg.py @@ -65,8 +65,8 @@ def test_dygraph(self): class TestRad2degAPI2(TestRad2degAPI): def setUp(self): - self.x_np = np.pi / 2 - self.x_shape = [] + self.x_np = [np.pi / 2] + self.x_shape = [1] self.out_np = 90 self.x_dtype = 'float32'