From 392012461c5c6b96ce379ffcc5280442a645facc Mon Sep 17 00:00:00 2001 From: liyulingyue <852433440@qq.com> Date: Fri, 20 Jan 2023 11:14:54 +0800 Subject: [PATCH 1/4] fix div 0 error of split --- paddle/phi/infermeta/unary.cc | 4 ++++ python/paddle/fluid/tests/unittests/test_split_op.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/paddle/phi/infermeta/unary.cc b/paddle/phi/infermeta/unary.cc index 5a7b2cf16a1f8c..feeb63295889e0 100644 --- a/paddle/phi/infermeta/unary.cc +++ b/paddle/phi/infermeta/unary.cc @@ -3600,6 +3600,10 @@ void SplitWithNumInferMeta(const MetaTensor& x, auto input_axis_dim = x.dims().at(axis_value); // step1: get formated sections std::vector sections_vec; + PADDLE_ENFORCE_NE(num, + 0, + phi::errors::InvalidArgument( + "Attr(num_or_sections) should be 0."); PADDLE_ENFORCE_EQ(input_axis_dim % num, 0, phi::errors::InvalidArgument( diff --git a/python/paddle/fluid/tests/unittests/test_split_op.py b/python/paddle/fluid/tests/unittests/test_split_op.py index 943861ab2f57b3..b8dc555820d5f8 100644 --- a/python/paddle/fluid/tests/unittests/test_split_op.py +++ b/python/paddle/fluid/tests/unittests/test_split_op.py @@ -336,6 +336,12 @@ def test_axis_type_tensor(): self.assertRaises(TypeError, test_axis_type_tensor) + def test_0_num_tensor(): + x9 = fluid.layers.data(shape=[4], dtype='float32', name='x7') + paddle.split(input=x9, num_or_sections=0) + + self.assertRaises(TypeError, test_0_num_tensor) + class API_TestSplit(unittest.TestCase): def test_out(self): From bc131809d104dd696ad84db52f190ff13bc940fc Mon Sep 17 00:00:00 2001 From: liyulingyue <852433440@qq.com> Date: Fri, 20 Jan 2023 19:49:28 +0800 Subject: [PATCH 2/4] bug fix --- paddle/phi/infermeta/unary.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/paddle/phi/infermeta/unary.cc b/paddle/phi/infermeta/unary.cc index feeb63295889e0..affe97a49f554f 100644 --- a/paddle/phi/infermeta/unary.cc +++ b/paddle/phi/infermeta/unary.cc @@ -3600,10 +3600,10 @@ void SplitWithNumInferMeta(const MetaTensor& x, auto input_axis_dim = x.dims().at(axis_value); // step1: get formated sections std::vector sections_vec; - PADDLE_ENFORCE_NE(num, - 0, - phi::errors::InvalidArgument( - "Attr(num_or_sections) should be 0."); + PADDLE_ENFORCE_NE( + num, + 0, + phi::errors::InvalidArgument("Attr(num_or_sections) should be 0.")); PADDLE_ENFORCE_EQ(input_axis_dim % num, 0, phi::errors::InvalidArgument( From 39cf1048763f426cbd467fff722d462e4a9fd725 Mon Sep 17 00:00:00 2001 From: liyulingyue <852433440@qq.com> Date: Sat, 21 Jan 2023 13:37:54 +0800 Subject: [PATCH 3/4] bug fix; unittest change into dygraph --- paddle/phi/infermeta/unary.cc | 2 +- python/paddle/fluid/tests/unittests/test_split_op.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/paddle/phi/infermeta/unary.cc b/paddle/phi/infermeta/unary.cc index affe97a49f554f..7827fd1ee87e95 100644 --- a/paddle/phi/infermeta/unary.cc +++ b/paddle/phi/infermeta/unary.cc @@ -3603,7 +3603,7 @@ void SplitWithNumInferMeta(const MetaTensor& x, PADDLE_ENFORCE_NE( num, 0, - phi::errors::InvalidArgument("Attr(num_or_sections) should be 0.")); + phi::errors::InvalidArgument("Attr(num_or_sections) should not be 0.")); PADDLE_ENFORCE_EQ(input_axis_dim % num, 0, phi::errors::InvalidArgument( diff --git a/python/paddle/fluid/tests/unittests/test_split_op.py b/python/paddle/fluid/tests/unittests/test_split_op.py index b8dc555820d5f8..962966a9c8fc73 100644 --- a/python/paddle/fluid/tests/unittests/test_split_op.py +++ b/python/paddle/fluid/tests/unittests/test_split_op.py @@ -336,11 +336,13 @@ def test_axis_type_tensor(): self.assertRaises(TypeError, test_axis_type_tensor) + with paddle.fluid.dygraph.guard(): + def test_0_num_tensor(): - x9 = fluid.layers.data(shape=[4], dtype='float32', name='x7') - paddle.split(input=x9, num_or_sections=0) + x = paddle.uniform([1, 1, 1], dtype='float32') + paddle.split(x, num_or_sections=0) - self.assertRaises(TypeError, test_0_num_tensor) + self.assertRaises(ValueError, test_0_num_tensor) class API_TestSplit(unittest.TestCase): From 48bf6c3231d1df535c525072e7375468074bd385 Mon Sep 17 00:00:00 2001 From: Liyulingyue <852433440@qq.com> Date: Sat, 4 Feb 2023 21:09:24 +0800 Subject: [PATCH 4/4] xxx