Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF frontend: add softsign op #6799

Merged
merged 1 commit into from
Nov 2, 2020
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
11 changes: 11 additions & 0 deletions python/tvm/relay/frontend/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1923,6 +1923,16 @@ def _impl(inputs, attr, params, mod):
return _impl


def _softsign():
# op description: https://www.tensorflow.org/api_docs/python/tf/math/softsign
def _impl(inputs, attr, params, mod):
abs_out = get_relay_op("abs")(inputs[0])
add_out = abs_out + tvm.relay.const(1, attr["T"].name)
return inputs[0] / add_out

return _impl


def _softplus():
# op description: https://www.tensorflow.org/api_docs/python/tf/math/softplus
def _impl(inputs, attr, params, mod):
Expand Down Expand Up @@ -2381,6 +2391,7 @@ def _impl(inputs, attr, params, mod):
"Slice": _slice(),
"Softmax": _softmax(),
"Softplus": _softplus(),
"Softsign": _softsign(),
"SpaceToBatchND": _space_to_batch_nd(),
"SpaceToDepth": _space_to_depth(),
"Split": _split(False),
Expand Down
16 changes: 16 additions & 0 deletions tests/python/frontend/tensorflow/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -3504,6 +3504,22 @@ def _test_forward_expm1(shape):
_test_forward_expm1([2, 5, 2, 5])


def test_forward_softsign():
"""test operator softsign """

def _test_forward_softsign(shape):
tf.disable_eager_execution()
np_data = np.random.uniform(1, 100, size=shape).astype(np.float32)
tf.reset_default_graph()
in_data = tf.placeholder(tf.float32, shape, name="in_data")
tf.nn.softsign(in_data, name="softsign")
compare_tf_with_tvm([np_data], ["in_data:0"], "softsign:0")

_test_forward_softsign([1, 100])
_test_forward_softsign([1, 10, 10])
_test_forward_softsign([2, 5, 2, 5])


def test_forward_negative():
"""test tf operator Neg """
np_data = np.random.uniform(-100, 255, size=(224, 224, 3)).astype(np.float32)
Expand Down