From 3d49882e2ce0491a247f6f97e8c83dffe1826d0b Mon Sep 17 00:00:00 2001 From: wawltor Date: Fri, 15 Jan 2021 10:51:35 +0800 Subject: [PATCH] fix the rnn mask memory bug for out of read (#30459) * fix the rnn mask memory bug for out of read * update the code for the rnn --- paddle/fluid/operators/rnn_op.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/operators/rnn_op.h b/paddle/fluid/operators/rnn_op.h index 253765bb419..b993f5ac174 100644 --- a/paddle/fluid/operators/rnn_op.h +++ b/paddle/fluid/operators/rnn_op.h @@ -960,9 +960,10 @@ class RNNCPUKernel : public framework::OpKernel { if (has_seq_length) { sequence_length = ctx.Input("SequenceLength"); } - if (!dropout_mask->IsInitialized()) { - dropout_mask->mutable_data(output->dims(), ctx.GetPlace()); + if (dropout_mask->IsInitialized()) { + if (dropout_mask->numel() != output->numel()) dropout_mask->clear(); } + dropout_mask->mutable_data(output->dims(), ctx.GetPlace()); // init the output and allocate the memory output->mutable_data(ctx.GetPlace()); -- GitLab