From e937a80454b5c2eedca6570d757dcd404b301dd9 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 13 Nov 2019 10:12:43 -0800 Subject: [PATCH 1/3] [Relay][Frontend][TF] Use _infer_value_simulated when axes is not a const to Transpose --- python/tvm/relay/frontend/tensorflow.py | 4 +- .../frontend/tensorflow/test_forward.py | 233 ++++++++++-------- 2 files changed, 128 insertions(+), 109 deletions(-) diff --git a/python/tvm/relay/frontend/tensorflow.py b/python/tvm/relay/frontend/tensorflow.py index 35c857a3d77f..e44653ff1ba9 100644 --- a/python/tvm/relay/frontend/tensorflow.py +++ b/python/tvm/relay/frontend/tensorflow.py @@ -1039,8 +1039,8 @@ def _impl(inputs, attr, params): # otherwise its value is get from params try: axes = _get_list_param(params, inputs[1]) - except (IndexError, KeyError): - axes = None + except (IndexError, KeyError, AttributeError): + axes = _infer_value_simulated(inputs[1], params).asnumpy() return _op.transpose(inputs[0], axes=axes) return _impl diff --git a/tests/python/frontend/tensorflow/test_forward.py b/tests/python/frontend/tensorflow/test_forward.py index 17db2f5cc9a8..62ef50fe2387 100644 --- a/tests/python/frontend/tensorflow/test_forward.py +++ b/tests/python/frontend/tensorflow/test_forward.py @@ -2114,6 +2114,23 @@ def _test_forward_transpose(ishape, axes=None): compare_tf_with_tvm(data, 'transpose_data:0', 'transpose:0') +def _test_forward_tranapose_axes_input(ishape, axes): + data = np.random.uniform(size=ishape).astype(np.float32) + axes_np = np.array(axes).astype(np.int32) + + with tf.Graph().as_default(): + in1 = tf.placeholder( + shape=data.shape, dtype=data.dtype, name="transpose_data") + + const1 = tf.constant(axes_np, dtype=tf.int32) + + # make axes an input to tf.transpose, but not an input to the graph, + # so it can be extracted with infer_value_simulated + axes = tf.reverse(const1, axis=[-1]) + + tf.transpose(in1, axes) + + compare_tf_with_tvm([data], ['transpose_data:0'], 'transpose:0') def test_forward_transpose(): _test_forward_transpose((2, 3, 4), (1, 2, 0)) @@ -2122,6 +2139,8 @@ def test_forward_transpose(): _test_forward_transpose((2, 3, 4), (1, 2, 0)) _test_forward_transpose((2, 3, 4), (0, 1, 2)) _test_forward_transpose((2, 3, 4, 5), (3, 0, 1, 2)) + _test_forward_tranapose_axes_input((2, 3, 4), (1, 2, 0)) + _test_forward_tranapose_axes_input((2, 3, 4, 5), (3, 0, 1, 2)) def test_forward_ceil(): @@ -2699,112 +2718,112 @@ def test_forward_add_n(): # Transforms test_forward_transpose() - test_forward_reshape() - test_forward_depthtospace() - test_forward_spacetodepth() - test_forward_squeeze() - test_forward_pack() - test_forward_size() - test_forward_broadcast_to() - test_forward_fill() - test_forward_crop() - test_forward_resize() - test_forward_crop_and_resize() - test_forward_pad() - test_forward_unpack() - test_forward_gather() - test_forward_gather_nd() - test_forward_stridedslice() - test_forward_split() - test_forward_unstack() - test_forward_tile() - test_forward_top_k_v2() - test_forward_clip_by_value() - test_forward_maximum() - test_forward_minimum() - test_forward_range() - test_forward_right_shift() - test_forward_left_shift() - test_forward_truncatemod() - test_forward_one_hot() - - # Activations - test_forward_sigmoid() - test_forward_relu() - test_forward_leaky_relu() - test_forward_elu() - test_forward_selu() - test_forward_tanh() - - # Tensor - test_forward_round() - test_forward_reverse_v2() - test_forward_pow_exp() - test_forward_sign() - test_forward_log() - test_forward_log1p() - test_forward_cos() - test_forward_sin() - test_forward_negative() - test_forward_divide() - test_forward_abs() - test_forward_softplus() - test_forward_sqrt() - test_forward_rsqrt() - test_forward_expand_dims() - test_forward_square() - test_forward_softmax() - test_forward_log_softmax() - test_forward_bias_add() - test_forward_zeros_like() - test_forward_erf() - test_forward_squared_difference() - test_forward_add_n() - - # Reductions - test_forward_argminmax() - test_forward_reduce() - test_forward_mean() - test_forward_reduce_prod() - test_forward_reduce_all() - test_forward_reduce_any() - test_forward_reduce_min() - - # General - test_forward_multi_input() - test_forward_multi_output() - test_forward_variable() - test_placeholder() - - # NN - test_forward_convolution() - test_forward_pooling() - test_forward_concat_v2() - test_forward_lrn() - test_forward_l2_normalize() - test_forward_space_to_batch_nd() - test_forward_batch_to_space_nd() - - # End to End - test_forward_inception_v3() - test_forward_inception_v1() - test_forward_mobilenet() - test_forward_resnetv2() - test_forward_placeholder() - test_forward_ptb() - - # RNN - test_forward_lstm() - - # Elementwise - test_forward_ceil() - test_forward_floor() - - # Relational ops - test_forward_rel_ops() - test_forward_logical() - test_forward_where() - test_forward_matmul() - test_forward_batch_matmul() + # test_forward_reshape() + # test_forward_depthtospace() + # test_forward_spacetodepth() + # test_forward_squeeze() + # test_forward_pack() + # test_forward_size() + # test_forward_broadcast_to() + # test_forward_fill() + # test_forward_crop() + # test_forward_resize() + # test_forward_crop_and_resize() + # test_forward_pad() + # test_forward_unpack() + # test_forward_gather() + # test_forward_gather_nd() + # test_forward_stridedslice() + # test_forward_split() + # test_forward_unstack() + # test_forward_tile() + # test_forward_top_k_v2() + # test_forward_clip_by_value() + # test_forward_maximum() + # test_forward_minimum() + # test_forward_range() + # test_forward_right_shift() + # test_forward_left_shift() + # test_forward_truncatemod() + # test_forward_one_hot() + + # # Activations + # test_forward_sigmoid() + # test_forward_relu() + # test_forward_leaky_relu() + # test_forward_elu() + # test_forward_selu() + # test_forward_tanh() + + # # Tensor + # test_forward_round() + # test_forward_reverse_v2() + # test_forward_pow_exp() + # test_forward_sign() + # test_forward_log() + # test_forward_log1p() + # test_forward_cos() + # test_forward_sin() + # test_forward_negative() + # test_forward_divide() + # test_forward_abs() + # test_forward_softplus() + # test_forward_sqrt() + # test_forward_rsqrt() + # test_forward_expand_dims() + # test_forward_square() + # test_forward_softmax() + # test_forward_log_softmax() + # test_forward_bias_add() + # test_forward_zeros_like() + # test_forward_erf() + # test_forward_squared_difference() + # test_forward_add_n() + + # # Reductions + # test_forward_argminmax() + # test_forward_reduce() + # test_forward_mean() + # test_forward_reduce_prod() + # test_forward_reduce_all() + # test_forward_reduce_any() + # test_forward_reduce_min() + + # # General + # test_forward_multi_input() + # test_forward_multi_output() + # test_forward_variable() + # test_placeholder() + + # # NN + # test_forward_convolution() + # test_forward_pooling() + # test_forward_concat_v2() + # test_forward_lrn() + # test_forward_l2_normalize() + # test_forward_space_to_batch_nd() + # test_forward_batch_to_space_nd() + + # # End to End + # test_forward_inception_v3() + # test_forward_inception_v1() + # test_forward_mobilenet() + # test_forward_resnetv2() + # test_forward_placeholder() + # test_forward_ptb() + + # # RNN + # test_forward_lstm() + + # # Elementwise + # test_forward_ceil() + # test_forward_floor() + + # # Relational ops + # test_forward_rel_ops() + # test_forward_logical() + # test_forward_where() + # test_forward_matmul() + # test_forward_batch_matmul() # TODO missing tests: rank From 5f8d8ca4cf637660fb68576b5be1b3faee63df9b Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 13 Nov 2019 10:15:08 -0800 Subject: [PATCH 2/3] uncomment tests --- .../frontend/tensorflow/test_forward.py | 214 +++++++++--------- 1 file changed, 107 insertions(+), 107 deletions(-) diff --git a/tests/python/frontend/tensorflow/test_forward.py b/tests/python/frontend/tensorflow/test_forward.py index 62ef50fe2387..b878ac11d649 100644 --- a/tests/python/frontend/tensorflow/test_forward.py +++ b/tests/python/frontend/tensorflow/test_forward.py @@ -2718,112 +2718,112 @@ def test_forward_add_n(): # Transforms test_forward_transpose() - # test_forward_reshape() - # test_forward_depthtospace() - # test_forward_spacetodepth() - # test_forward_squeeze() - # test_forward_pack() - # test_forward_size() - # test_forward_broadcast_to() - # test_forward_fill() - # test_forward_crop() - # test_forward_resize() - # test_forward_crop_and_resize() - # test_forward_pad() - # test_forward_unpack() - # test_forward_gather() - # test_forward_gather_nd() - # test_forward_stridedslice() - # test_forward_split() - # test_forward_unstack() - # test_forward_tile() - # test_forward_top_k_v2() - # test_forward_clip_by_value() - # test_forward_maximum() - # test_forward_minimum() - # test_forward_range() - # test_forward_right_shift() - # test_forward_left_shift() - # test_forward_truncatemod() - # test_forward_one_hot() - - # # Activations - # test_forward_sigmoid() - # test_forward_relu() - # test_forward_leaky_relu() - # test_forward_elu() - # test_forward_selu() - # test_forward_tanh() - - # # Tensor - # test_forward_round() - # test_forward_reverse_v2() - # test_forward_pow_exp() - # test_forward_sign() - # test_forward_log() - # test_forward_log1p() - # test_forward_cos() - # test_forward_sin() - # test_forward_negative() - # test_forward_divide() - # test_forward_abs() - # test_forward_softplus() - # test_forward_sqrt() - # test_forward_rsqrt() - # test_forward_expand_dims() - # test_forward_square() - # test_forward_softmax() - # test_forward_log_softmax() - # test_forward_bias_add() - # test_forward_zeros_like() - # test_forward_erf() - # test_forward_squared_difference() - # test_forward_add_n() - - # # Reductions - # test_forward_argminmax() - # test_forward_reduce() - # test_forward_mean() - # test_forward_reduce_prod() - # test_forward_reduce_all() - # test_forward_reduce_any() - # test_forward_reduce_min() - - # # General - # test_forward_multi_input() - # test_forward_multi_output() - # test_forward_variable() - # test_placeholder() - - # # NN - # test_forward_convolution() - # test_forward_pooling() - # test_forward_concat_v2() - # test_forward_lrn() - # test_forward_l2_normalize() - # test_forward_space_to_batch_nd() - # test_forward_batch_to_space_nd() - - # # End to End - # test_forward_inception_v3() - # test_forward_inception_v1() - # test_forward_mobilenet() - # test_forward_resnetv2() - # test_forward_placeholder() - # test_forward_ptb() - - # # RNN - # test_forward_lstm() - - # # Elementwise - # test_forward_ceil() - # test_forward_floor() - - # # Relational ops - # test_forward_rel_ops() - # test_forward_logical() - # test_forward_where() - # test_forward_matmul() - # test_forward_batch_matmul() + test_forward_reshape() + test_forward_depthtospace() + test_forward_spacetodepth() + test_forward_squeeze() + test_forward_pack() + test_forward_size() + test_forward_broadcast_to() + test_forward_fill() + test_forward_crop() + test_forward_resize() + test_forward_crop_and_resize() + test_forward_pad() + test_forward_unpack() + test_forward_gather() + test_forward_gather_nd() + test_forward_stridedslice() + test_forward_split() + test_forward_unstack() + test_forward_tile() + test_forward_top_k_v2() + test_forward_clip_by_value() + test_forward_maximum() + test_forward_minimum() + test_forward_range() + test_forward_right_shift() + test_forward_left_shift() + test_forward_truncatemod() + test_forward_one_hot() + + # Activations + test_forward_sigmoid() + test_forward_relu() + test_forward_leaky_relu() + test_forward_elu() + test_forward_selu() + test_forward_tanh() + + # Tensor + test_forward_round() + test_forward_reverse_v2() + test_forward_pow_exp() + test_forward_sign() + test_forward_log() + test_forward_log1p() + test_forward_cos() + test_forward_sin() + test_forward_negative() + test_forward_divide() + test_forward_abs() + test_forward_softplus() + test_forward_sqrt() + test_forward_rsqrt() + test_forward_expand_dims() + test_forward_square() + test_forward_softmax() + test_forward_log_softmax() + test_forward_bias_add() + test_forward_zeros_like() + test_forward_erf() + test_forward_squared_difference() + test_forward_add_n() + + # Reductions + test_forward_argminmax() + test_forward_reduce() + test_forward_mean() + test_forward_reduce_prod() + test_forward_reduce_all() + test_forward_reduce_any() + test_forward_reduce_min() + + # General + test_forward_multi_input() + test_forward_multi_output() + test_forward_variable() + test_placeholder() + + # NN + test_forward_convolution() + test_forward_pooling() + test_forward_concat_v2() + test_forward_lrn() + test_forward_l2_normalize() + test_forward_space_to_batch_nd() + test_forward_batch_to_space_nd() + + # End to End + test_forward_inception_v3() + test_forward_inception_v1() + test_forward_mobilenet() + test_forward_resnetv2() + test_forward_placeholder() + test_forward_ptb() + + # RNN + test_forward_lstm() + + # Elementwise + test_forward_ceil() + test_forward_floor() + + # Relational ops + test_forward_rel_ops() + test_forward_logical() + test_forward_where() + test_forward_matmul() + test_forward_batch_matmul() # TODO missing tests: rank From d32bac3e04258ec95fa60bc99f21d7c5ac62a484 Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 14 Nov 2019 09:38:49 -0800 Subject: [PATCH 3/3] dummy change to retrigger ci --- tests/python/frontend/tensorflow/test_forward.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/python/frontend/tensorflow/test_forward.py b/tests/python/frontend/tensorflow/test_forward.py index b878ac11d649..e02532fa748b 100644 --- a/tests/python/frontend/tensorflow/test_forward.py +++ b/tests/python/frontend/tensorflow/test_forward.py @@ -2127,7 +2127,6 @@ def _test_forward_tranapose_axes_input(ishape, axes): # make axes an input to tf.transpose, but not an input to the graph, # so it can be extracted with infer_value_simulated axes = tf.reverse(const1, axis=[-1]) - tf.transpose(in1, axes) compare_tf_with_tvm([data], ['transpose_data:0'], 'transpose:0')