21
21
22
22
23
23
def save_bundled_program (
24
+ method_names ,
24
25
inputs ,
25
26
exec_prog ,
26
27
graph_module ,
@@ -30,20 +31,20 @@ def save_bundled_program(
30
31
# set for the model. If we wish to test the model with multiple inputs then they can be
31
32
# appended to this list. len(inputs) == number of test sets we want to run.
32
33
#
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.
36
37
bundled_inputs = [inputs for _ in range (len (exec_prog .program .execution_plan ))]
37
38
38
39
# 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.
41
42
expected_outputs = [
42
43
[[graph_module (* x )] for x in inputs ]
43
44
for i in range (len (exec_prog .program .execution_plan ))
44
45
]
45
46
46
- bundled_config = BundledConfig (bundled_inputs , expected_outputs )
47
+ bundled_config = BundledConfig (method_names , bundled_inputs , expected_outputs )
47
48
48
49
bundled_program = create_bundled_program (exec_prog .program , bundled_config )
49
50
bundled_program_buffer = serialize_from_bundled_program_to_flatbuffer (
@@ -54,16 +55,18 @@ def save_bundled_program(
54
55
file .write (bundled_program_buffer )
55
56
56
57
57
- def export_to_pte (model_name , model , example_inputs ):
58
+ def export_to_pte (model_name , model , method_names , example_inputs ):
58
59
exec_prog = export_to_exec_prog (model , example_inputs )
59
60
save_pte_program (exec_prog .buffer , model_name )
60
61
61
62
# Just as an example to show how multiple input sets can be bundled along, here we
62
63
# create a list with the example_inputs tuple used twice. Each instance of example_inputs
63
64
# is a Tuple[Union[torch.tenor, int, bool]] which represents one test set for the model.
64
65
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
+ )
67
70
68
71
69
72
if __name__ == "__main__" :
@@ -87,4 +90,6 @@ def export_to_pte(model_name, model, example_inputs):
87
90
* MODEL_NAME_TO_MODEL [args .model_name ]
88
91
)
89
92
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