From 911e4c7db6efd9e78a7ee6accc5b070e85a75417 Mon Sep 17 00:00:00 2001 From: pkpk Date: Fri, 27 Dec 2019 09:10:43 +0800 Subject: [PATCH] Fix the bug in sequence_scatter unitest (#21960) * test=develop * test=develop * test=develop * change the check_shape_white_list in web * test=develop * test=develop --- .../sequence/test_sequence_scatter_op.py | 33 ++++++++++++++----- .../white_list/check_shape_white_list.py | 5 ++- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/sequence/test_sequence_scatter_op.py b/python/paddle/fluid/tests/unittests/sequence/test_sequence_scatter_op.py index 153efd9182..1cc78c85b5 100644 --- a/python/paddle/fluid/tests/unittests/sequence/test_sequence_scatter_op.py +++ b/python/paddle/fluid/tests/unittests/sequence/test_sequence_scatter_op.py @@ -21,24 +21,23 @@ from op_test import OpTest class TestSequenceScatterOp(OpTest): def init_lod(self): - return [[3, 5, 4]] + return [[30, 50, 40]] def setUp(self): self.op_type = "sequence_scatter" X_data = np.random.uniform(0.1, 1.0, [3, 6]).astype('float64') - Ids_data = np.array([[0], [1], [2], [5], [4], [3], [0], [1], [3], [2], - [5], [4]]).astype('int64') + Ids_data = np.random.randint(0, 6, (120, 1)).astype('int64') Ids_lod = self.init_lod() - Updates_data = np.random.uniform(0.1, 1.0, [12, 1]).astype('float64') + Updates_data = np.random.uniform(0.1, 1.0, [120, 1]).astype('float64') Updates_lod = Ids_lod Out_data = np.copy(X_data) offset = 0 for i in range(3): - Out_data[i][Ids_data[offset:(offset + Ids_lod[0][ - i])]] += Updates_data[offset:(offset + Ids_lod[0][i])] + for j in range(Ids_lod[0][i]): + Out_data[i][Ids_data[offset + j]] += Updates_data[offset + j] offset += Ids_lod[0][i] self.inputs = { @@ -57,18 +56,34 @@ class TestSequenceScatterOp(OpTest): class TestSequenceScatterOpSeqLen0(TestSequenceScatterOp): def init_lod(self): - return [[6, 0, 6]] + return [[60, 60, 00]] class TestSequenceScatterOpSeqLen0Case1(TestSequenceScatterOp): def init_lod(self): - return [[0, 6, 6]] + return [[0, 60, 60]] class TestSequenceScatterOpSeqLen0Case2(TestSequenceScatterOp): def init_lod(self): - return [[6, 6, 0]] + return [[60, 0, 60]] +class TestSequenceScatterOpSeqLen0Case3(TestSequenceScatterOp): + def init_lod(self): + return [[120, 0, 0]] + + +class TestSequenceScatterOpSeqLen0Case4(TestSequenceScatterOp): + def init_lod(self): + return [[0, 120, 0]] + + +class TestSequenceScatterOpSeqLen0Case5(TestSequenceScatterOp): + def init_lod(self): + return [[0, 0, 120]] + + +# run the uni tests if __name__ == "__main__": unittest.main() diff --git a/python/paddle/fluid/tests/unittests/white_list/check_shape_white_list.py b/python/paddle/fluid/tests/unittests/white_list/check_shape_white_list.py index a7426bb516..c79e7358e7 100644 --- a/python/paddle/fluid/tests/unittests/white_list/check_shape_white_list.py +++ b/python/paddle/fluid/tests/unittests/white_list/check_shape_white_list.py @@ -18,7 +18,6 @@ NOT_CHECK_OP_LIST = [ ] NEED_TO_FIX_OP_LIST = [ - 'sequence_scatter', 'sequence_topk_avg_pooling', 'matmul', - 'add_position_encoding', 'margin_rank_loss', 'elementwise_pow', - 'fused_elemwise_activation', 'mul' + 'sequence_topk_avg_pooling', 'matmul', 'add_position_encoding', + 'margin_rank_loss', 'elementwise_pow', 'fused_elemwise_activation', 'mul' ]