16
16
import subprocess
17
17
from typing import List
18
18
19
- import executorch .exir as exir
20
-
21
19
import torch
22
- from executorch .exir import ExecutorchBackendConfig
20
+ from executorch .exir import ExecutorchBackendConfig , to_edge
23
21
24
22
from executorch .exir .passes import MemoryPlanningPass , ToOutVarPass
25
23
from executorch .exir .print_program import pretty_print
30
28
)
31
29
32
30
from executorch .test .models .linear_model import LinearModel
31
+ from torch .export import export
33
32
34
33
35
34
def main () -> None :
@@ -38,21 +37,17 @@ def main() -> None:
38
37
trace_inputs = (torch .ones (2 , 2 , dtype = torch .float ),)
39
38
40
39
# Trace to FX Graph.
41
- exec_prog = (
42
- exir .capture (model , trace_inputs )
43
- .to_edge ()
44
- .to_executorch (
45
- config = ExecutorchBackendConfig (
46
- memory_planning_pass = MemoryPlanningPass (),
47
- to_out_var_pass = ToOutVarPass (),
48
- )
40
+ exec_prog = to_edge (export (model , trace_inputs )).to_executorch (
41
+ config = ExecutorchBackendConfig (
42
+ memory_planning_pass = MemoryPlanningPass (),
43
+ to_out_var_pass = ToOutVarPass (),
49
44
)
50
45
)
51
46
# Emit in-memory representation.
52
- pretty_print (exec_prog .program )
47
+ pretty_print (exec_prog .executorch_program )
53
48
54
49
# Serialize to flatbuffer.
55
- exec_prog .program .version = 0
50
+ exec_prog .executorch_program .version = 0
56
51
57
52
# Create test sets
58
53
method_test_cases : List [MethodTestCase ] = []
@@ -66,7 +61,6 @@ def main() -> None:
66
61
]
67
62
68
63
bundled_program = BundledProgram (exec_prog , method_test_suites )
69
- pretty_print (bundled_program )
70
64
71
65
bundled_program_flatbuffer = serialize_from_bundled_program_to_flatbuffer (
72
66
bundled_program
@@ -76,7 +70,7 @@ def main() -> None:
76
70
subprocess .run (["hg" , "root" ], stdout = subprocess .PIPE ).stdout .decode ().strip ()
77
71
)
78
72
with open (
79
- f"{ fbsource_base_path } /fbcode/executorch/test/models/linear_out_bundled_program.pte " ,
73
+ f"{ fbsource_base_path } /fbcode/executorch/test/models/linear_out_bundled_program.bpte " ,
80
74
"wb" ,
81
75
) as file :
82
76
file .write (bundled_program_flatbuffer )
0 commit comments