Skip to content

Commit

Permalink
Add support for sharing params of operators in tensorflow frontend (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lfengad authored Mar 30, 2020
1 parent 3bab699 commit c38f2f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/tvm/relay/frontend/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _dim_check(attrs):
def _get_param(params, input_node):
if isinstance(input_node, _expr.Constant):
return np.atleast_1d(input_node.data.asnumpy())
return params.pop(input_node.name_hint).asnumpy()
return params[input_node.name_hint].asnumpy()

def _get_num_param(params, input_node):
return _get_param(params, input_node).item()
Expand Down
18 changes: 18 additions & 0 deletions tests/python/frontend/tensorflow/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -3058,6 +3058,21 @@ def test_forward_add_n():
_test_forward_add_n(in4)
_test_forward_add_n(in5)

#######################################################################
# Sharing params case
# ----------------------


def test_sharing_node():
"""Test the sharing params case."""
np_data = np.random.uniform(size=(2,2,2)).astype('float32')
with tf.Graph().as_default():
in_data = tf.placeholder(tf.float32, shape=(2, 2, 2), name='in_data')
axis = tf.constant([-1], dtype=tf.int32, name='axis')
mean0 = tf.reduce_mean(in_data, axis=axis, keepdims=False, name='mean0')
mean1 = tf.reduce_mean(in_data, axis=axis, keepdims=False, name='mean1')
out = tf.add(mean0, mean1, name='out')
compare_tf_with_tvm([np_data], ['in_data:0'], 'out:0')

#######################################################################
# Unravel Index
Expand Down Expand Up @@ -3311,3 +3326,6 @@ def test_forward_isfinite():

# Internal misc. ops
test_read_variable_op()

# Sharing params case using Mean ops
test_sharing_node()

0 comments on commit c38f2f3

Please sign in to comment.