diff --git a/paddle/operators/gru_op.h b/paddle/operators/gru_op.h index 2c9aa762428879232430e0e3e191b7b388454468..ba90ec9816c40a6a49065ac6efcee6b93dffce90 100644 --- a/paddle/operators/gru_op.h +++ b/paddle/operators/gru_op.h @@ -51,26 +51,16 @@ class GRUKernel : public framework::OpKernel { auto* hidden = context.Output("Hidden"); hidden->mutable_data(context.GetPlace()); - // context.ShareLoD("Input", "Gate"); - // context.ShareLoD("Input", "ResetHiddenPrev"); context.ShareLoD("Input", "Hidden"); - // auto gate_dims = gate->dims(); auto hidden_dims = hidden->dims(); - // LoDTensor batch_gate, batch_reset_hidden_prev, batch_hidden; - // batch_gate.mutable_data(gate_dims, context.GetPlace()); - // batch_reset_hidden_prev.mutable_data(hidden_dims, context.GetPlace()); - // batch_hidden.mutable_data(hidden_dims, context.GetPlace()); - bool is_reverse = context.Attr("is_reverse"); math::LoDTensor2BatchFunctor to_batch; - // to_batch(context.device_context(), *input, batch_gate, is_reverse); to_batch(context.device_context(), *input, *batch_gate, true, is_reverse); int frame_size = hidden_dims[1]; int batch_size = hidden_dims[0]; - // auto g = EigenMatrix::From(batch_gate); auto g = EigenMatrix::From(*batch_gate); auto place = context.GetEigenDevice(); if (bias) { @@ -85,20 +75,13 @@ class GRUKernel : public framework::OpKernel { gru_value.stateWeight = const_cast(weight_data + 2 * frame_size * frame_size); gru_value.prevOutValue = const_cast(h0_data); - // auto batch_starts = batch_gate.lod()[0]; auto batch_starts = batch_gate->lod()[0]; - // for (auto i = batch_gate->lod()[1].begin(); i != - // batch_gate->lod()[1].end(); ++i) - // std::cout << static_cast(*i) << ' '; size_t num_batch = batch_starts.size() - 1; for (size_t n = 0; n < num_batch; n++) { int bstart = static_cast(batch_starts[n]); int bend = static_cast(batch_starts[n + 1]); int cur_batch_size = bend - bstart; - // Tensor gate_t = batch_gate.Slice(bstart, bend); - // Tensor reset_hidden_prev_t = batch_reset_hidden_prev.Slice(bstart, - // bend); Tensor gate_t = batch_gate->Slice(bstart, bend); Tensor reset_hidden_prev_t = batch_reset_hidden_prev->Slice(bstart, bend); Tensor hidden_t = batch_hidden->Slice(bstart, bend); @@ -113,13 +96,6 @@ class GRUKernel : public framework::OpKernel { } math::Batch2LoDTensorFunctor to_seq; - // batch_gate.set_lod(batch_gate.lod()); - // to_seq(context.device_context(), batch_gate, *gate); - // batch_reset_hidden_prev.set_lod(batch_gate.lod()); - // to_seq(context.device_context(), batch_reset_hidden_prev, - // *reset_hidden_prev); - // batch_hidden.set_lod(batch_gate.lod()); - // to_seq(context.device_context(), batch_hidden, *hidden); batch_hidden->set_lod(batch_gate->lod()); to_seq(context.device_context(), *batch_hidden, *hidden); } @@ -167,11 +143,8 @@ class GRUGradKernel : public framework::OpKernel { zero(context.device_context(), &batch_reset_hidden_prev_grad, static_cast(0.0)); - // batch_hidden.set_lod(batch_gate->lod()); bool is_reverse = context.Attr("is_reverse"); batch_hidden_grad.set_lod(batch_hidden->lod()); - // context.ShareLoD(framework::GradVarName("Hidden"), - // framework::GradVarName("Input")); to_batch(context.device_context(), *hidden_grad, batch_hidden_grad, false, is_reverse); diff --git a/python/paddle/v2/framework/tests/test_gru_op.py b/python/paddle/v2/framework/tests/test_gru_op.py index 1c8bbabf12d9c38166c3d010a395b108532744ae..1848fb3491999a6a0d492cc93d1936a005bd7a31 100644 --- a/python/paddle/v2/framework/tests/test_gru_op.py +++ b/python/paddle/v2/framework/tests/test_gru_op.py @@ -62,7 +62,6 @@ class TestGRUOp(OpTest): return idx_in_seq_list def gru_step(self, x, h_p, w, b): - # print x.shape, h_p.shape, w.shape, b.shape batch_size = x.shape[0] frame_size = w.shape[0] g = x + np.tile(b, (batch_size, 1)) @@ -96,7 +95,6 @@ class TestGRUOp(OpTest): num_batch = len(idx_in_seq_list) end_idx = 0 for batch_idx in range(num_batch): - # print idx_in_seq_list[batch_idx] x = input[idx_in_seq_list[batch_idx]] g, r_h_p, h = self.gru_step(x, h_p, w, b) if batch_idx < (num_batch - 1): @@ -110,9 +108,8 @@ class TestGRUOp(OpTest): return batch_gate, batch_reset_hidden_prev, hidden def set_data(self): - lod = [[0, 2, 6, 9]] #[[0, 1, 2, 3]] + lod = [[0, 2, 6, 9]] self.idx_in_seq_list = self.seq_to_batch(lod, self.is_reverse) - # print self.idx_in_seq_list batch_size = self.batch_size frame_size = self.frame_size input = np.random.rand(batch_size, frame_size * 3).astype('float64')