From 05b0d11355c46d38d98d6675ae3b17677387d914 Mon Sep 17 00:00:00 2001 From: zhouwei25 Date: Wed, 15 Mar 2023 11:28:27 +0000 Subject: [PATCH] support output 0D, correct usage --- framework/api/loss/runner.py | 4 ++-- framework/api/optimizer/lrbase.py | 2 +- framework/api/optimizer/runner.py | 2 +- framework/api/paddlebase/test_allclose.py | 22 +++++++++++----------- framework/api/paddlebase/test_argmax.py | 10 +++++----- framework/api/paddlebase/test_argmin.py | 10 +++++----- framework/api/paddlebase/test_equal_all.py | 16 ++++++++-------- framework/api/paddlebase/test_numel.py | 2 +- framework/e2e/scene/runner.py | 4 ++-- 9 files changed, 36 insertions(+), 36 deletions(-) diff --git a/framework/api/loss/runner.py b/framework/api/loss/runner.py index ec4c65e113..8ed98c44aa 100644 --- a/framework/api/loss/runner.py +++ b/framework/api/loss/runner.py @@ -80,7 +80,7 @@ def run(self, model=None, expect=None): # logging.info('at {}, res is: {}'.format(i, loss)) if self.debug: print(loss) - self.result.append(loss.numpy()[0]) + self.result.append(float(loss)) # logging.info('at {}, result is: {}'.format(i, self.result)) self.check(result=self.result, expect=expect) @@ -172,7 +172,7 @@ def run(self, model=None, expect=None): # logging.info('at {}, res is: {}'.format(i, loss)) if self.debug: print(loss) - self.result.append(loss.numpy()[0]) + self.result.append(float(loss)) # logging.info('at {}, result is: {}'.format(i, self.result)) self.check(result=self.result, expect=expect) diff --git a/framework/api/optimizer/lrbase.py b/framework/api/optimizer/lrbase.py index ef152de74e..f62071dfdf 100644 --- a/framework/api/optimizer/lrbase.py +++ b/framework/api/optimizer/lrbase.py @@ -72,7 +72,7 @@ def run(self): # self.optimizer.clear_grad() # if self.debug: # print(loss) - # self.result.append(loss.numpy()[0]) + # self.result.append(float(loss)) def check(self, result=None, expect=None, delta=1e-6, rtol=1e-7): """ diff --git a/framework/api/optimizer/runner.py b/framework/api/optimizer/runner.py index 4a8a611caf..31ca37e6aa 100644 --- a/framework/api/optimizer/runner.py +++ b/framework/api/optimizer/runner.py @@ -34,7 +34,7 @@ def run(self): self.optimizer.clear_grad() if self.debug: print(loss) - self.result.append(loss.numpy()[0]) + self.result.append(float(loss)) def check(self, expect=None, rtol=1e-05, atol=1e-08): """ diff --git a/framework/api/paddlebase/test_allclose.py b/framework/api/paddlebase/test_allclose.py index 4bbd54c1a6..1f3cb21031 100644 --- a/framework/api/paddlebase/test_allclose.py +++ b/framework/api/paddlebase/test_allclose.py @@ -51,7 +51,7 @@ def test_allclose_base(): a = 0.01 r = 0.01 res = np.allclose(x, y, rtol=r, atol=a, equal_nan=False) - res = np.array([res]) + res = np.array(res) obj.base(res=res, x=x, y=y, rtol=r, atol=a, equal_nan=False) @@ -65,7 +65,7 @@ def test_allclose1(): a = 0.0 r = 0.01 res = np.allclose(x, y, rtol=r, atol=a, equal_nan=False) - res = np.array([res]) + res = np.array(res) obj2.run(res=res, x=x, y=y, rtol=r, atol=a, equal_nan=False) @@ -79,7 +79,7 @@ def test_allclose2(): a = 0.001 r = 0.000001 res = np.allclose(x, y, rtol=r, atol=a, equal_nan=False) - res = np.array([res]) + res = np.array(res) obj.run(res=res, x=x, y=y, rtol=r, atol=a, equal_nan=False) @@ -93,7 +93,7 @@ def test_allclose3(): a = 0.001 r = 0.000001 res = np.allclose(x, y, rtol=r, atol=a, equal_nan=True) - res = np.array([res]) + res = np.array(res) obj.run(res=res, x=x, y=y, rtol=r, atol=a, equal_nan=True) @@ -107,7 +107,7 @@ def test_allclose4(): a = 0.001 r = 0.00001 res = np.allclose(x, y, rtol=r, atol=a, equal_nan=True) - res = np.array([res]) + res = np.array(res) obj.run(res=res, x=x, y=y, rtol=r, atol=a, equal_nan=True) @@ -121,7 +121,7 @@ def test_allclose5(): a = 0.001 r = 0.00001 res = np.allclose(x, y, rtol=r, atol=a, equal_nan=False) - res = np.array([res]) + res = np.array(res) obj.run(res=res, x=x, y=y, rtol=r, atol=a, equal_nan=False) @@ -133,7 +133,7 @@ def test_allclose6(): x = np.array([10.001]) y = np.array([10.00001]) res = np.allclose(x, y) - res = np.array([res]) + res = np.array(res) obj.run(res=res, x=x, y=y) @@ -145,7 +145,7 @@ def test_allclose7(): x = 0.1 + np.arange(24).reshape(2, 2, 2, 3) y = np.arange(24).reshape(2, 2, 2, 3) res = np.allclose(x, y) - res = np.array([res]) + res = np.array(res) obj.run(res=res, x=x, y=y) @@ -159,7 +159,7 @@ def test_allclose8(): a = -2.0 r = -3.0 res = np.allclose(x, y, rtol=r, atol=a) - res = np.array([res]) + res = np.array(res) obj.run(res=res, x=x, y=y, rtol=r, atol=a) @@ -171,7 +171,7 @@ def test_allclose9(): x = np.array([]) y = np.array([]) res = np.allclose(x, y) - res = np.array([res]) + res = np.array(res) obj.run(res=res, x=x, y=y) @@ -199,4 +199,4 @@ def test_allclose10(): """ x = np.array([10.001]) y = np.array([10.00001]) - obj1.exception(mode="c", etype="NotFoundError", x=x, y=y) + obj1.exception(mode="c", etype="NotFound", x=x, y=y) diff --git a/framework/api/paddlebase/test_argmax.py b/framework/api/paddlebase/test_argmax.py index 61bde532f6..52fb0a61b0 100644 --- a/framework/api/paddlebase/test_argmax.py +++ b/framework/api/paddlebase/test_argmax.py @@ -52,7 +52,7 @@ def test_argmax(): """ x = randtool("float", -10, 10, [3, 3, 3]) res = np.argmax(a=x) - obj.run(res=[res], x=x) + obj.run(res=res, x=x) @pytest.mark.api_base_argmax_parameters @@ -87,7 +87,7 @@ def test_argmax3(): x = randtool("int", -10, 10, [3, 3]) dtype = "int32" res = np.argmax(a=x) - obj.run(res=[res], x=x, dtype=dtype) + obj.run(res=res, x=x, dtype=dtype) @pytest.mark.api_base_argmax_parameters @@ -133,7 +133,7 @@ def test_argmax7(): x = np.array([[-1], [2], [3]]) keepdim = None res = np.argmax(a=x) - obj.run(res=[res], x=x, keepdim=keepdim) + obj.run(res=res, x=x, keepdim=keepdim) @pytest.mark.api_base_argmax_parameters @@ -155,7 +155,7 @@ def test_argmax9(): """ x = randtool("float", -1, 1, [3, 3]) axis = 2 - obj.exception(mode="c", etype="InvalidArgumentError", x=x, axis=axis) + obj.exception(mode="c", etype="InvalidArgument", x=x, axis=axis) @pytest.mark.api_base_argmax_exception @@ -175,7 +175,7 @@ def test_argmax11(): """ x = randtool("float", -10, 10, [3, 3]) dtype = np.float32 - obj.exception(mode="c", etype="InvalidArgumentError", x=x, dtype=dtype) + obj.exception(mode="c", etype="InvalidArgument", x=x, dtype=dtype) @pytest.mark.api_base_argmax_exception diff --git a/framework/api/paddlebase/test_argmin.py b/framework/api/paddlebase/test_argmin.py index adbc4e6c7d..cb000d5821 100644 --- a/framework/api/paddlebase/test_argmin.py +++ b/framework/api/paddlebase/test_argmin.py @@ -52,7 +52,7 @@ def test_argmin(): """ x = randtool("float", -10, 10, [3, 3, 3]) res = np.argmin(a=x) - obj.run(res=[res], x=x) + obj.run(res=res, x=x) @pytest.mark.api_base_argmin_parameters @@ -87,7 +87,7 @@ def test_argmin3(): x = randtool("int", -10, 10, [3, 3]) dtype = "int32" res = np.argmin(a=x) - obj.run(res=[res], x=x, dtype=dtype) + obj.run(res=res, x=x, dtype=dtype) @pytest.mark.api_base_argmin_parameters @@ -133,7 +133,7 @@ def test_argmin7(): x = np.array([[-1], [2], [3]]) keepdim = None res = np.argmin(a=x) - obj.run(res=[res], x=x, keepdim=keepdim) + obj.run(res=res, x=x, keepdim=keepdim) @pytest.mark.api_base_argmin_parameters @@ -155,7 +155,7 @@ def test_argmin9(): """ x = randtool("float", -1, 1, [3, 3]) axis = 2 - obj.exception(mode="c", etype="InvalidArgumentError", x=x, axis=axis) + obj.exception(mode="c", etype="InvalidArgument", x=x, axis=axis) @pytest.mark.api_base_argmin_exception @@ -175,7 +175,7 @@ def test_argmin11(): """ x = randtool("float", -10, 10, [3, 3]) dtype = np.float32 - obj.exception(mode="c", etype="InvalidArgumentError", x=x, dtype=dtype) + obj.exception(mode="c", etype="InvalidArgument", x=x, dtype=dtype) @pytest.mark.api_base_argmin_exception diff --git a/framework/api/paddlebase/test_equal_all.py b/framework/api/paddlebase/test_equal_all.py index 5fa2d033db..3ee024b701 100644 --- a/framework/api/paddlebase/test_equal_all.py +++ b/framework/api/paddlebase/test_equal_all.py @@ -37,7 +37,7 @@ def test_equal_all_base(): """ x = randtool("int", -10, 10, [3, 3, 3]) y = x - res = np.array([True]) + res = np.array(True) obj.base(res=res, x=x, y=y) @@ -48,7 +48,7 @@ def test_equal_all(): """ x = randtool("float", -10, 10, [3, 3, 3]) y = x - res = np.array([True]) + res = np.array(True) obj.run(res=res, x=x, y=y) @@ -59,7 +59,7 @@ def test_equal_all1(): """ x = randtool("float", -10, 10, [3, 3, 3]) y = randtool("int", -10, 10, [3, 3, 3]) - res = np.array([False]) + res = np.array(False) obj.run(res=res, x=x, y=y) @@ -70,7 +70,7 @@ def test_equal_all2(): """ x = randtool("float", -10, 10, [3, 3, 3]) y = randtool("int", -10, 10, [3, 3]) - res = np.array([False]) + res = np.array(False) obj.run(res=res, x=x, y=y) @@ -81,7 +81,7 @@ def test_equal_all4(): """ x = np.array([[3, 3, 3], [3, 3, 3]]) y = np.array([[3, 3, 3]]) - res = np.array([False]) + res = np.array(False) obj.run(res=res, x=x, y=y) @@ -102,7 +102,7 @@ def test_equal_all6(): """ x = np.array([[True, False, True], [True, False, True]]) y = np.array([[True, False, True]]) - res = np.array([False]) + res = np.array(False) obj.run(res=res, x=x, y=y) @@ -113,7 +113,7 @@ def test_equal_all7(): """ x = np.array([[[True, False, True], [True, False, True]]]) y = np.array([[True, False, True], [True, False, True]]) - res = np.array([False]) + res = np.array(False) obj.run(res=res, x=x, y=y) @@ -124,5 +124,5 @@ def test_equal_all8(): """ x = np.array([[[[[True, False, True], [True, False, True]]]]]) y = x - res = np.array([True]) + res = np.array(True) obj.run(res=res, x=x, y=y) diff --git a/framework/api/paddlebase/test_numel.py b/framework/api/paddlebase/test_numel.py index 0087664306..6742a675d9 100644 --- a/framework/api/paddlebase/test_numel.py +++ b/framework/api/paddlebase/test_numel.py @@ -32,5 +32,5 @@ def test_numel_base(): base """ x = np.arange(20).reshape(4, 5) - res = np.array([20]) + res = np.array(20) obj.base(res=res, x=x) diff --git a/framework/e2e/scene/runner.py b/framework/e2e/scene/runner.py index ec4c65e113..8ed98c44aa 100644 --- a/framework/e2e/scene/runner.py +++ b/framework/e2e/scene/runner.py @@ -80,7 +80,7 @@ def run(self, model=None, expect=None): # logging.info('at {}, res is: {}'.format(i, loss)) if self.debug: print(loss) - self.result.append(loss.numpy()[0]) + self.result.append(float(loss)) # logging.info('at {}, result is: {}'.format(i, self.result)) self.check(result=self.result, expect=expect) @@ -172,7 +172,7 @@ def run(self, model=None, expect=None): # logging.info('at {}, res is: {}'.format(i, loss)) if self.debug: print(loss) - self.result.append(loss.numpy()[0]) + self.result.append(float(loss)) # logging.info('at {}, result is: {}'.format(i, self.result)) self.check(result=self.result, expect=expect)