Skip to content

Commit 62cba60

Browse files
Gasoonjiafacebook-github-bot
authored andcommitted
Update bp export example (#633)
Summary: Pull Request resolved: #633 Update the export example for bundled program, including api update, comments and file name suffix. Reviewed By: tarun292 Differential Revision: D49849371 fbshipit-source-id: ba0faaecf4b6af1ae9d02d5d7f86a00b79379f5a
1 parent 1ed6250 commit 62cba60

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

examples/export/export_bundled_program.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222

2323
def 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

6972
if __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

Comments
 (0)