From 3bf7036ca0fe99c203371ba6e7132f66481bed93 Mon Sep 17 00:00:00 2001 From: wqgo <1552367872@qq.com> Date: Wed, 1 Mar 2023 23:41:30 +0800 Subject: [PATCH 1/3] add float16 to greater_equal --- .../paddle/fluid/tests/unittests/test_compare_op.py | 12 ++++++++++++ python/paddle/tensor/logic.py | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_compare_op.py b/python/paddle/fluid/tests/unittests/test_compare_op.py index 8ae2d9221862c..8282ff0edc5dc 100755 --- a/python/paddle/fluid/tests/unittests/test_compare_op.py +++ b/python/paddle/fluid/tests/unittests/test_compare_op.py @@ -479,6 +479,18 @@ def test_api_fp16(self): (res,) = exe.run(fetch_list=[out]) self.assertEqual((res == np.array([True, False])).all(), True) +class API_Test_Greater_Equal(unittest.TestCase): + def test_api_fp16(self): + paddle.enable_static() + with fluid.program_guard(fluid.Program(), fluid.Program()): + label = paddle.to_tensor([3, 3], dtype="float16") + limit = paddle.to_tensor([3, 2], dtype="float16") + out = paddle.greater_equal(x=label, y=limit) + if core.is_compiled_with_cuda(): + place = paddle.CUDAPlace(0) + exe = fluid.Executor(place) + (res,) = exe.run(fetch_list=[out]) + self.assertEqual((res == np.array([True, True])).all(), True) class TestCompareOpPlace(unittest.TestCase): def test_place_1(self): diff --git a/python/paddle/tensor/logic.py b/python/paddle/tensor/logic.py index 47045269eb03d..09b00d20941ea 100644 --- a/python/paddle/tensor/logic.py +++ b/python/paddle/tensor/logic.py @@ -495,8 +495,8 @@ def greater_equal(x, y, name=None): The output has no gradient. Args: - x(Tensor): First input to compare which is N-D tensor. The input data type should be bool, float32, float64, int32, int64. - y(Tensor): Second input to compare which is N-D tensor. The input data type should be bool, float32, float64, int32, int64. + x(Tensor): First input to compare which is N-D tensor. The input data type should be bool, float16, float32, float64, int32, int64. + y(Tensor): Second input to compare which is N-D tensor. The input data type should be bool, float16, float32, float64, int32, int64. name(str, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. Returns: @@ -518,13 +518,13 @@ def greater_equal(x, y, name=None): check_variable_and_dtype( x, "x", - ["bool", "float32", "float64", "int32", "int64"], + ["bool", "float16", "float32", "float64", "int32", "int64"], "greater_equal", ) check_variable_and_dtype( y, "y", - ["bool", "float32", "float64", "int32", "int64"], + ["bool", "float16", "float32", "float64", "int32", "int64"], "greater_equal", ) helper = LayerHelper("greater_equal", **locals()) From 98c3a8439cb62d8de83730b3ccf4c4fb680dc223 Mon Sep 17 00:00:00 2001 From: wqgo <1552367872@qq.com> Date: Fri, 3 Mar 2023 14:50:53 +0800 Subject: [PATCH 2/3] update codestyle --- .../fluid/tests/unittests/test_compare_op.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_compare_op.py b/python/paddle/fluid/tests/unittests/test_compare_op.py index 8282ff0edc5dc..8a4608a545086 100755 --- a/python/paddle/fluid/tests/unittests/test_compare_op.py +++ b/python/paddle/fluid/tests/unittests/test_compare_op.py @@ -479,18 +479,22 @@ def test_api_fp16(self): (res,) = exe.run(fetch_list=[out]) self.assertEqual((res == np.array([True, False])).all(), True) -class API_Test_Greater_Equal(unittest.TestCase): + +class API_TestElementwise_Greater_Than(unittest.TestCase): def test_api_fp16(self): paddle.enable_static() - with fluid.program_guard(fluid.Program(), fluid.Program()): + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() + ): label = paddle.to_tensor([3, 3], dtype="float16") limit = paddle.to_tensor([3, 2], dtype="float16") - out = paddle.greater_equal(x=label, y=limit) + out = paddle.greater_than(x=label, y=limit) if core.is_compiled_with_cuda(): place = paddle.CUDAPlace(0) - exe = fluid.Executor(place) + exe = paddle.static.Executor(place) (res,) = exe.run(fetch_list=[out]) - self.assertEqual((res == np.array([True, True])).all(), True) + self.assertEqual((res == np.array([False, True])).all(), True) + class TestCompareOpPlace(unittest.TestCase): def test_place_1(self): From 74f697cadef9a563b5784e4bc507af4068543f7a Mon Sep 17 00:00:00 2001 From: wqgo <1552367872@qq.com> Date: Fri, 3 Mar 2023 17:11:53 +0800 Subject: [PATCH 3/3] update --- python/paddle/fluid/tests/unittests/test_compare_op.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_compare_op.py b/python/paddle/fluid/tests/unittests/test_compare_op.py index 8a4608a545086..b6fe1d82d906a 100755 --- a/python/paddle/fluid/tests/unittests/test_compare_op.py +++ b/python/paddle/fluid/tests/unittests/test_compare_op.py @@ -480,7 +480,7 @@ def test_api_fp16(self): self.assertEqual((res == np.array([True, False])).all(), True) -class API_TestElementwise_Greater_Than(unittest.TestCase): +class API_TestElementwise_Greater_Equal(unittest.TestCase): def test_api_fp16(self): paddle.enable_static() with paddle.static.program_guard( @@ -488,12 +488,12 @@ def test_api_fp16(self): ): label = paddle.to_tensor([3, 3], dtype="float16") limit = paddle.to_tensor([3, 2], dtype="float16") - out = paddle.greater_than(x=label, y=limit) + out = paddle.greater_equal(x=label, y=limit) if core.is_compiled_with_cuda(): place = paddle.CUDAPlace(0) exe = paddle.static.Executor(place) (res,) = exe.run(fetch_list=[out]) - self.assertEqual((res == np.array([False, True])).all(), True) + self.assertEqual((res == np.array([True, True])).all(), True) class TestCompareOpPlace(unittest.TestCase):