From 816c18a22b3dee566792e393b59dcde849ef4d9d Mon Sep 17 00:00:00 2001 From: Qiao Longfei Date: Sun, 6 Jan 2019 17:44:40 +0800 Subject: [PATCH] update test_gru_unit_op --- .../fluid/tests/unittests/test_gru_unit_op.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_gru_unit_op.py b/python/paddle/fluid/tests/unittests/test_gru_unit_op.py index b5a66fdf086..fdc6b75dbda 100644 --- a/python/paddle/fluid/tests/unittests/test_gru_unit_op.py +++ b/python/paddle/fluid/tests/unittests/test_gru_unit_op.py @@ -71,7 +71,7 @@ class TestGRUUnitOp(OpTest): 'gate_activation': GRUActivationType.sigmoid } - def set_outputs(self): + def set_outputs(self, origin_mode=False): # GRU calculations batch_size = self.batch_size frame_size = self.frame_size @@ -93,7 +93,10 @@ class TestGRUUnitOp(OpTest): c = self.activate[self.attrs['activation']](np.dot(r_h_p, w_c) + g[:, frame_size * 2:]) g = np.hstack((u_r, c)) - h = u * c + (1 - u) * h_p + if origin_mode: + h = (1 - u) * c + u * h_p + else: + h = u * c + (1 - u) * h_p self.outputs = { 'Gate': g.astype('float64'), 'ResetHiddenPrev': r_h_p.astype('float64'), @@ -111,6 +114,12 @@ class TestGRUUnitOp(OpTest): self.check_grad(['Input', 'HiddenPrev', 'Weight'], ['Hidden']) +class TestGRUUnitOpOriginMode(TestGRUUnitOp): + def setUp(self): + self.set_inputs() + self.set_outputs(origin_mode=True) + + class TestGRUUnitOpWithBias(TestGRUUnitOp): def set_inputs(self): batch_size = self.batch_size @@ -132,5 +141,11 @@ class TestGRUUnitOpWithBias(TestGRUUnitOp): no_grad_set=set('Input')) +class TestGRUUnitOpWithBiasOriginMode(TestGRUUnitOpWithBias): + def setUp(self): + self.set_inputs() + self.set_outputs(origin_mode=True) + + if __name__ == '__main__': unittest.main() -- GitLab