You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by zh...@apache.org on 2021/04/08 21:10:21 UTC
[incubator-mxnet] branch v1.x updated: [v1.x] Add mx2onnx operator
support matrix (#20139)
This is an automated email from the ASF dual-hosted git repository.
zha0q1 pushed a commit to branch v1.x
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/v1.x by this push:
new 24159ca [v1.x] Add mx2onnx operator support matrix (#20139)
24159ca is described below
commit 24159ca95bba8025d07a4b6ca59b821ed6094f3b
Author: Zhaoqi Zhu <zh...@gmail.com>
AuthorDate: Thu Apr 8 14:08:26 2021 -0700
[v1.x] Add mx2onnx operator support matrix (#20139)
* update lowest opset from 11 to 12. add api get_operator_support
* add operator matrix
* fix
* rename op_translation
* add whitelist
* fix
---
python/mxnet/onnx/README.md | 150 ++++++++++++++++++++-
python/mxnet/onnx/__init__.py | 2 +-
python/mxnet/onnx/mx2onnx/__init__.py | 4 +-
python/mxnet/onnx/mx2onnx/_export_model.py | 20 +++
python/mxnet/onnx/mx2onnx/_export_onnx.py | 6 +-
...ions_opset11.py => _op_translations_opset12.py} | 0
tools/license_header.py | 2 +-
tools/onnx/generate_op_support_matrix.py | 47 +++++++
8 files changed, 223 insertions(+), 8 deletions(-)
diff --git a/python/mxnet/onnx/README.md b/python/mxnet/onnx/README.md
index e46a332..48da01f 100644
--- a/python/mxnet/onnx/README.md
+++ b/python/mxnet/onnx/README.md
@@ -30,7 +30,155 @@ If you are a user of earlier MXNet versions and do not want to upgrade MXNet, yo
### APIs
-### Operator Support Matrix - ONNX 1.7
+### Operator Support Matrix
+|MXNet Op|ONNX Version|
+|:-|:-:|
+|Activation|1.7 1.8 |
+|BatchNorm|1.7 1.8 |
+|BlockGrad|1.7 1.8 |
+|Cast|1.7 1.8 |
+|Concat|1.7 1.8 |
+|Convolution|1.7 1.8 |
+|Crop|1.7 1.8 |
+|Deconvolution|1.7 1.8 |
+|Dropout|1.7 1.8 |
+|Embedding|1.7 1.8 |
+|Flatten|1.7 1.8 |
+|FullyConnected|1.7 1.8 |
+|InstanceNorm|1.7 1.8 |
+|L2Normalization|1.7 1.8 |
+|LRN|1.7 1.8 |
+|LayerNorm|1.7 1.8 |
+|LeakyReLU|1.7 1.8 |
+|LogisticRegressionOutput|1.7 1.8 |
+|MakeLoss|1.7 1.8 |
+|Pad|1.7 1.8 |
+|Pooling|1.7 1.8 |
+|RNN|1.7 1.8 |
+|ROIPooling|1.7 1.8 |
+|Reshape|1.7 1.8 |
+|SequenceMask|1.7 1.8 |
+|SequenceReverse|1.7 1.8 |
+|SliceChannel|1.7 1.8 |
+|SoftmaxOutput|1.7 1.8 |
+|SwapAxis|1.7 1.8 |
+|UpSampling|1.7 1.8 |
+|_arange|1.7 1.8 |
+|_contrib_AdaptiveAvgPooling2D|1.7 1.8 |
+|_contrib_BilinearResize2D|1.7 1.8 |
+|_contrib_ROIAlign|1.7 1.8 |
+|_contrib_arange_like|1.7 1.8 |
+|_contrib_box_decode|1.7 1.8 |
+|_contrib_box_nms|1.7 1.8 |
+|_contrib_div_sqrt_dim|1.7 1.8 |
+|_contrib_interleaved_matmul_selfatt_qk|1.7 1.8 |
+|_contrib_interleaved_matmul_selfatt_valatt|1.7 1.8 |
+|_copy|1.7 1.8 |
+|_div_scalar|1.7 1.8 |
+|_equal_scalar|1.7 1.8 |
+|_greater_scalar|1.7 1.8 |
+|_lesser_scalar|1.7 1.8 |
+|_linalg_gemm2|1.7 1.8 |
+|_maximum|1.7 1.8 |
+|_maximum_scalar|1.7 1.8 |
+|_minimum|1.7 1.8 |
+|_minimum_scalar|1.7 1.8 |
+|_minus_scalar|1.7 1.8 |
+|_mul_scalar|1.7 1.8 |
+|_ones|1.7 1.8 |
+|_plus_scalar|1.7 1.8 |
+|_power|1.7 1.8 |
+|_power_scalar|1.7 1.8 |
+|_random_normal|1.7 1.8 |
+|_random_uniform|1.7 1.8 |
+|_random_uniform_like|1.7 1.8 |
+|_rdiv_scalar|1.7 1.8 |
+|_rminus_scalar|1.7 1.8 |
+|_rnn_param_concat|1.7 1.8 |
+|_sample_multinomial|1.7 1.8 |
+|_zeros|1.7 1.8 |
+|abs|1.7 1.8 |
+|add_n|1.7 1.8 |
+|arccos|1.7 1.8 |
+|arcsin|1.7 1.8 |
+|arctan|1.7 1.8 |
+|argmax|1.7 1.8 |
+|argmin|1.7 1.8 |
+|argsort|1.7 1.8 |
+|batch_dot|1.7 1.8 |
+|broadcast_add|1.7 1.8 |
+|broadcast_axis|1.7 1.8 |
+|broadcast_div|1.7 1.8 |
+|broadcast_equal|1.7 1.8 |
+|broadcast_greater|1.7 1.8 |
+|broadcast_greater_equal|1.7 1.8 |
+|broadcast_lesser|1.7 1.8 |
+|broadcast_lesser_equal|1.7 1.8 |
+|broadcast_like|1.7 1.8 |
+|broadcast_logical_and|1.7 1.8 |
+|broadcast_logical_or|1.7 1.8 |
+|broadcast_logical_xor|1.7 1.8 |
+|broadcast_minimum|1.7 1.8 |
+|broadcast_mod|1.7 1.8 |
+|broadcast_mul|1.7 1.8 |
+|broadcast_power|1.7 1.8 |
+|broadcast_sub|1.7 1.8 |
+|broadcast_to|1.7 1.8 |
+|ceil|1.7 1.8 |
+|clip|1.7 1.8 |
+|cos|1.7 1.8 |
+|depth_to_space|1.7 1.8 |
+|dot|1.7 1.8 |
+|elemwise_add|1.7 1.8 |
+|elemwise_div|1.7 1.8 |
+|elemwise_mul|1.7 1.8 |
+|elemwise_sub|1.7 1.8 |
+|exp|1.7 1.8 |
+|expand_dims|1.7 1.8 |
+|floor|1.7 1.8 |
+|gather_nd|1.7 1.8 |
+|hard_sigmoid|1.7 1.8 |
+|identity|1.7 1.8 |
+|log|1.7 1.8 |
+|log2|1.7 1.8 |
+|log_softmax|1.7 1.8 |
+|logical_not|1.7 1.8 |
+|max|1.7 1.8 |
+|mean|1.7 1.8 |
+|min|1.7 1.8 |
+|negative|1.7 1.8 |
+|norm|1.7 1.8 |
+|null|1.7 1.8 |
+|one_hot|1.7 1.8 |
+|ones_like|1.7 1.8 |
+|prod|1.7 1.8 |
+|reciprocal|1.7 1.8 |
+|relu|1.7 1.8 |
+|repeat|1.7 1.8 |
+|reshape_like|1.7 1.8 |
+|reverse|1.7 1.8 |
+|shape_array|1.7 1.8 |
+|sigmoid|1.7 1.8 |
+|sin|1.7 1.8 |
+|size_array|1.7 1.8 |
+|slice|1.7 1.8 |
+|slice_axis|1.7 1.8 |
+|slice_like|1.7 1.8 |
+|softmax|1.7 1.8 |
+|space_to_depth|1.7 1.8 |
+|sqrt|1.7 1.8 |
+|square|1.7 1.8 |
+|squeeze|1.7 1.8 |
+|stack|1.7 1.8 |
+|sum|1.7 1.8 |
+|take|1.7 1.8 |
+|tan|1.7 1.8 |
+|tanh|1.7 1.8 |
+|tile|1.7 1.8 |
+|topk|1.7 1.8 |
+|transpose|1.7 1.8 |
+|where|1.7 1.8 |
+|zeros_like|1.7 1.8 |
### GluonCV Pretrained Model Support Matrix
diff --git a/python/mxnet/onnx/__init__.py b/python/mxnet/onnx/__init__.py
index 3caab21..85b81b3 100644
--- a/python/mxnet/onnx/__init__.py
+++ b/python/mxnet/onnx/__init__.py
@@ -18,4 +18,4 @@
# coding: utf-8
"""ONNX Export module"""
-from .mx2onnx import export_model
+from .mx2onnx import export_model, get_operator_support
diff --git a/python/mxnet/onnx/mx2onnx/__init__.py b/python/mxnet/onnx/mx2onnx/__init__.py
index 20d110e..339d74d 100644
--- a/python/mxnet/onnx/mx2onnx/__init__.py
+++ b/python/mxnet/onnx/mx2onnx/__init__.py
@@ -18,6 +18,6 @@
# coding: utf-8
"""ONNX Export module"""
-from ._export_model import export_model
-from ._op_translations import _op_translations_opset11
+from ._export_model import export_model, get_operator_support
+from ._op_translations import _op_translations_opset12
from ._op_translations import _op_translations_opset13
diff --git a/python/mxnet/onnx/mx2onnx/_export_model.py b/python/mxnet/onnx/mx2onnx/_export_model.py
index 687899b..b960282 100644
--- a/python/mxnet/onnx/mx2onnx/_export_model.py
+++ b/python/mxnet/onnx/mx2onnx/_export_model.py
@@ -28,6 +28,26 @@ from ._export_onnx import MXNetGraph
from ._export_helper import load_module
+def get_operator_support(opset_version=None):
+ """Return a list of MXNet operators supported by the current/specified opset
+ """
+ try:
+ from onnx.defs import onnx_opset_version
+ except ImportError:
+ raise ImportError("Onnx and protobuf need to be installed. "
+ + "Instructions to install - https://github.com/onnx/onnx")
+ if opset_version is None:
+ opset_version = onnx_opset_version()
+ all_versions = range(opset_version, 11, -1)
+ ops = set()
+ for ver in all_versions:
+ if ver in MXNetGraph.registry_:
+ ops.update(MXNetGraph.registry_[ver].keys())
+ ops = list(ops)
+ ops.sort()
+ return ops
+
+
def export_model(sym, params, in_shapes=None, in_types=np.float32,
onnx_file_path='model.onnx', verbose=False, dynamic=False,
dynamic_input_shapes=None, run_shape_inference=False, input_type=None,
diff --git a/python/mxnet/onnx/mx2onnx/_export_onnx.py b/python/mxnet/onnx/mx2onnx/_export_onnx.py
index 8bcb7a6..307095b 100644
--- a/python/mxnet/onnx/mx2onnx/_export_onnx.py
+++ b/python/mxnet/onnx/mx2onnx/_export_onnx.py
@@ -66,7 +66,7 @@ class MXNetGraph(object):
self.output_tensors = []
@staticmethod
- def register(op_name, opset_version=11):
+ def register(op_name, opset_version=12):
"""Register operators"""
def wrapper(func):
"""Helper function to map functions"""
@@ -92,9 +92,9 @@ class MXNetGraph(object):
op = str(node["op"])
opset_version = kwargs.get("opset_version", onnx_opset_version())
# fallback to older opset versions if op is not registered in current version
- for op_version in range(opset_version, 10, -1):
+ for op_version in range(opset_version, 11, -1):
if op_version not in MXNetGraph.registry_ or op not in MXNetGraph.registry_[op_version]:
- if opset_version == 11:
+ if opset_version == 12:
raise AttributeError("No conversion function registered for op type %s yet." % op)
continue
convert_func = MXNetGraph.registry_[op_version][op]
diff --git a/python/mxnet/onnx/mx2onnx/_op_translations/_op_translations_opset11.py b/python/mxnet/onnx/mx2onnx/_op_translations/_op_translations_opset12.py
similarity index 100%
rename from python/mxnet/onnx/mx2onnx/_op_translations/_op_translations_opset11.py
rename to python/mxnet/onnx/mx2onnx/_op_translations/_op_translations_opset12.py
diff --git a/tools/license_header.py b/tools/license_header.py
index 0e42f79..387c444 100755
--- a/tools/license_header.py
+++ b/tools/license_header.py
@@ -125,7 +125,7 @@ _WHITE_LIST = [
# Dual-Licensed under Apache 2.0 and Nvidia BSD-3
'python/mxnet/onnx/mx2onnx/_export_onnx.py',
'python/mxnet/onnx/mx2onnx/_op_translations.py',
- 'python/mxnet/onnx/mx2onnx/_op_translations/_op_translations_opset11.py',
+ 'python/mxnet/onnx/mx2onnx/_op_translations/_op_translations_opset12.py',
'python/mxnet/onnx/mx2onnx/_op_translations/_op_translations_opset13.py',
# Github template
diff --git a/tools/onnx/generate_op_support_matrix.py b/tools/onnx/generate_op_support_matrix.py
new file mode 100644
index 0000000..b57af66
--- /dev/null
+++ b/tools/onnx/generate_op_support_matrix.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import mxnet as mx
+
+# Need to update here
+opset_to_onnx = {
+ 12 : '1.7',
+ 13 : '1.8',
+}
+
+def generate_op_support_matrix(opset):
+ all_versions = range(12, opset+1, 1)
+ from collections import defaultdict
+ support = defaultdict(lambda: '')
+ for ver in all_versions:
+ ops = mx.onnx.get_operator_support(ver)
+ for op in ops:
+ support[op] += '%s ' % opset_to_onnx.get(ver, 'unknown version')
+ md_string = '|MXNet Op|ONNX Version|\n|:-|:-:|\n'
+ for i in support.items():
+ md_string += '|%s|%s|\n' % i
+ try:
+ file_name = './op_support_matrix.md'
+ with open(file_name, 'w') as f:
+ f.write(md_string)
+ except Exception as e:
+ print('Error writing to file')
+
+# Change the parameter to the highest ONNX version supported
+generate_op_support_matrix(13)