From cacf549e8a2c0a3c801d7ab7625c2d8018b0d82a Mon Sep 17 00:00:00 2001 From: chengduoZH Date: Mon, 17 Sep 2018 15:05:56 +0800 Subject: [PATCH] refine seq_pool --- paddle/fluid/operators/math/sequence_pooling.cu | 4 ++-- python/paddle/fluid/tests/unittests/test_seq_pool.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/paddle/fluid/operators/math/sequence_pooling.cu b/paddle/fluid/operators/math/sequence_pooling.cu index 97c2e69fe5..a92aef805a 100644 --- a/paddle/fluid/operators/math/sequence_pooling.cu +++ b/paddle/fluid/operators/math/sequence_pooling.cu @@ -135,7 +135,7 @@ class SequencePoolFunctor { const std::string pooltype, const framework::LoDTensor& input, framework::Tensor* output, framework::Tensor* index = nullptr) { - auto lod = input.lod()[0]; + auto& lod = input.lod()[0]; const size_t item_dim = output->numel() / output->dims()[0]; dim3 threads(1024, 1); dim3 grid(lod.size(), 1); @@ -297,7 +297,7 @@ class SequencePoolGradFunctor { framework::LoDTensor* in_grad, /* max pool has index */ const framework::Tensor* index = nullptr) { - auto lod = in_grad->lod()[0]; + auto& lod = in_grad->lod()[0]; const size_t item_dim = in_grad->numel() / in_grad->dims()[0]; dim3 threads(1024, 1); dim3 grid(lod.size(), 1); diff --git a/python/paddle/fluid/tests/unittests/test_seq_pool.py b/python/paddle/fluid/tests/unittests/test_seq_pool.py index 66e77714c5..641eb03a5f 100644 --- a/python/paddle/fluid/tests/unittests/test_seq_pool.py +++ b/python/paddle/fluid/tests/unittests/test_seq_pool.py @@ -31,11 +31,11 @@ class TestSeqAvgPool(OpTest): self.op_type = 'sequence_pool' # one level, batch size is 4 x = np.random.uniform(0.1, 1, [11, 23]).astype('float32') - lod = [[4, 1, 3, 3]] + lod = [[11]] self.inputs = {'X': (x, lod)} offset = self.convert_to_offset(lod) - out = np.zeros((4, 23)).astype('float32') + out = np.zeros((len(lod[0]), 23)).astype('float32') self.outputs = {'Out': out} return x, offset, out @@ -71,7 +71,7 @@ class TestSeqMaxPool(TestSeqAvgPool): def set_data(self): self.op_type = 'sequence_pool' x = np.random.uniform(0.1, 1, [13, 23]).astype('float32') - lod = [[4, 1, 3, 5]] + lod = [[13]] offset = self.convert_to_offset(lod) for i in range(len(offset[0]) - 1): l = offset[0][i + 1] - offset[0][i] @@ -79,7 +79,7 @@ class TestSeqMaxPool(TestSeqAvgPool): self.inputs = {'X': (x, lod)} - out = np.zeros((4, 23)).astype('float32') + out = np.zeros((1, 23)).astype('float32') self.outputs = {'Out': out} return x, offset, out -- GitLab