Skip to content

Commit

Permalink
Add IdentityN operator for TF Frontend (apache#7452)
Browse files Browse the repository at this point in the history
* Add frontend code and tests

* Add Frontend Code

Co-authored-by: Ubuntu <ubuntu@ip-172-31-42-251.us-east-2.compute.internal>
  • Loading branch information
2 people authored and trevor-m committed Mar 2, 2021
1 parent dbbc7ba commit da1dbed
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python/tvm/relay/frontend/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,13 @@ def _impl(inputs, attr, params, mod):
return _impl


def _identityn():
def _impl(inputs, attr, params, mod):
return inputs

return _impl


def _concatV2():
def _impl(inputs, attr, params, mod):
pop_node = inputs.pop(len(inputs) - 1)
Expand Down Expand Up @@ -2378,6 +2385,7 @@ def _impl(inputs, attr, params, mod):
"Greater": _broadcast("greater"),
"GreaterEqual": _broadcast("greater_equal"),
"Identity": _identity(),
"IdentityN": _identityn(),
"IsFinite": AttrCvt("isfinite"),
"IsInf": AttrCvt("isinf"),
"IsNan": AttrCvt("isnan"),
Expand Down
50 changes: 50 additions & 0 deletions tests/python/frontend/tensorflow/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -4090,6 +4090,56 @@ def test_forward_dilation():
_test_dilation2d([1, 3, 3, 1], [2, 2, 1], [1, 1, 1, 1], [1, 1, 2, 1], "VALID")


def _test_identityn(data_np_list):
with tf.Graph().as_default():
data_tensors = []
data_tensors_name = []
for index, data_np in enumerate(data_np_list):
tensor_name = f"data_{index}"
data_tensors_name.append(tensor_name + ":0")
data_tensors.append(
tf.placeholder(shape=data_np.shape, dtype=str(data_np.dtype), name=tensor_name)
)

output = tf.identity_n(data_tensors)
output_names = [out.name for out in output]
compare_tf_with_tvm(
data_np_list,
data_tensors_name,
output_names,
)


@pytest.mark.parametrize(
"data_np_list",
[
(
[
np.array([[1, 1], [0, 3], [0, 1], [2, 0], [3, 1]], dtype=np.int64),
np.array([1, 2, 3, 4, 5], dtype=np.int64),
np.array([5, 6], dtype=np.int64),
]
),
(
[
np.array([[1, 1], [0, 3], [2, 0], [3, 1]], dtype=np.int64),
np.array([1, 2, 3, 4], dtype=np.int64),
np.array([5, 6], dtype=np.int64),
np.array([True, False, True]),
]
),
(
[
np.array([]),
np.array([[]]),
]
),
],
)
def test_forward_identityn(data_np_list):
_test_identityn(data_np_list)


#######################################################################
# Sparse To Dense
# ---------------
Expand Down

0 comments on commit da1dbed

Please sign in to comment.