You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2021/02/05 18:33:08 UTC

[GitHub] [incubator-mxnet] waytrue17 opened a new pull request #19851: [v1.x] ONNX export rewrite Take

waytrue17 opened a new pull request #19851:
URL: https://github.com/apache/incubator-mxnet/pull/19851


   ## Description ##
   ONNX export rewrite Take + unittest
   ## Checklist ##
   ### Essentials ###
   - [ ] PR's title starts with a category (e.g. [BUGFIX], [MODEL], [TUTORIAL], [FEATURE], [DOC], etc)
   - [ ] Changes are complete (i.e. I finished coding on this PR)
   - [ ] All changes have test coverage
   - [ ] Code is well-documented
   
   ### Changes ###
   - [ ] Feature1, tests, (and when applicable, API doc)
   - [ ] Feature2, tests, (and when applicable, API doc)
   
   ## Comments ##
   - If this change is a backward incompatible change, why must this change be made.
   - Interesting edge cases to note here
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] Zha0q1 commented on a change in pull request #19851: [v1.x] ONNX export rewrite Take

Posted by GitBox <gi...@apache.org>.
Zha0q1 commented on a change in pull request #19851:
URL: https://github.com/apache/incubator-mxnet/pull/19851#discussion_r571194134



##########
File path: python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
##########
@@ -2386,18 +2386,67 @@ def convert_topk(node, **kwargs):
 def convert_take(node, **kwargs):
     """Map MXNet's Take operator attributes to onnx's Gather operator.
     """
+    from onnx.helper import make_node
+    from onnx import TensorProto
     name, input_nodes, attrs = get_inputs(node, kwargs)
-
     axis = int(attrs.get('axis', 0))
+    mode = str(attrs.get('mode', 'clip'))
 
-    node = onnx.helper.make_node(
-        "Gather",
-        input_nodes,
-        [name],
-        axis=axis,
-        name=name,
-    )
-    return [node]
+    data = input_nodes[0]
+    indices = input_nodes[1]
+
+    nodes = [
+        make_node('Cast', [indices], [name+'_indices'], to=int(TensorProto.INT64)),
+    ]
+
+    if mode == 'raise':
+        nodes += [
+            make_node('Gather', [data, name+'_indices'], [name], axis=axis, name=name)
+        ]
+
+        return nodes
+
+    nodes += [
+        create_tensor([-1], name+'_-1', kwargs["initializer"]),
+        make_node('Shape', [data], [name+'_data_shape']),
+    ]
+
+    # cornor case

Review comment:
       nit: corner : )




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] Zha0q1 commented on a change in pull request #19851: [v1.x] ONNX export rewrite Take

Posted by GitBox <gi...@apache.org>.
Zha0q1 commented on a change in pull request #19851:
URL: https://github.com/apache/incubator-mxnet/pull/19851#discussion_r571195335



##########
File path: tests/python-pytest/onnx/test_operators.py
##########
@@ -927,3 +927,15 @@ def test_onnx_export_convolution(tmp_path, dtype, shape, num_filter, num_group,
                   **kwargs)
     inputs = [x, w] if no_bias else [x, w, b]
     op_export_test('convolution', M, inputs, tmp_path)
+
+
+@pytest.mark.parametrize('dtype', ['int32', 'int64', 'float16', 'float32', 'float64'])
+@pytest.mark.parametrize('axis', [-3, -2, -1, 0, 1, 2])
+@pytest.mark.parametrize('mode', ['clip', 'wrap'])

Review comment:
       Shall we also test raise mode/




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #19851: [v1.x] ONNX export rewrite Take

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #19851:
URL: https://github.com/apache/incubator-mxnet/pull/19851#issuecomment-779440477


   Jenkins CI successfully triggered : [centos-gpu, unix-cpu, website]


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] josephevans commented on a change in pull request #19851: [v1.x] ONNX export rewrite Take

Posted by GitBox <gi...@apache.org>.
josephevans commented on a change in pull request #19851:
URL: https://github.com/apache/incubator-mxnet/pull/19851#discussion_r571333899



##########
File path: tests/python-pytest/onnx/test_operators.py
##########
@@ -927,3 +927,15 @@ def test_onnx_export_convolution(tmp_path, dtype, shape, num_filter, num_group,
                   **kwargs)
     inputs = [x, w] if no_bias else [x, w, b]
     op_export_test('convolution', M, inputs, tmp_path)
+
+
+@pytest.mark.parametrize('dtype', ['int32', 'int64', 'float16', 'float32', 'float64'])
+@pytest.mark.parametrize('axis', [-3, -2, -1, 0, 1, 2])
+@pytest.mark.parametrize('mode', ['clip', 'wrap'])

Review comment:
       We can split it into multiple tests, one test just for 'raise' mode and the other tests the 'clip' and 'wrap' modes, since the parametrized options will be different. 
   
   Sorta like this:
   https://github.com/apache/incubator-mxnet/pull/19855/files#diff-30a9f0d694eb3951b810ec760f714b3873ab4453e685620b1571991e644aae3cR859-R881




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] Zha0q1 merged pull request #19851: [v1.x] ONNX export rewrite Take

Posted by GitBox <gi...@apache.org>.
Zha0q1 merged pull request #19851:
URL: https://github.com/apache/incubator-mxnet/pull/19851


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] waytrue17 commented on a change in pull request #19851: [v1.x] ONNX export rewrite Take

Posted by GitBox <gi...@apache.org>.
waytrue17 commented on a change in pull request #19851:
URL: https://github.com/apache/incubator-mxnet/pull/19851#discussion_r571221194



##########
File path: python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
##########
@@ -2386,18 +2386,67 @@ def convert_topk(node, **kwargs):
 def convert_take(node, **kwargs):
     """Map MXNet's Take operator attributes to onnx's Gather operator.
     """
+    from onnx.helper import make_node
+    from onnx import TensorProto
     name, input_nodes, attrs = get_inputs(node, kwargs)
-
     axis = int(attrs.get('axis', 0))
+    mode = str(attrs.get('mode', 'clip'))
 
-    node = onnx.helper.make_node(
-        "Gather",
-        input_nodes,
-        [name],
-        axis=axis,
-        name=name,
-    )
-    return [node]
+    data = input_nodes[0]
+    indices = input_nodes[1]
+
+    nodes = [
+        make_node('Cast', [indices], [name+'_indices'], to=int(TensorProto.INT64)),
+    ]
+
+    if mode == 'raise':
+        nodes += [
+            make_node('Gather', [data, name+'_indices'], [name], axis=axis, name=name)
+        ]
+
+        return nodes
+
+    nodes += [
+        create_tensor([-1], name+'_-1', kwargs["initializer"]),
+        make_node('Shape', [data], [name+'_data_shape']),
+    ]
+
+    # cornor case

Review comment:
       good catch!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] waytrue17 commented on pull request #19851: [v1.x] ONNX export rewrite Take

Posted by GitBox <gi...@apache.org>.
waytrue17 commented on pull request #19851:
URL: https://github.com/apache/incubator-mxnet/pull/19851#issuecomment-779440460


   @mxnet-bot run ci [centos-gpu, unix-cpu, website]


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #19851: [v1.x] ONNX export rewrite Take

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #19851:
URL: https://github.com/apache/incubator-mxnet/pull/19851#issuecomment-774210097


   Hey @waytrue17 , Thanks for submitting the PR 
   All tests are already queued to run once. If tests fail, you can trigger one or more tests again with the following commands: 
   - To trigger all jobs: @mxnet-bot run ci [all] 
   - To trigger specific jobs: @mxnet-bot run ci [job1, job2] 
   *** 
   **CI supported jobs**: [clang, website, centos-gpu, windows-cpu, sanity, windows-gpu, unix-cpu, edge, unix-gpu, centos-cpu, miscellaneous]
   *** 
   _Note_: 
    Only following 3 categories can trigger CI :PR Author, MXNet Committer, Jenkins Admin. 
   All CI tests must pass before the PR can be merged. 
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-mxnet] waytrue17 commented on a change in pull request #19851: [v1.x] ONNX export rewrite Take

Posted by GitBox <gi...@apache.org>.
waytrue17 commented on a change in pull request #19851:
URL: https://github.com/apache/incubator-mxnet/pull/19851#discussion_r571220223



##########
File path: tests/python-pytest/onnx/test_operators.py
##########
@@ -927,3 +927,15 @@ def test_onnx_export_convolution(tmp_path, dtype, shape, num_filter, num_group,
                   **kwargs)
     inputs = [x, w] if no_bias else [x, w, b]
     op_export_test('convolution', M, inputs, tmp_path)
+
+
+@pytest.mark.parametrize('dtype', ['int32', 'int64', 'float16', 'float32', 'float64'])
+@pytest.mark.parametrize('axis', [-3, -2, -1, 0, 1, 2])
+@pytest.mark.parametrize('mode', ['clip', 'wrap'])

Review comment:
       The raise mode will raise an error when indices out of bound. Do you have suggestions how we can test it?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org