Skip to content

Commit 2d5de33

Browse files
committed
[Relax] [ONNX] Add support for Sign and Not
1 parent b654852 commit 2d5de33

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

python/tvm/relax/frontend/onnx/onnx_frontend.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,22 @@ def _impl_v14(cls, bb, inputs, attr, params):
19481948
)
19491949

19501950

1951+
class Sign(OnnxOpConverter):
1952+
"""Converts an onnx Sign node into an equivalent Relax expression."""
1953+
1954+
@classmethod
1955+
def _impl_v9(cls, bb, inputs, attr, params):
1956+
return relax.op.sign(inputs[0])
1957+
1958+
1959+
class Not(OnnxOpConverter):
1960+
"""Converts an onnx Not node into an equivalent Relax expression."""
1961+
1962+
@classmethod
1963+
def _impl_v1(cls, bb, inputs, attr, params):
1964+
return relax.op.logical_not(inputs[0])
1965+
1966+
19511967
def _get_convert_map():
19521968
return {
19531969
"MatMul": MatMul,
@@ -2030,6 +2046,8 @@ def _get_convert_map():
20302046
"Elu": Elu,
20312047
"HardSigmoid": HardSigmoid,
20322048
"HardSwish": HardSwish,
2049+
"Sign": Sign,
2050+
"Not": Not,
20332051
}
20342052

20352053

tests/python/relax/test_frontend_onnx.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,14 @@ def test_hardswish():
600600
verify_unary("HardSwish", [32, 32])
601601

602602

603+
def test_sign():
604+
verify_unary("Sign", [32, 32])
605+
606+
607+
def test_not():
608+
verify_unary("Not", [32, 32], dtype=TensorProto.BOOL)
609+
610+
603611
def test_conv():
604612
def _verify_conv(input_shape, weight_shape, output_shape):
605613
bias_shape = [output_shape[1]]

0 commit comments

Comments
 (0)