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/05/24 18:14:54 UTC

[incubator-mxnet] branch v1.x updated: fix embedding dtype and output order (#20295)

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 f8d4b24  fix embedding dtype and output order (#20295)
f8d4b24 is described below

commit f8d4b24a8574103d6ea17c353b03836df5db5543
Author: waytrue17 <52...@users.noreply.github.com>
AuthorDate: Mon May 24 11:13:23 2021 -0700

    fix embedding dtype and output order (#20295)
    
    Co-authored-by: Wei Chu <we...@amazon.com>
---
 python/mxnet/onnx/mx2onnx/_export_onnx.py                   | 13 +++++++++++--
 .../mx2onnx/_op_translations/_op_translations_opset12.py    |  3 ++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/python/mxnet/onnx/mx2onnx/_export_onnx.py b/python/mxnet/onnx/mx2onnx/_export_onnx.py
index 0556078..1349381 100644
--- a/python/mxnet/onnx/mx2onnx/_export_onnx.py
+++ b/python/mxnet/onnx/mx2onnx/_export_onnx.py
@@ -392,8 +392,17 @@ class MXNetGraph(object):
                 # if node_output_names is empty then we use the last returned node as output
                 if not node_output_names:
                     node_output_names = [converted[-1].name]
-                # process node outputs (sort by alphabetical order)
-                node_output_names.sort()
+                # process node outputs (sort by output index)
+                def str2int(s):
+                    import re
+                    i = re.search(r'\d{0,2}$', s).group()
+                    if i == '':
+                        return 0
+                    else:
+                        return int(i)
+
+                sorted(node_output_names, key=str2int)
+
                 # match the output names to output dtypes
                 if dtypes is not None:
                     assert len(node_output_names) == len(dtypes)
diff --git a/python/mxnet/onnx/mx2onnx/_op_translations/_op_translations_opset12.py b/python/mxnet/onnx/mx2onnx/_op_translations/_op_translations_opset12.py
index deda791..cd4728e 100644
--- a/python/mxnet/onnx/mx2onnx/_op_translations/_op_translations_opset12.py
+++ b/python/mxnet/onnx/mx2onnx/_op_translations/_op_translations_opset12.py
@@ -3088,13 +3088,14 @@ def convert_embedding(node, **kwargs):
 
     name, input_nodes, attrs = get_inputs(node, kwargs)
     axis = int(attrs.get('axis', 0))
+    dtype = str(attrs.get('dtype', 'float32'))
 
     nodes = [
         make_node('Cast', [input_nodes[0]], [name+'_indices_casted'], to=int(TensorProto.INT64)),
         make_node('Gather', [input_nodes[1], name+'_indices_casted'], [name], axis=axis, name=name)
     ]
 
-    return nodes
+    return nodes, (dtype, )
 
 
 @mx_op.register("stack")