@@ -48,7 +48,7 @@ def get_tvm_output_with_vm(graph_def, input_data, target, ctx, opset=None, freez
4848 """ Generic function to execute and get tvm output with vm executor"""
4949 if not isinstance (input_data , list ):
5050 input_data = [input_data ]
51- input_names , shape_dict = get_input_data_shape_dict (graph_def , input_data )
51+ _ , shape_dict = get_input_data_shape_dict (graph_def , input_data )
5252
5353 mod , params = relay .frontend .from_onnx (graph_def , shape_dict , opset = opset , freeze_params = freeze_params )
5454
@@ -167,15 +167,26 @@ def test_reshape():
167167# @tvm.testing.uses_gpu
168168def test_expand ():
169169
170- def _test_expand (name , data , shape , ref_data ):
170+ def _test_expand (name , data , shape , ref_data , dtype = "int32" ):
171171 shape_array = np .array (shape )
172- shape_node = onnx .helper .make_node ('Constant' ,
173- inputs = [],
174- outputs = ['shape' ],
175- value = onnx .helper .make_tensor (name = 'const_tensor' ,
176- data_type = onnx .TensorProto .INT32 ,
177- dims = shape_array .shape ,
178- vals = shape_array .flatten ().astype ('int32' )))
172+ if dtype == "int32" :
173+ shape_node = onnx .helper .make_node ('Constant' ,
174+ inputs = [],
175+ outputs = ['shape' ],
176+ value = onnx .helper .make_tensor (name = 'const_tensor' ,
177+ data_type = onnx .TensorProto .INT32 ,
178+ dims = shape_array .shape ,
179+ vals = shape_array .flatten ().astype ('int32' )))
180+ elif dtype == "int64" :
181+ shape_node = onnx .helper .make_node ('Constant' ,
182+ inputs = [],
183+ outputs = ['shape' ],
184+ value = onnx .helper .make_tensor (name = 'const_tensor' ,
185+ data_type = onnx .TensorProto .INT64 ,
186+ dims = shape_array .shape ,
187+ vals = shape_array .flatten ().astype ('int64' )))
188+ else :
189+ raise "Invalid dtype"
179190 expand_node = helper .make_node ("Expand" , ["in" , "shape" ], ["out" ])
180191
181192 graph = helper .make_graph ([shape_node , expand_node ],
@@ -196,13 +207,15 @@ def _test_expand(name, data, shape, ref_data):
196207 shape = (3 , 4 )
197208 data = np .random .uniform (size = in_shape ).astype (np .float32 )
198209 ref_data = np .tile (data , 4 )
199- _test_expand ('expand_with_dim_unchanged_test' , data , shape , ref_data )
210+ _test_expand ('expand_with_dim_unchanged_test' , data , shape , ref_data , "int32" )
211+ _test_expand ('expand_with_dim_unchanged_test' , data , shape , ref_data , "int64" )
200212
201213 in_shape = (3 , 1 )
202214 shape = (2 , 1 , 6 )
203215 data = np .random .uniform (size = in_shape ).astype (np .float32 )
204216 ref_data = data * np .ones (shape , dtype = np .float32 )
205- _test_expand ('expand_with_dim_changed_test' , data , shape , ref_data )
217+ _test_expand ('expand_with_dim_changed_test' , data , shape , ref_data , "int32" )
218+ _test_expand ('expand_with_dim_changed_test' , data , shape , ref_data , "int64" )
206219
207220
208221def verify_depth_to_space (inshape , outshape , mode , blockSize ):
@@ -822,8 +835,8 @@ def verify_batch_matmul(a_shape, b_shape):
822835 model , [a_array , b_array ], target , ctx )
823836 tvm .testing .assert_allclose (out_np , tvm_out , rtol = 1e-5 , atol = 1e-5 )
824837
825- # TODO(mbrookhart): enable once VM supports heterogenous execution
826- # @tvm.testing.uses_gpu
838+ # TODO(mbrookhart): enable cuda once VM supports heterogenous execution
839+ @tvm .testing .parametrize_targets ( "llvm" )
827840def test_batch_matmul ():
828841 verify_batch_matmul ((2 , 3 , 4 , 3 ), (2 , 3 , 3 , 4 ))
829842 verify_batch_matmul ((2 , 4 , 3 ), (3 , 4 ))
@@ -1024,11 +1037,9 @@ def _test_upsample_bilinear_opset9():
10241037 graph , producer_name = 'upsample_bilinear_opset9_test' )
10251038
10261039 for target , ctx in tvm .testing .enabled_targets ():
1027- tvm_out = get_tvm_output (
1028- model , in_array , target , ctx , out_shape , 'float32' )
1040+ tvm_out = get_tvm_output_with_vm (model , [in_array ], target , ctx , opset = 9 , freeze_params = True )
10291041 tvm .testing .assert_allclose (out_array , tvm_out , rtol = 1e-5 , atol = 1e-5 )
10301042
1031-
10321043def _test_upsample3d_trilinear ():
10331044 scale = 2
10341045 in_shape = (1 , 1 , 3 , 3 , 3 )
@@ -1062,7 +1073,8 @@ def _test_upsample3d_trilinear():
10621073 model , in_array , target , ctx , out_shape , 'float32' )
10631074 tvm .testing .assert_allclose (out_array , tvm_out , rtol = 1e-5 , atol = 1e-5 )
10641075
1065- @tvm .testing .uses_gpu
1076+ # TODO(mbrookhart): enable once VM supports heterogenous execution
1077+ # @tvm.testing.uses_gpu
10661078def test_upsample ():
10671079 _test_upsample_nearest ()
10681080 _test_upsample_bilinear ()
@@ -1455,7 +1467,7 @@ def verify_pad_v11(indata, pads, mode='constant', value=0.0):
14551467 outputs = [helper .make_tensor_value_info ("output" ,
14561468 TensorProto .FLOAT , list (outdata .shape ))])
14571469 else :
1458- inputs = [indata , pads , np .array ([value ])]
1470+ inputs = [indata , pads , np .array ([value ]). astype ( "float32" ) ]
14591471 outdata = np .pad (indata , pad_width = np_pads ,
14601472 mode = 'constant' , constant_values = value )
14611473 node = helper .make_node (
@@ -1471,7 +1483,7 @@ def verify_pad_v11(indata, pads, mode='constant', value=0.0):
14711483 helper .make_tensor_value_info ("pads" ,
14721484 TensorProto .INT64 ,(len (pads ),)),
14731485 helper .make_tensor_value_info ("constant_value" ,
1474- TensorProto .INT64 ,(1 ,)),
1486+ TensorProto .FLOAT ,(1 ,)),
14751487 ],
14761488 initializer = [helper .make_tensor ("pads" , TensorProto .INT64 , (len (pads ),), pads ),
14771489 helper .make_tensor ("constant_value" , TensorProto .FLOAT , (1 ,), [value ])],
@@ -1480,12 +1492,12 @@ def verify_pad_v11(indata, pads, mode='constant', value=0.0):
14801492 model = helper .make_model (graph , producer_name = 'pad_test' )
14811493 # tvm result
14821494 for target , ctx in tvm .testing .enabled_targets ():
1483- tvm_out = get_tvm_output (
1484- model , inputs , target , ctx , outdata .shape , 'float32' , opset = 11 )
1495+ tvm_out = get_tvm_output_with_vm (model , inputs , target , ctx , opset = 11 , freeze_params = False )
14851496 tvm .testing .assert_allclose (outdata , tvm_out , rtol = 1e-5 , atol = 1e-5 )
14861497
14871498
1488- @tvm .testing .uses_gpu
1499+ # TODO(mbrookhart): enable once VM supports heterogenous execution
1500+ # @tvm.testing.uses_gpu
14891501def test_pad ():
14901502 verify_pad (np .random .randn (2 , 2 ).astype (
14911503 np .float32 ), [0 , 1 , 0 , 0 ], 'constant' , 0.0 )
0 commit comments