Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cherry pick to 2.2.1]Fix rnn grad bug in cpu when dropout is zero (#37080) #37086

Merged
merged 1 commit into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions paddle/fluid/operators/rnn_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,9 @@ class RNNCPUKernel : public framework::OpKernel<T> {
}
dropout_mask->mutable_data<uint8_t>(output->dims(), ctx.GetPlace());

auto& dev_ctx = ctx.template device_context<platform::CPUDeviceContext>();
math::SetConstant<platform::CPUDeviceContext, uint8_t> ones;
ones(dev_ctx, dropout_mask, static_cast<uint8_t>(1));
// init the output and allocate the memory
output->mutable_data<T>(ctx.GetPlace());
int gate_num = 4;
Expand Down
30 changes: 30 additions & 0 deletions python/paddle/fluid/tests/unittests/test_rnn_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()