From 004c1b715543ed3493232bb9a1b6d8bbc15a8a2e Mon Sep 17 00:00:00 2001 From: liyulingyue <852433440@qq.com> Date: Fri, 20 Jan 2023 18:38:14 +0800 Subject: [PATCH 1/6] fix the div 0 error of sequence_concat --- python/paddle/fluid/layers/sequence_lod.py | 4 ++++ .../tests/unittests/sequence/test_sequence_concat.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/python/paddle/fluid/layers/sequence_lod.py b/python/paddle/fluid/layers/sequence_lod.py index 99ed064a48bd0..3d1fddb171bad 100644 --- a/python/paddle/fluid/layers/sequence_lod.py +++ b/python/paddle/fluid/layers/sequence_lod.py @@ -451,6 +451,10 @@ def sequence_concat(input, name=None): ['int64', 'float32', 'float64'], 'fluid.layers.sequence_concat', ) + if input_x.dim() == 1 and 0 in input_x.shape: + raise ValueError( + 'the shape of element in input list should not be 0.' + ) out = helper.create_variable_for_type_inference(dtype=helper.input_dtype()) helper.append_op( diff --git a/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py b/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py index cb262f9495f8f..67ed0da7ae0dc 100644 --- a/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py +++ b/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py @@ -120,6 +120,15 @@ def test_dtype(): self.assertRaises(TypeError, test_dtype) + def test_0_shape(): + # dtype must be 'float32', 'float64', 'int64' + x4_data = fluid.layers.data(name="x4", shape=[0], dtype='int32') + y4_data = fluid.layers.data(name="y4", shape=[1], dtype='int16') + input_list = [x4_data, y4_data] + fluid.layers.sequence_concat(input=input_list) + + self.assertRaises(ValueError, test_0_shape) + if __name__ == '__main__': paddle.enable_static() From 499b5264f5469295ddd59f943696d06547c1e498 Mon Sep 17 00:00:00 2001 From: liyulingyue <852433440@qq.com> Date: Fri, 20 Jan 2023 19:41:14 +0800 Subject: [PATCH 2/6] bug fix --- .../fluid/tests/unittests/sequence/test_sequence_concat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py b/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py index 67ed0da7ae0dc..d65cb02ab0595 100644 --- a/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py +++ b/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py @@ -122,8 +122,8 @@ def test_dtype(): def test_0_shape(): # dtype must be 'float32', 'float64', 'int64' - x4_data = fluid.layers.data(name="x4", shape=[0], dtype='int32') - y4_data = fluid.layers.data(name="y4", shape=[1], dtype='int16') + x4_data = fluid.layers.data(name="x4", shape=[0], dtype='float32') + y4_data = fluid.layers.data(name="y4", shape=[1], dtype='float32') input_list = [x4_data, y4_data] fluid.layers.sequence_concat(input=input_list) From a9a83aa4b3764d02bafa077cf6fc1218c7033b46 Mon Sep 17 00:00:00 2001 From: Liyulingyue <852433440@qq.com> Date: Wed, 1 Feb 2023 19:18:22 +0800 Subject: [PATCH 3/6] replace fluid with static --- .../fluid/tests/unittests/sequence/test_sequence_concat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py b/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py index 1835bc45099b6..6878a9db9d749 100644 --- a/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py +++ b/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py @@ -132,8 +132,8 @@ def test_dtype(): def test_0_shape(): # dtype must be 'float32', 'float64', 'int64' - x4_data = fluid.layers.data(name="x4", shape=[0], dtype='float32') - y4_data = fluid.layers.data(name="y4", shape=[1], dtype='float32') + x4_data = paddle.static.data(name="x4", shape=[0], dtype='float32') + y4_data = paddle.static.data(name="y4", shape=[1], dtype='float32') input_list = [x4_data, y4_data] fluid.layers.sequence_concat(input=input_list) From 23df7e274c76e11296ea89de6f696e97c396723d Mon Sep 17 00:00:00 2001 From: Liyulingyue <852433440@qq.com> Date: Mon, 6 Feb 2023 05:46:19 +0800 Subject: [PATCH 4/6] fixed --- paddle/fluid/operators/sequence_ops/sequence_concat_op.cc | 5 +++++ python/paddle/fluid/layers/sequence_lod.py | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/operators/sequence_ops/sequence_concat_op.cc b/paddle/fluid/operators/sequence_ops/sequence_concat_op.cc index 63aef4a6282a4..888bb2658bb99 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_concat_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_concat_op.cc @@ -69,6 +69,11 @@ class SequenceConcatOp : public framework::OperatorWithKernel { out_dims = phi::vectorize(x_dim); } batch_size += x_dim[0]; + PADDLE_ENFORCE_NE( + x_dim[0], + 0, + platform::errors::InvalidArgument( + "The first dim of SequenceConcatOp inputs must not be 0."); if (feature_size == 0) { feature_size = phi::product(x_dim) / x_dim[0]; } else { diff --git a/python/paddle/fluid/layers/sequence_lod.py b/python/paddle/fluid/layers/sequence_lod.py index 3d1fddb171bad..99ed064a48bd0 100644 --- a/python/paddle/fluid/layers/sequence_lod.py +++ b/python/paddle/fluid/layers/sequence_lod.py @@ -451,10 +451,6 @@ def sequence_concat(input, name=None): ['int64', 'float32', 'float64'], 'fluid.layers.sequence_concat', ) - if input_x.dim() == 1 and 0 in input_x.shape: - raise ValueError( - 'the shape of element in input list should not be 0.' - ) out = helper.create_variable_for_type_inference(dtype=helper.input_dtype()) helper.append_op( From 70f5049ddd30349f86724a50f1c80b410e79736e Mon Sep 17 00:00:00 2001 From: Liyulingyue <852433440@qq.com> Date: Mon, 6 Feb 2023 20:13:07 +0800 Subject: [PATCH 5/6] fix error --- paddle/fluid/operators/sequence_ops/sequence_concat_op.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/operators/sequence_ops/sequence_concat_op.cc b/paddle/fluid/operators/sequence_ops/sequence_concat_op.cc index 888bb2658bb99..762ca5e42d763 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_concat_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_concat_op.cc @@ -70,10 +70,10 @@ class SequenceConcatOp : public framework::OperatorWithKernel { } batch_size += x_dim[0]; PADDLE_ENFORCE_NE( - x_dim[0], - 0, - platform::errors::InvalidArgument( - "The first dim of SequenceConcatOp inputs must not be 0."); + x_dim[0], + 0, + platform::errors::InvalidArgument( + "The first dim of SequenceConcatOp inputs must not be 0.")); if (feature_size == 0) { feature_size = phi::product(x_dim) / x_dim[0]; } else { From 257c6b4e41417fb64fb616da63ea1dd21097f90c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Tue, 7 Feb 2023 06:17:00 +0800 Subject: [PATCH 6/6] Update test_sequence_concat.py --- .../fluid/tests/unittests/sequence/test_sequence_concat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py b/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py index e01cbddcba6db..5d281d1cd9fc2 100644 --- a/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py +++ b/python/paddle/fluid/tests/unittests/sequence/test_sequence_concat.py @@ -139,7 +139,7 @@ def test_0_shape(): x4_data = paddle.static.data(name="x4", shape=[0], dtype='float32') y4_data = paddle.static.data(name="y4", shape=[1], dtype='float32') input_list = [x4_data, y4_data] - fluid.layers.sequence_concat(input=input_list) + paddle.static.nn.sequence_lod.sequence_concat(input=input_list) self.assertRaises(ValueError, test_0_shape)