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/01/15 21:51:54 UTC
[GitHub] [incubator-mxnet] Zha0q1 opened a new pull request #19761: [v1.x] ONNX conversion for _maximum_scalar
Zha0q1 opened a new pull request #19761:
URL: https://github.com/apache/incubator-mxnet/pull/19761
There is one limitation: because we do not know the dtype of the tensor input, so we have to use the global input dtype for creating the scalar input. So if those two types do not match this will not work
----------------------------------------------------------------
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 #19761: [wip][v1.x] ONNX conversion for topk
Posted by GitBox <gi...@apache.org>.
Zha0q1 merged pull request #19761:
URL: https://github.com/apache/incubator-mxnet/pull/19761
----------------------------------------------------------------
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 #19761: [wip][v1.x] ONNX conversion for topk
Posted by GitBox <gi...@apache.org>.
Zha0q1 merged pull request #19761:
URL: https://github.com/apache/incubator-mxnet/pull/19761
----------------------------------------------------------------
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 #19761: [wip][v1.x] ONNX conversion for topk
Posted by GitBox <gi...@apache.org>.
waytrue17 commented on a change in pull request #19761:
URL: https://github.com/apache/incubator-mxnet/pull/19761#discussion_r558696397
##########
File path: python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
##########
@@ -2208,33 +2208,59 @@ def convert_broadcast_to(node, **kwargs):
return [tensor_node, expand_node]
-@mx_op.register("topk")
+@mx_op.register('topk')
def convert_topk(node, **kwargs):
"""Map MXNet's topk operator attributes to onnx's TopK operator
and return the created node.
"""
from onnx.helper import make_node
name, input_nodes, attrs = get_inputs(node, kwargs)
+ opset_version = kwargs['opset_version']
+ if opset_version < 11:
+ raise AttributeError('ONNX opset 11 or greater is required to export this operator')
+
axis = int(attrs.get('axis', '-1'))
k = int(attrs.get('k', '1'))
- ret_type = attrs.get('ret_typ')
- outputs = [name]
+ ret_type = attrs.get('ret_typ', 'indices')
+ is_ascend = int(attrs.get('is_ascend', '0'))
+ dtype = attrs.get('dtype', 'float32')
- if ret_type and ret_type == 'both':
- outputs.append(name + '_output1')
- else:
- raise NotImplementedError("ONNX expects both value and indices as output")
+ if ret_type == 'mask':
+ raise NotImplementedError('topk does not currently support ret_type==\'mask\'')
- opset_version = kwargs['opset_version']
- if opset_version >= 10:
- nodes = [
- create_const_scalar_node(name+"_k", np.int64(k), kwargs),
- make_node("TopK", [input_nodes[0], name+"_k"], outputs, axis=axis, name=name)
+ nodes = [
+ create_tensor([k], name+'_k', kwargs['initializer']),
]
- return nodes
+
+ if ret_type in ['both', 'value']:
+ if dtype == 'int64':
+ nodes += [
+ make_node('TopK', [input_nodes[0], name+'_k'], [name+'0', name+'1'], axis=axis,
+ largest=(0 if is_ascend else 1), sorted=1),
Review comment:
Is it safe to return both values and indices for `value` mode?
##########
File path: python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
##########
@@ -2208,33 +2208,59 @@ def convert_broadcast_to(node, **kwargs):
return [tensor_node, expand_node]
-@mx_op.register("topk")
+@mx_op.register('topk')
def convert_topk(node, **kwargs):
"""Map MXNet's topk operator attributes to onnx's TopK operator
and return the created node.
"""
from onnx.helper import make_node
name, input_nodes, attrs = get_inputs(node, kwargs)
+ opset_version = kwargs['opset_version']
+ if opset_version < 11:
+ raise AttributeError('ONNX opset 11 or greater is required to export this operator')
+
axis = int(attrs.get('axis', '-1'))
k = int(attrs.get('k', '1'))
- ret_type = attrs.get('ret_typ')
- outputs = [name]
+ ret_type = attrs.get('ret_typ', 'indices')
+ is_ascend = int(attrs.get('is_ascend', '0'))
+ dtype = attrs.get('dtype', 'float32')
- if ret_type and ret_type == 'both':
- outputs.append(name + '_output1')
- else:
- raise NotImplementedError("ONNX expects both value and indices as output")
+ if ret_type == 'mask':
+ raise NotImplementedError('topk does not currently support ret_type==\'mask\'')
- opset_version = kwargs['opset_version']
- if opset_version >= 10:
- nodes = [
- create_const_scalar_node(name+"_k", np.int64(k), kwargs),
- make_node("TopK", [input_nodes[0], name+"_k"], outputs, axis=axis, name=name)
+ nodes = [
+ create_tensor([k], name+'_k', kwargs['initializer']),
]
- return nodes
+
+ if ret_type in ['both', 'value']:
+ if dtype == 'int64':
+ nodes += [
+ make_node('TopK', [input_nodes[0], name+'_k'], [name+'0', name+'1'], axis=axis,
+ largest=(0 if is_ascend else 1), sorted=1),
+ ]
+ else:
+ nodes += [
+ make_node('TopK', [input_nodes[0], name+'_k'], [name+'0', name+'1_'], axis=axis,
+ largest=(0 if is_ascend else 1), sorted=1),
+ make_node('Cast', [name+'1_'], [name+'1'],
+ to=onnx.mapping.NP_TYPE_TO_TENSOR_TYPE[np.dtype(dtype)])
Review comment:
Do we need to cast dtype for `value` 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 #19761: [v1.x] ONNX conversion for _maximum_scalar
Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #19761:
URL: https://github.com/apache/incubator-mxnet/pull/19761#issuecomment-761217617
Hey @Zha0q1 , 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, miscellaneous, centos-gpu, unix-cpu, windows-gpu, unix-gpu, website, sanity, windows-cpu, edge, centos-cpu]
***
_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