Skip to content

Commit

Permalink
[Relax] [ONNX] Add support for Sign and Not
Browse files Browse the repository at this point in the history
  • Loading branch information
tsu-bin committed Jul 18, 2024
1 parent 73078f1 commit 75000ad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions python/tvm/relax/frontend/onnx/onnx_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,22 @@ def _impl_v14(cls, bb, inputs, attr, params):
)


class Sign(OnnxOpConverter):
"""Converts an onnx Sign node into an equivalent Relax expression."""

@classmethod
def _impl_v9(cls, bb, inputs, attr, params):
return relax.op.sign(inputs[0])


class Not(OnnxOpConverter):
"""Converts an onnx Not node into an equivalent Relax expression."""

@classmethod
def _impl_v1(cls, bb, inputs, attr, params):
return relax.op.logical_not(inputs[0])


def _get_convert_map():
return {
"MatMul": MatMul,
Expand Down Expand Up @@ -2030,6 +2046,8 @@ def _get_convert_map():
"Elu": Elu,
"HardSigmoid": HardSigmoid,
"HardSwish": HardSwish,
"Sign": Sign,
"Not": Not,
}


Expand Down
8 changes: 8 additions & 0 deletions tests/python/relax/test_frontend_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,14 @@ def test_hardswish():
verify_unary("HardSwish", [32, 32])


def test_sign():
verify_unary("Sign", [32, 32])


def test_not():
verify_unary("Not", [32, 32], dtype=TensorProto.BOOL)


def test_conv():
def _verify_conv(input_shape, weight_shape, output_shape):
bias_shape = [output_shape[1]]
Expand Down

0 comments on commit 75000ad

Please sign in to comment.