diff --git a/paddle/fluid/operators/rnn_op.h b/paddle/fluid/operators/rnn_op.h index ab64e50d450f02afe20c37f33f19aaa6c63a5509..5e19be5e4cfe18d202d85a81c3297eeec1c84dd8 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 763ec3e7038a45df2b24a2dfdfcc75c36358d34f..79e33166bb6f8d0b0bcea036df388f1924cc1bc0 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 @@ class TestRNNOp4(TestRNNOp): 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()