Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[v1.x] ONNX fix log_softmax for opset 12 #20209

Merged
merged 4 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2395,22 +2395,28 @@ def convert_logsoftmax(node, **kwargs):
"""Map MXNet's log_softmax operator attributes to onnx's LogSoftMax operator
and return the created node.
"""
from onnx.helper import make_node
name, input_nodes, attrs = get_inputs(node, kwargs)

# Converting to int
axis = int(attrs.get("axis", -1))
temp = attrs.get("temperature", 'None')
temp = attrs.get('temperature', 'None')
use_length = attrs.get('use_length', 'False')

if temp != 'None':
raise AttributeError("LogSoftMax: ONNX supports only temperature=None")
raise AttributeError('LogSoftMax currently does not support temperature!=None')

node = onnx.helper.make_node(
'LogSoftmax',
input_nodes,
[name],
axis=axis,
name=name
)
return [node]
if use_length in ['1', 'True']:
raise AttributeError('LogSoftMax currently does not support use_length==True')

nodes = [
make_node('Exp', [input_nodes[0]], [name+'_exp']),
make_node('ReduceSum', [name+'_exp'], [name+'_rsum'], axes=[axis], keepdims=1),
make_node('Div', [name+'_exp', name+'_rsum'], [name+'_div']),
make_node('Log', [name+'_div'], [name])
]

return nodes

@mx_op.register("norm")
def convert_norm(node, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1615,3 +1615,32 @@ def convert_norm(node, **kwargs):
make_node('Reshape', [name+'_norm', name+'_1'], [name])
]
return nodes


@mx_op.register("log_softmax", OPSET_VERSION)
def convert_logsoftmax(node, **kwargs):
"""Map MXNet's log_softmax operator attributes to onnx's LogSoftMax operator
and return the created node.
"""
name, input_nodes, attrs = get_inputs(node, kwargs)

# Converting to int
axis = int(attrs.get("axis", -1))
temp = attrs.get('temperature', 'None')
use_length = attrs.get('use_length', 'False')

if temp != 'None':
raise AttributeError('LogSoftMax currently does not support temperature!=None')

if use_length in ['1', 'True']:
raise AttributeError('LogSoftMax currently does not support use_length==True')

node = onnx.helper.make_node(
'LogSoftmax',
input_nodes,
[name],
axis=axis,
name=name
)

return [node]