add opset14 rnn ops (#7687)

* add opset14 rnn ops

* update kernel hashes
This commit is contained in:
Ashwini Khade 2021-05-14 05:52:54 -07:00 committed by GitHub
parent 3725d0211f
commit 442c7300eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 74 additions and 32 deletions

View file

@ -825,18 +825,9 @@ namespace Microsoft.ML.OnnxRuntime.Tests
{ "test_min_int8", "node test error"},
{ "test_cast_FLOAT_to_STRING", "node test error"},
{ "test_identity_sequence", "data type not supported"},
{ "test_gru_batchwise", "opset14 version not implemented yet"},
{ "test_gru_defaults", "opset14 version not implemented yet"},
{ "test_gru_seq_length", "opset14 version not implemented yet"},
{ "test_gru_with_initial_bias", "opset14 version not implemented yet"},
{ "test_lstm_batchwise", "opset14 version not implemented yet"},
{ "test_lstm_defaults", "opset14 version not implemented yet"},
{ "test_lstm_with_initial_bias", "opset14 version not implemented yet"},
{ "test_lstm_with_peepholes", "opset14 version not implemented yet"},
{ "test_rnn_seq_length", "opset14 version not implemented yet"},
{ "test_simple_rnn_batchwise", "opset14 version not implemented yet"},
{ "test_simple_rnn_defaults", "opset14 version not implemented yet"},
{ "test_simple_rnn_with_initial_bias", "opset14 version not implemented yet"},
{ "test_gru_batchwise", "batchwise operations not supported"},
{ "test_lstm_batchwise", "batchwise operations not supported"},
{ "test_simple_rnn_batchwise", "batchwise operations not supported"},
{ "test_sub_uint8", "data type not supported"},
{ "test_mul_uint8", "data type not supported"},
{ "test_add_uint8", "data type not supported"},

View file

@ -189,9 +189,9 @@ class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOn
class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 10, int32_t, ArgMax);
class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 10, float, ArgMin);
class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 10, int32_t, ArgMin);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, GRU);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, LSTM);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, RNN);
class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, 13, GRU);
class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, 13, LSTM);
class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, 13, RNN);
class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 6, 12, Cast);
class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 4, 10, Concat);
class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 10, Gather);
@ -686,6 +686,9 @@ class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, Re
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, Identity);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, float, BatchNormalization);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, double, BatchNormalization);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, GRU);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, LSTM);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, RNN);
// !!PLEASE READ BELOW!! Following that, add new entries above this comment
@ -976,9 +979,9 @@ Status RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) {
float, ArgMin)>,
BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 10,
int32_t, ArgMin)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, GRU)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, LSTM)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, RNN)>,
BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, 13, GRU)>,
BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, 13, LSTM)>,
BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, 13, RNN)>,
BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 6, 12, Cast)>,
BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 4, 10,
Concat)>,
@ -1805,6 +1808,9 @@ Status RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) {
BatchNormalization)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, double,
BatchNormalization)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, GRU)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, LSTM)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, RNN)>,
};
for (auto& function_table_entry : function_table) {

View file

@ -138,9 +138,18 @@ Equations (Default: f=Sigmoid, g=Tanh):
namespace onnxruntime {
ONNX_CPU_OPERATOR_KERNEL(
ONNX_CPU_OPERATOR_VERSIONED_KERNEL(
GRU,
7,
13,
KernelDefBuilder().TypeConstraint("T", {DataTypeImpl::GetTensorType<float>(),
DataTypeImpl::GetTensorType<double>()})
.TypeConstraint("T1", DataTypeImpl::GetTensorType<int32_t>()),
DeepCpuGruOp);
ONNX_CPU_OPERATOR_KERNEL(
GRU,
14,
KernelDefBuilder().TypeConstraint("T", {DataTypeImpl::GetTensorType<float>(),
DataTypeImpl::GetTensorType<double>()})
.TypeConstraint("T1", DataTypeImpl::GetTensorType<int32_t>()),

View file

@ -49,6 +49,10 @@ class DeepCpuGruOp final : public OpKernel {
activation_funcs_ = rnn::detail::ActivationFuncs(activation_func_names,
activation_func_alphas,
activation_func_betas);
layout_ = info.GetAttrOrDefault("layout", static_cast<int64_t>(0));
ORT_ENFORCE(layout_ == 0,
"Batchwise recurrent operations (layout == 1) are not supported. If you need support create a github issue with justification.");
}
Status Compute(OpKernelContext* context) const override;
@ -62,6 +66,7 @@ class DeepCpuGruOp final : public OpKernel {
int hidden_size_ {};
float clip_;
int linear_before_reset_ {};
int64_t layout_;
rnn::detail::ActivationFuncs activation_funcs_;

View file

@ -156,7 +156,14 @@ Equations (Default: f=Sigmoid, g=Tanh, h=Tanh):
namespace onnxruntime {
/* LSTM operator */
ONNX_CPU_OPERATOR_KERNEL(LSTM, 7,
ONNX_CPU_OPERATOR_VERSIONED_KERNEL(LSTM, 7, 13,
KernelDefBuilder()
.TypeConstraint("T", {DataTypeImpl::GetTensorType<float>(),
DataTypeImpl::GetTensorType<double>()})
.TypeConstraint("T1", DataTypeImpl::GetTensorType<int32_t>()),
DeepCpuLstmOp);
ONNX_CPU_OPERATOR_KERNEL(LSTM, 14,
KernelDefBuilder()
.TypeConstraint("T", {DataTypeImpl::GetTensorType<float>(),
DataTypeImpl::GetTensorType<double>()})

View file

@ -13,7 +13,8 @@ namespace onnxruntime {
class LSTMBase {
protected:
LSTMBase(const OpKernelInfo& info)
: clip_(info.GetAttrOrDefault<float>("clip", std::numeric_limits<float>::max())) {
: clip_(info.GetAttrOrDefault<float>("clip", std::numeric_limits<float>::max())),
layout_(info.GetAttrOrDefault("layout", static_cast<int64_t>(0))) {
std::string direction;
ORT_ENFORCE(info.GetAttr("direction", &direction).IsOK());
@ -46,6 +47,9 @@ class LSTMBase {
activation_funcs_ = rnn::detail::ActivationFuncs(activation_func_names,
activation_func_alphas,
activation_func_betas);
ORT_ENFORCE(layout_ == 0,
"Batchwise recurrent operations (layout == 1) are not supported. If you need support create a github issue with justification.");
}
~LSTMBase() = default;
@ -70,6 +74,7 @@ class LSTMBase {
int hidden_size_ = 0;
float clip_;
bool input_forget_ = false;
int64_t layout_;
rnn::detail::ActivationFuncs activation_funcs_;
};

View file

@ -11,9 +11,18 @@
#include "core/util/math_cpuonly.h"
namespace onnxruntime {
ONNX_CPU_OPERATOR_KERNEL(
ONNX_CPU_OPERATOR_VERSIONED_KERNEL(
RNN,
7,
13,
KernelDefBuilder()
.TypeConstraint("T", DataTypeImpl::GetTensorType<float>())
.TypeConstraint("T1", DataTypeImpl::GetTensorType<int>()),
RNN<float>);
ONNX_CPU_OPERATOR_KERNEL(
RNN,
14,
KernelDefBuilder()
.TypeConstraint("T", DataTypeImpl::GetTensorType<float>())
.TypeConstraint("T1", DataTypeImpl::GetTensorType<int>()),

View file

@ -17,7 +17,8 @@ class RNN : public OpKernel {
public:
RNN(const OpKernelInfo& info) : OpKernel(info),
clip_(info.GetAttrOrDefault("clip", -1.0f)) {
clip_(info.GetAttrOrDefault("clip", -1.0f)),
layout_(info.GetAttrOrDefault("layout", static_cast<int64_t>(0))) {
ORT_ENFORCE(info.GetAttr("direction", &direction_).IsOK());
ORT_ENFORCE(allowed_directions.find(direction_) != allowed_directions.end());
const int num_directions = direction_ == "bidirectional" ? 2 : 1;
@ -39,6 +40,9 @@ class RNN : public OpKernel {
ORT_ENFORCE(allowed_activations.find(activations_[direction]) != allowed_activations.end(),
"RNN op: Invalid activation attribute - ", activations_[direction]);
}
ORT_ENFORCE(layout_ == 0,
"Batchwise recurrent operations (layout == 1) are not supported. If you need support create a github issue with justification.");
}
Status Compute(OpKernelContext* context) const override;
@ -63,6 +67,9 @@ class RNN : public OpKernel {
int64_t hidden_size_;
// const std::string default_activation = "Tanh";
// added since opset 14. Default value 0 matches the behavior prior to opset14
int64_t layout_;
};
} // namespace onnxruntime

View file

@ -879,6 +879,10 @@
"GreaterOrEqual ai.onnx CPUExecutionProvider",
17416867432093505280
],
[
"GRU ai.onnx CPUExecutionProvider",
5656895183302764352
],
[
"GRU ai.onnx CPUExecutionProvider",
2706165712066264784
@ -1083,6 +1087,10 @@
"LRN ai.onnx CPUExecutionProvider",
15047083116516536152
],
[
"LSTM ai.onnx CPUExecutionProvider",
4392316607181063320
],
[
"LSTM ai.onnx CPUExecutionProvider",
5860801277476873352
@ -2047,6 +2055,10 @@
"ReverseSequence ai.onnx CPUExecutionProvider",
777686786711298232
],
[
"RNN ai.onnx CPUExecutionProvider",
1524012948315159160
],
[
"RNN ai.onnx CPUExecutionProvider",
7150196822928564664

View file

@ -54,18 +54,9 @@
"^test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric_cpu",
// Following tests are for opset 14 ops and are not yet implemented in ORT
"^test_gru_batchwise_cpu",
"^test_gru_defaults_cpu",
"^test_gru_seq_length_cpu",
"^test_gru_with_initial_bias_cpu",
"^test_identity_sequence_cpu",
"^test_lstm_batchwise_cpu",
"^test_lstm_defaults_cpu",
"^test_lstm_with_initial_bias_cpu",
"^test_lstm_with_peepholes_cpu",
"^test_rnn_seq_length_cpu",
"^test_simple_rnn_batchwise_cpu",
"^test_simple_rnn_defaults_cpu",
"^test_simple_rnn_with_initial_bias_cpu",
"^test_sub_uint8_cpu",
"^test_mul_uint8_cpu",
"^test_add_uint8_cpu",