diff --git a/paddle/fluid/operators/rnn_op.h b/paddle/fluid/operators/rnn_op.h index ab64e50d450f0..5e19be5e4cfe1 100644 --- a/paddle/fluid/operators/rnn_op.h +++ b/paddle/fluid/operators/rnn_op.h @@ -965,6 +965,9 @@ class RNNCPUKernel : public framework::OpKernel { } dropout_mask->mutable_data(output->dims(), ctx.GetPlace()); + auto& dev_ctx = ctx.template device_context(); + math::SetConstant ones; + ones(dev_ctx, dropout_mask, static_cast(1)); // init the output and allocate the memory output->mutable_data(ctx.GetPlace()); int gate_num = 4; diff --git a/python/paddle/fluid/tests/unittests/test_rnn_op.py b/python/paddle/fluid/tests/unittests/test_rnn_op.py index 763ec3e7038a4..79e33166bb6f8 100644 --- a/python/paddle/fluid/tests/unittests/test_rnn_op.py +++ b/python/paddle/fluid/tests/unittests/test_rnn_op.py @@ -168,5 +168,35 @@ def set_attrs(self): self.is_bidirec = True +class TestRNNOp5(TestRNNOp): + def set_attrs(self): + self.num_layers = 2 + + +class TestRNNOp6(TestRNNOp): + def set_attrs(self): + self.num_layers = 2 + self.is_bidirec = True + + +class TestRNNOp7(TestRNNOp): + def set_attrs(self): + self.num_layers = 2 + self.is_bidirec = True + self.is_test = True + + +class TestRNNOp8(TestRNNOp): + def set_attrs(self): + self.num_layers = 2 + self.is_bidirec = True + self.sequence_length = None + + +class TestRNNOp9(TestRNNOp): + def set_attrs(self): + self.num_layers = 3 + + if __name__ == '__main__': unittest.main()