From 8bc532bfb9e9eee9608d5c52e68e253a68b25fbb Mon Sep 17 00:00:00 2001 From: Ashwini Khade Date: Tue, 2 Apr 2019 22:30:00 -0700 Subject: [PATCH] update onnx and add removed experimental ops to contrib ops (#723) --- cgmanifest.json | 2 +- cmake/external/onnx | 2 +- .../core/graph/contrib_ops/contrib_defs.cc | 71 +++++++++++++++++++ .../providers/cpu/activation/activations.cc | 1 + .../providers/cpu/cpu_execution_provider.cc | 2 + onnxruntime/test/onnx/main.cc | 7 +- .../test/python/onnx_backend_test_series.py | 7 ++ .../linux/docker/scripts/install_deps.sh | 4 +- 8 files changed, 91 insertions(+), 5 deletions(-) diff --git a/cgmanifest.json b/cgmanifest.json index 2991301bba..49659cec54 100644 --- a/cgmanifest.json +++ b/cgmanifest.json @@ -49,7 +49,7 @@ "component":{ "type":"git", "git":{ - "commitHash":"3a9a87871021a02d6b970c1e26ffa4c0dd720677", + "commitHash":"fdb978a580bcb461ea077b9772c973928b8dbf5f", "repositoryUrl":"https://github.com/onnx/onnx.git" } } diff --git a/cmake/external/onnx b/cmake/external/onnx index 3a9a878710..fdb978a580 160000 --- a/cmake/external/onnx +++ b/cmake/external/onnx @@ -1 +1 @@ -Subproject commit 3a9a87871021a02d6b970c1e26ffa4c0dd720677 +Subproject commit fdb978a580bcb461ea077b9772c973928b8dbf5f diff --git a/onnxruntime/core/graph/contrib_ops/contrib_defs.cc b/onnxruntime/core/graph/contrib_ops/contrib_defs.cc index e84af1256e..2daa648fa3 100644 --- a/onnxruntime/core/graph/contrib_ops/contrib_defs.cc +++ b/onnxruntime/core/graph/contrib_ops/contrib_defs.cc @@ -286,6 +286,65 @@ If scale is not provided, crop the borders as provided.)DOC"; .Output(0, "output", "Result, has same type as input, with H and W dimensions reduced.", "T") .TypeConstraint("T", {"tensor(float16)", "tensor(float)", "tensor(double)"}, "Constrain input and output types to float tensors."); + static const char* ThresholdedRelu_ver1_doc = R"DOC( +ThresholdedRelu takes one input data (Tensor) and produces one output data +(Tensor) where the rectified linear function, y = x for x > alpha, y = 0 otherwise, +is applied to the tensor elementwise. )DOC"; + + ONNX_CONTRIB_OPERATOR_SCHEMA(ThresholdedRelu) + .SinceVersion(1) + .SetDoc(ThresholdedRelu_ver1_doc) + .Attr("alpha", "Threshold value", AttributeProto::FLOAT, 1.0f) + .Input(0, "X", "Input tensor", "T") + .Output(0, "Y", "Output tensor", "T") + .TypeConstraint("T", {"tensor(float16)", "tensor(float)", "tensor(double)"}, "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction(ONNX_NAMESPACE::propagateShapeAndTypeFromFirstInput); + + static const char* DynamicSlice_ver1_doc = R"DOC( +Produces a slice of the input tensor along multiple axes. Similar to numpy: +https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html +Slices uses `axes`, `starts` and `ends` inputs to specify the start and end +dimension for each axis in the list of axes, it uses this information to +slice the input `data` tensor. If a negative value is passed for any of the +start or end indices, it represent number of elements before the end of that +dimension. If the value passed to start or end is larger than the `n` (the +number of elements in this dimension), it represents `n`. For slicing to the +end of a dimension with unknown size, it is recommended to pass in `INT_MAX`. +If `axes` are omitted, they are set to `[0, ..., ndim-1]`. +Example 1: + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + axes = [0, 1] + starts = [1, 0] + ends = [2, 3] + result = [ + [5, 6, 7], + ] +Example 2: + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + starts = [0, 1] + ends = [-1, 1000] + result = [ + [2, 3, 4], + ] +)DOC"; + + ONNX_CONTRIB_OPERATOR_SCHEMA(DynamicSlice) + .SinceVersion(1) + .SetDoc(DynamicSlice_ver1_doc) + .Input(0, "data", "Tensor of data to extract slices from.", "T") + .Input(1, "starts", "1-D tensor of starting indices of corresponding axis in `axes`", "Tind") + .Input(2, "ends", "1-D tensor of ending indices (exclusive) of corresponding axis in axes", "Tind") + .Input(3, "axes", "1-D tensor of axes that `starts` and `ends` apply to.", "Tind", OpSchema::Optional) + .Output(0, "output", "Sliced data tensor.", "T") + .TypeConstraint("T", OpSchema::all_tensor_types(), "Constrain input and output types to all tensor types.") + .TypeConstraint("Tind", {"tensor(int32)", "tensor(int64)"}, "Constrain indices to integer types"); + ONNX_CONTRIB_OPERATOR_SCHEMA(Affine) .SinceVersion(10) .Deprecate() @@ -332,6 +391,18 @@ If scale is not provided, crop the borders as provided.)DOC"; .Output(0, "output", "Result, has same type as input, with H and W dimensions reduced.", "T") .TypeConstraint("T", {"tensor(float16)", "tensor(float)", "tensor(double)"}, "Constrain input and output types to float tensors."); + ONNX_CONTRIB_OPERATOR_SCHEMA(DynamicSlice) + .SinceVersion(10) + .Deprecate() + .SetDoc(DynamicSlice_ver1_doc) + .Input(0, "data", "Tensor of data to extract slices from.", "T") + .Input(1, "starts", "1-D tensor of starting indices of corresponding axis in `axes`", "Tind") + .Input(2, "ends", "1-D tensor of ending indices (exclusive) of corresponding axis in axes", "Tind") + .Input(3, "axes", "1-D tensor of axes that `starts` and `ends` apply to.", "Tind", OpSchema::Optional) + .Output(0, "output", "Sliced data tensor.", "T") + .TypeConstraint("T", OpSchema::all_tensor_types(), "Constrain input and output types to all tensor types.") + .TypeConstraint("Tind", {"tensor(int32)", "tensor(int64)"}, "Constrain indices to integer types"); + // End of ONNX exp ops(Affine, Crop, ParametricSoftplus, ImageScaler) old version history maintainance ONNX_CONTRIB_OPERATOR_SCHEMA(SampleOp) diff --git a/onnxruntime/core/providers/cpu/activation/activations.cc b/onnxruntime/core/providers/cpu/activation/activations.cc index 145831ec99..cbdaaceb8d 100644 --- a/onnxruntime/core/providers/cpu/activation/activations.cc +++ b/onnxruntime/core/providers/cpu/activation/activations.cc @@ -29,6 +29,7 @@ REGISTER_UNARY_ELEMENTWISE_KERNEL_ALIAS(Softplus, ParametricSoftplus, 1); REGISTER_UNARY_ELEMENTWISE_KERNEL(Softsign, 1); REGISTER_UNARY_ELEMENTWISE_KERNEL(Tanh, 6); REGISTER_UNARY_ELEMENTWISE_KERNEL(ThresholdedRelu, 1); +REGISTER_UNARY_ELEMENTWISE_KERNEL(ThresholdedRelu, 10); template <> Status Sigmoid::Compute(OpKernelContext* context) const { diff --git a/onnxruntime/core/providers/cpu/cpu_execution_provider.cc b/onnxruntime/core/providers/cpu/cpu_execution_provider.cc index 979788c38b..3fc0dc7122 100644 --- a/onnxruntime/core/providers/cpu/cpu_execution_provider.cc +++ b/onnxruntime/core/providers/cpu/cpu_execution_provider.cc @@ -262,6 +262,7 @@ class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, // Opset 10 class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, StringNormalizer); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, TopK); +class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, ThresholdedRelu); void RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) { kernel_registry.Register(BuildKernelCreateInfo()); @@ -513,6 +514,7 @@ void RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) { // Opset 10 kernel_registry.Register(BuildKernelCreateInfo()); kernel_registry.Register(BuildKernelCreateInfo()); + kernel_registry.Register(BuildKernelCreateInfo()); } // Forward declarations of ml op kernels diff --git a/onnxruntime/test/onnx/main.cc b/onnxruntime/test/onnx/main.cc index e68d94845e..84bc5fab5a 100644 --- a/onnxruntime/test/onnx/main.cc +++ b/onnxruntime/test/onnx/main.cc @@ -318,7 +318,12 @@ int real_main(int argc, char* argv[], OrtEnv** p_env) { {"tf_inception_v4", "Cast opset 9 not supported yet"}, {"tf_nasnet_large", "disable temporarily"}, {"tf_nasnet_mobile", "disable temporarily"}, - {"tf_pnasnet_large", "disable temporarily"}}; + {"tf_pnasnet_large", "disable temporarily"}, + {"slice", "Slice opset 10 not supported yet"}, + {"slice_neg", "Slice opset 10 not supported yet"}, + {"slice_start_out_of_bounds", "Slice opset 10 not supported yet"}, + {"slice_end_out_of_bounds", "Slice opset 10 not supported yet"}, + {"slice_default_axes", "Slice opset 10 not supported yet"}}; #ifdef USE_CUDA broken_tests["maxpool_2d_default"] = "cudnn pooling only support input dimension >= 3"; diff --git a/onnxruntime/test/python/onnx_backend_test_series.py b/onnxruntime/test/python/onnx_backend_test_series.py index ab6880ff2f..cdda888cbb 100644 --- a/onnxruntime/test/python/onnx_backend_test_series.py +++ b/onnxruntime/test/python/onnx_backend_test_series.py @@ -83,6 +83,13 @@ backend_test.exclude(r'(' '|^test_vgg19_cpu.*' '|^test_zfnet512_cpu.*' '|^test_gru_seq_length_cpu.*' +'|^test_slice_cpu.*' +'|^test_slice_default_axes_cpu.*' +'|^test_slice_default_steps_cpu.*' +'|^test_slice_end_out_of_bounds_cpu.*' +'|^test_slice_neg_cpu.*' +'|^test_slice_neg_steps_cpu.*' +'|^test_slice_start_out_of_bounds_cpu.*' ')') # import all test cases at global scope to make diff --git a/tools/ci_build/github/linux/docker/scripts/install_deps.sh b/tools/ci_build/github/linux/docker/scripts/install_deps.sh index 083b5d178d..ca333cc6e4 100755 --- a/tools/ci_build/github/linux/docker/scripts/install_deps.sh +++ b/tools/ci_build/github/linux/docker/scripts/install_deps.sh @@ -38,8 +38,8 @@ else #5af210ca8a1c73aa6bae8754c9346ec54d0a756e is v1.2.3 #bae6333e149a59a3faa9c4d9c44974373dcf5256 is v1.3.0 #9e55ace55aad1ada27516038dfbdc66a8a0763db is v1.4.1 - #3a9a87871021a02d6b970c1e26ffa4c0dd720677 is v1.4.1 latest - for onnx_version in "5af210ca8a1c73aa6bae8754c9346ec54d0a756e" "bae6333e149a59a3faa9c4d9c44974373dcf5256" "9e55ace55aad1ada27516038dfbdc66a8a0763db" "3a9a87871021a02d6b970c1e26ffa4c0dd720677"; do + #fdb978a580bcb461ea077b9772c973928b8dbf5f" is v1.4.1 latest + for onnx_version in "5af210ca8a1c73aa6bae8754c9346ec54d0a756e" "bae6333e149a59a3faa9c4d9c44974373dcf5256" "9e55ace55aad1ada27516038dfbdc66a8a0763db" "fdb978a580bcb461ea077b9772c973928b8dbf5f" ; do if [ -z ${lastest_onnx_version+x} ]; then echo "first pass"; else