Skip to content

Commit

Permalink
TF frontend: add softsign op (apache#6799)
Browse files Browse the repository at this point in the history
  • Loading branch information
alter-xp authored and Trevor Morris committed Dec 2, 2020
1 parent c5500ac commit 32b1267
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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 @@ -3520,6 +3520,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

0 comments on commit 32b1267

Please sign in to comment.