Skip to content

Commit

Permalink
fix the div 0 error of sequence_concat (#49963)
Browse files Browse the repository at this point in the history
* fix the div 0 error of sequence_concat
* Update test_sequence_concat.py
  • Loading branch information
Liyulingyue authored Feb 7, 2023
1 parent 20075bf commit 84fe2de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions paddle/fluid/operators/sequence_ops/sequence_concat_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ def test_dtype():

self.assertRaises(TypeError, test_dtype)

def test_0_shape():
# dtype must be 'float32', 'float64', 'int64'
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]
paddle.static.nn.sequence_lod.sequence_concat(input=input_list)

self.assertRaises(ValueError, test_0_shape)


if __name__ == '__main__':
paddle.enable_static()
Expand Down

0 comments on commit 84fe2de

Please sign in to comment.