Skip to content

Commit

Permalink
[BUGFIX] Fallback to native implementation of RNN when use_sequence_l…
Browse files Browse the repository at this point in the history
…ength=True (apache#19466)

This PR is addressing apache#19323. I've added additional check for use_sequence_length parameter when choosing kernel to run. oneDNN does not support variable sequence length so the code right now raises an error.
  • Loading branch information
grygielski authored Nov 4, 2020
1 parent 07cd205 commit 087f6ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/operator/nn/mkldnn/mkldnn_rnn-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,11 @@ inline bool SupportMKLDNNRnn(const int input_dtype) {
return false;
}

inline bool SupportMKLDNNRnn(const RNNParam &param, const int input_dtype) {
if (param.use_sequence_length) return false;
return SupportMKLDNNRnn(input_dtype);
}

} // namespace op
} // namespace mxnet

Expand Down
6 changes: 4 additions & 2 deletions src/operator/rnn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ inline static bool RNNStorageType(const nnvm::NodeAttrs& attrs,
DispatchMode* dispatch_mode,
std::vector<int> *in_attrs,
std::vector<int> *out_attrs) {
const bool support_mkldnn_rnn = dmlc::GetEnv("MXNET_USE_MKLDNN_RNN", 1);
const RNNParam& param = nnvm::get<RNNParam>(attrs.parsed);
const bool support_mkldnn_rnn =
!param.use_sequence_length && dmlc::GetEnv("MXNET_USE_MKLDNN_RNN", 1);
return MKLDNNStorageType(attrs, dev_mask, support_mkldnn_rnn,
dispatch_mode, in_attrs, out_attrs);
}
Expand Down Expand Up @@ -244,7 +246,7 @@ static OpStatePtr CreateRNNState(const nnvm::NodeAttrs &attrs,
}

#if MXNET_USE_MKLDNN == 1
if (ctx.dev_type == kCPU && SupportMKLDNNRnn(in_types[rnn_enum::kData])) {
if (ctx.dev_type == kCPU && SupportMKLDNNRnn(param, in_types[rnn_enum::kData])) {
const mxnet::TShape& data_shape = in_shapes[rnn_enum::kData];
state = OpStatePtr::Create<MKLDNNRnnOp>(param, data_shape[0],
data_shape[1], data_shape[2]);
Expand Down

0 comments on commit 087f6ff

Please sign in to comment.