2121
2222
2323def save_bundled_program (
24+ method_names ,
2425 inputs ,
2526 exec_prog ,
2627 graph_module ,
@@ -30,20 +31,20 @@ def save_bundled_program(
3031 # set for the model. If we wish to test the model with multiple inputs then they can be
3132 # appended to this list. len(inputs) == number of test sets we want to run.
3233 #
33- # If we have multiple execution plans in this program then we add another list of tuples
34- # to test that corresponding execution plan . Index of list of tuples will match the index
35- # of the execution plan against which it will be tested.
34+ # If we have multiple methods in this program then we add another list of tuples to test
35+ # that corresponding method . Index of list of tuples will match the index of the method's name
36+ # in the method_names list forwarded to BundledConfig against which it will be tested.
3637 bundled_inputs = [inputs for _ in range (len (exec_prog .program .execution_plan ))]
3738
3839 # For each input tuple we run the graph module and put the resulting output in a list. This
39- # is repeated over all the tuples present in the input list and then repeated for each execution
40- # plan we want to test against.
40+ # is repeated over all the tuples present in the input list and then repeated for each method
41+ # name we want to test against.
4142 expected_outputs = [
4243 [[graph_module (* x )] for x in inputs ]
4344 for i in range (len (exec_prog .program .execution_plan ))
4445 ]
4546
46- bundled_config = BundledConfig (bundled_inputs , expected_outputs )
47+ bundled_config = BundledConfig (method_names , bundled_inputs , expected_outputs )
4748
4849 bundled_program = create_bundled_program (exec_prog .program , bundled_config )
4950 bundled_program_buffer = serialize_from_bundled_program_to_flatbuffer (
@@ -54,16 +55,18 @@ def save_bundled_program(
5455 file .write (bundled_program_buffer )
5556
5657
57- def export_to_pte (model_name , model , example_inputs ):
58+ def export_to_pte (model_name , model , method_names , example_inputs ):
5859 exec_prog = export_to_exec_prog (model , example_inputs )
5960 save_pte_program (exec_prog .buffer , model_name )
6061
6162 # Just as an example to show how multiple input sets can be bundled along, here we
6263 # create a list with the example_inputs tuple used twice. Each instance of example_inputs
6364 # is a Tuple[Union[torch.tenor, int, bool]] which represents one test set for the model.
6465 bundled_inputs = [example_inputs , example_inputs ]
65- print (f"Saving exported program to { model_name } _bundled.pte" )
66- save_bundled_program (bundled_inputs , exec_prog , model , f"{ model_name } _bundled.pte" )
66+ print (f"Saving exported program to { model_name } _bundled.bp" )
67+ save_bundled_program (
68+ method_names , bundled_inputs , exec_prog , model , f"{ model_name } _bundled.bp"
69+ )
6770
6871
6972if __name__ == "__main__" :
@@ -87,4 +90,6 @@ def export_to_pte(model_name, model, example_inputs):
8790 * MODEL_NAME_TO_MODEL [args .model_name ]
8891 )
8992
90- export_to_pte (args .model_name , model , example_inputs )
93+ method_names = ["forward" ]
94+
95+ export_to_pte (args .model_name , model , method_names , example_inputs )
0 commit comments