@@ -815,66 +815,14 @@ def clz_comp(n):
815815
816816@pytest .mark .parametrize ("accel_type" , ACCEL_TYPES )
817817def test_tflite_tanh (accel_type ):
818- dtype = "int8"
819818 ifm_shape = [1 , 115 , 32 , 7 ]
820819
821- def create_tflite_graph ():
822- class Model (tf .Module ):
823- @tf .function
824- def tanh_function (self , x ):
825- op = tf .nn .tanh (x )
826- return op
827-
828- model = Model ()
829- concrete_func = model .tanh_function .get_concrete_function (
830- tf .TensorSpec (ifm_shape , dtype = tf .float32 )
831- )
832-
833- # Convert the model
834- def representative_dataset ():
835- for _ in range (100 ):
836- data = np .random .rand (* tuple (ifm_shape ))
837- yield [data .astype (np .float32 )]
838-
839- converter = tf .lite .TFLiteConverter .from_concrete_functions ([concrete_func ])
840- converter .optimizations = [tf .lite .Optimize .DEFAULT ]
841- converter .representative_dataset = representative_dataset
842- converter .target_spec .supported_ops = [tf .lite .OpsSet .TFLITE_BUILTINS_INT8 ]
843- converter .inference_input_type = tf .int8
844- converter .inference_output_type = tf .int8
845- tflite_model = converter .convert ()
846- return tflite_model
847-
848- tflite_graph = create_tflite_graph ()
849-
850- tflite_model = tflite .Model .Model .GetRootAsModel (tflite_graph , 0 )
851-
852- relay_module , params = relay .frontend .from_tflite (
853- tflite_model ,
854- shape_dict = {"input" : ifm_shape },
855- dtype_dict = {"input" : dtype },
856- )
857- mod = partition_for_ethosu (relay_module , params )
858-
859- # Generate reference data
860- input_data , output_data = infra .generate_ref_data_tflite (tflite_graph )
861-
862- compiled_models = infra .build_source (
863- mod ,
864- input_data ,
865- output_data ,
866- accel_type ,
867- )
868-
869- # Assumes only two runtime.Modules are created -- i.e. single offload module
870- ethosu_module = compiled_models [0 ].executor_factory .lib .imported_modules [0 ].imported_modules [0 ]
820+ @tf .function
821+ def tanh_func (x ):
822+ op = tf .nn .tanh (x )
823+ return op
871824
872- # Verify generated C source
873- get_artifacts = tvm ._ffi .get_global_func ("runtime.module.ethos-u.get_artifacts" )
874- compilation_artifacts = get_artifacts (ethosu_module )
875- cmms = bytes .fromhex (compilation_artifacts [0 ].command_stream )
876- infra .print_payload (cmms )
877- infra .verify_source (compiled_models , accel_type )
825+ _compare_tvm_with_tflite (tanh_func , [ifm_shape ], accel_type )
878826
879827
880828@pytest .mark .parametrize ("accel_type" , ACCEL_TYPES )
@@ -897,68 +845,15 @@ def concat_func(*inputs):
897845
898846
899847@pytest .mark .parametrize ("accel_type" , ACCEL_TYPES )
900- @pytest .mark .parametrize ("ifm_shape" , [[1 , 115 , 32 , 7 ], [1 , 4 , 5 , 2 ]])
901- def test_tflite_sigmoid (accel_type , ifm_shape ):
902- dtype = "int8"
903-
904- def create_tflite_graph ():
905- tf .config .run_functions_eagerly (True )
906-
907- class Model (tf .Module ):
908- @tf .function
909- def tanh_function (self , x ):
910- op = tf .nn .sigmoid (x )
911- return op
912-
913- model = Model ()
914- concrete_func = model .tanh_function .get_concrete_function (
915- tf .TensorSpec (ifm_shape , dtype = tf .float32 )
916- )
917-
918- # Convert the model
919- def representative_dataset ():
920- for _ in range (100 ):
921- data = np .random .rand (* tuple (ifm_shape ))
922- yield [data .astype (np .float32 )]
923-
924- converter = tf .lite .TFLiteConverter .from_concrete_functions ([concrete_func ])
925- converter .optimizations = [tf .lite .Optimize .DEFAULT ]
926- converter .representative_dataset = representative_dataset
927- converter .target_spec .supported_ops = [tf .lite .OpsSet .TFLITE_BUILTINS_INT8 ]
928- converter .inference_input_type = tf .int8
929- converter .inference_output_type = tf .int8
930- tflite_model = converter .convert ()
931- return tflite_model
932-
933- tflite_graph = create_tflite_graph ()
934- tflite_model = tflite .Model .Model .GetRootAsModel (tflite_graph , 0 )
935-
936- relay_module , params = relay .frontend .from_tflite (
937- tflite_model ,
938- shape_dict = {"input" : ifm_shape },
939- dtype_dict = {"input" : dtype },
940- )
941- mod = partition_for_ethosu (relay_module , params )
942-
943- # Generate reference data
944- input_data , output_data = infra .generate_ref_data_tflite (tflite_graph )
945-
946- compiled_models = infra .build_source (
947- mod ,
948- input_data ,
949- output_data ,
950- accel_type ,
951- )
848+ def test_tflite_sigmoid (accel_type ):
849+ ifm_shape = [1 , 135 , 41 , 6 ]
952850
953- # Assumes only two runtime.Modules are created -- i.e. single offload module
954- ethosu_module = compiled_models [0 ].executor_factory .lib .imported_modules [0 ].imported_modules [0 ]
851+ @tf .function
852+ def sigmoid_function (x ):
853+ op = tf .nn .sigmoid (x )
854+ return op
955855
956- # Verify generated C source
957- get_artifacts = tvm ._ffi .get_global_func ("runtime.module.ethos-u.get_artifacts" )
958- compilation_artifacts = get_artifacts (ethosu_module )
959- cmms = bytes .fromhex (compilation_artifacts [0 ].command_stream )
960- infra .print_payload (cmms )
961- infra .verify_source (compiled_models , accel_type )
856+ _compare_tvm_with_tflite (sigmoid_function , [ifm_shape ], accel_type )
962857
963858
964859if __name__ == "__main__" :
0 commit comments