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

Commit

Permalink
remove temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
Wei Chu committed Dec 18, 2020
1 parent f866fd0 commit bc91aea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
11 changes: 3 additions & 8 deletions python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,19 +854,14 @@ def convert_softmax(node, **kwargs):

axis = int(attrs.get("axis", -1))
temperature = attrs.get("temperature", None)
if not temperature:
temperature = 1.0
else:
temperature = float(temperature)
if temperature and float(temperature) != 1.0:
raise NotImplementedError("Temperature will be supported in onnx opset13.")
use_length = attrs.get("use_length", None)
input_type = kwargs["in_type"]
data = input_nodes[0]

nodes = [
create_tensor([temperature], name+"_temp", kwargs["initializer"], dtype="float64"),
make_node("Cast", [name+"_temp"], [name+"_T"], to=input_type),
make_node("Div", [data, name+"_T"], [name+"_div_out"]),
make_node("Exp", [name+"_div_out"], [name+"_exp_out"]),
make_node("Exp", [data], [name+"_exp_out"]),
make_node("ReduceSum", [name+"_exp_out"], [name+"_rsum_out"], axes=[axis], keepdims=1)
]
if len(input_nodes) == 1:
Expand Down
11 changes: 5 additions & 6 deletions tests/python-pytest/onnx/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,17 +306,16 @@ def test_onnx_export_cast(tmp_path, src_dtype, dst_dtype, shape):


@pytest.mark.parametrize('dtype', ['float16', 'float32'])
@pytest.mark.parametrize('temperature', [0.3, 0.5, 1.0])
def test_onnx_export_softmax(tmp_path, dtype, temperature):
def test_onnx_export_softmax(tmp_path, dtype):
x = mx.nd.random.uniform(0, 1, (2, 3, 4), dtype=dtype)
M1 = def_model('softmax', temperature=temperature)
M1 = def_model('softmax')
op_export_test('softmax_1', M1, [x], tmp_path)
M2 = def_model('softmax', use_length=True, axis=0, temperature=temperature)
M2 = def_model('softmax', use_length=True, axis=0)
l2 = mx.nd.array([[2,0,2,1],[1,1,2,1], [0,0,0,1]], dtype=int)
op_export_test('softmax_2', M2, [x, l2], tmp_path)
M3 = def_model('softmax', use_length=True, axis=-1, temperature=temperature)
M3 = def_model('softmax', use_length=True, axis=-1)
l3 = mx.nd.array([[2,0,4],[0,0,0]], dtype=int)
op_export_test('softmax_3', M3, [x, l3], tmp_path)
M4 = def_model('softmax', use_length=True, axis=1, temperature=temperature)
M4 = def_model('softmax', use_length=True, axis=1)
l4 = mx.nd.array([[2,0,3,1],[0,1,0,0]], dtype=int)
op_export_test('softmax_4', M4, [x, l4], tmp_path)

0 comments on commit bc91aea

Please sign in to comment.