@@ -124,7 +124,8 @@ def compare_tf_with_tvm(in_data, in_name, out_name, init_global_variables=False,
124124 if no_gpu and device == 'cuda' :
125125 continue
126126
127- tvm_output = run_tvm_graph (final_graph_def , in_data , in_node , target = device )
127+ tvm_output = run_tvm_graph (final_graph_def , in_data , in_node ,
128+ num_output = len (out_node ), target = device , out_names = out_name )
128129 # since the names from tensorflow and nnvm runs are not exactly same,
129130 # first len(tf_output) will be compared
130131 for i in range (len (tf_output )):
@@ -506,14 +507,24 @@ def test_forward_gather():
506507# Split
507508# -----
508509
509- def _test_split (in_shape , axis , num_split , dtype ):
510+ def _test_split (in_shape , axis , num_or_size_splits , dtype ):
511+ np_data = np .random .uniform (- 5 , 5 , size = in_shape ).astype (dtype )
512+
510513 """ One iteration of a Split """
514+ tf .reset_default_graph ()
515+ in_data = tf .placeholder (dtype , in_shape , name = "in_data" )
516+ num_split = len (num_or_size_splits ) if isinstance (num_or_size_splits , list ) else num_or_size_splits
517+ tf .split (in_data , num_or_size_splits , axis = axis )
511518
512- with tf .Graph ().as_default ():
513- in_data = tf .placeholder (dtype , in_shape , name = "in_data" )
514- tf .split (in_data , num_split , axis )
515- np_data = np .random .uniform (size = in_shape ).astype (dtype )
516- compare_tf_with_tvm (np_data , 'in_data:0' , 'split:0' )
519+ compare_tf_with_tvm ([np_data ], ['in_data:0' ], [f'split:{ n } ' for n in range (num_split )])
520+
521+ # and now test together with concat
522+ tf .reset_default_graph ()
523+ in_data = tf .placeholder (dtype , in_shape , name = "in_data" )
524+ splitted = tf .split (in_data , num_or_size_splits , axis = axis )
525+ tf .concat (splitted , axis )
526+
527+ compare_tf_with_tvm ([np_data ], 'in_data:0' , 'concat:0' )
517528
518529def test_forward_split ():
519530 '''test split layer'''
@@ -523,11 +534,11 @@ def test_forward_split():
523534 _test_split ((6 ,), 0 , 3 , 'float32' )
524535 # rank 2
525536 _test_split ((6 , 2 ), 0 , 3 , 'float32' )
526- _test_split ((2 , 6 ), 1 , 3 , 'float32' )
537+ _test_split ((2 , 6 ), 1 , 6 , 'float32' )
527538 # rank 3
528- _test_split ((6 , 2 , 4 ), 0 , 3 , 'float32 ' )
539+ _test_split ((6 , 2 , 4 ), 0 , 2 , 'int32 ' )
529540 _test_split ((2 , 6 , 4 ), 1 , 3 , 'float32' )
530- _test_split ((2 , 4 , 6 ), 2 , 3 , 'float32' )
541+ _test_split ((2 , 4 , 6 ), 2 , 1 , 'float32' )
531542 # rank 4
532543 _test_split ((6 , 1 , 3 , 5 ), 0 , 3 , 'float32' )
533544 _test_split ((1 , 6 , 3 , 5 ), 1 , 3 , 'float32' )
@@ -538,45 +549,30 @@ def test_forward_split():
538549 _test_split ((1 , 6 , 3 , 5 ), - 3 , 3 , 'float32' )
539550 _test_split ((1 , 3 , 6 , 5 ), - 2 , 3 , 'float32' )
540551 _test_split ((1 , 3 , 5 , 6 ), - 1 , 3 , 'float32' )
552+ # size_splits list
553+ _test_split ((6 ,), 0 , [1 , 2 , 3 ], 'int32' )
554+ _test_split ((3 , 6 , 4 ), - 2 , [1 , 4 , 1 ], 'float32' )
541555
542556
543557#######################################################################
544- # Split followed by concat
545- # ------------------------
558+ # Unstack
559+ # -------
546560
547- def _test_split_concat (in_shape , axis , num_split , dtype ):
548- """ One iteration of a split_concat pair"""
561+ def _test_unstack (ip_shape , axis , dtype ):
562+ tf .reset_default_graph ()
563+ in_data = tf .placeholder (dtype , ip_shape , name = "in_data" )
564+ tf .unstack (in_data , axis = axis )
565+ np_data = np .random .uniform (- 5 , 5 , size = ip_shape ).astype (dtype )
549566
550- with tf .Graph ().as_default ():
551- in_data = tf .placeholder (dtype , in_shape , name = "in_data" )
552- splitted = tf .split (in_data , num_split , axis )
553- tf .concat (splitted , axis )
554- np_data = np .random .uniform (size = in_shape ).astype (dtype )
555- compare_tf_with_tvm (np_data , 'in_data:0' , 'concat:0' )
556-
557- def test_forward_split_concat ():
558- '''test split followed by concat layers'''
559- # rank 1
560- _test_split_concat ((3 ,), 0 , 1 , 'float32' )
561- _test_split_concat ((3 ,), 0 , 3 , 'float32' )
562- _test_split_concat ((6 ,), 0 , 3 , 'float32' )
563- # rank 2
564- _test_split_concat ((6 , 2 ), 0 , 3 , 'float32' )
565- _test_split_concat ((2 , 6 ), 1 , 3 , 'float32' )
566- # rank 3
567- _test_split_concat ((6 , 2 , 4 ), 0 , 3 , 'float32' )
568- _test_split_concat ((2 , 6 , 4 ), 1 , 3 , 'float32' )
569- _test_split_concat ((2 , 4 , 6 ), 2 , 3 , 'float32' )
570- # rank 4
571- _test_split ((6 , 1 , 3 , 5 ), 0 , 3 , 'float32' )
572- _test_split ((1 , 6 , 3 , 5 ), 1 , 3 , 'float32' )
573- _test_split ((1 , 3 , 6 , 5 ), 2 , 3 , 'float32' )
574- _test_split ((1 , 3 , 5 , 6 ), 3 , 3 , 'float32' )
575- # split along negative axis
576- _test_split ((6 , 1 , 3 , 5 ), - 4 , 3 , 'float32' )
577- _test_split ((1 , 6 , 3 , 5 ), - 3 , 3 , 'float32' )
578- _test_split ((1 , 3 , 6 , 5 ), - 2 , 3 , 'float32' )
579- _test_split ((1 , 3 , 5 , 6 ), - 1 , 3 , 'float32' )
567+ compare_tf_with_tvm ([np_data ], ['in_data:0' ], [f'unstack:{ n } ' for n in range (ip_shape [axis ])])
568+
569+ def test_forward_unstack ():
570+ '''test unstack layer'''
571+ _test_unstack ((6 ,), 0 , 'int32' )
572+ _test_unstack ((2 ,6 ), 1 , 'float64' )
573+ # negative axis
574+ _test_unstack ((1 ,4 ), - 1 , 'int32' )
575+ _test_unstack ((3 ,6 ,4 ), - 2 , 'float32' )
580576
581577
582578#######################################################################
@@ -1139,7 +1135,7 @@ def test_forward_rel_ops():
11391135 test_forward_gather ()
11401136 test_forward_stridedslice ()
11411137 test_forward_split ()
1142- test_forward_split_concat ()
1138+ test_forward_unstack ()
11431139
11441140 # Activations
11451141 test_forward_sigmoid ()
0 commit comments