8
8
9
9
import torch
10
10
from executorch import exir
11
+ from executorch .exir import to_edge
11
12
from executorch .exir .backend .backend_api import to_backend
12
13
from executorch .exir .backend .test .demos .rpc .executor_backend_partitioner import (
13
14
ExecutorBackendPartitioner ,
20
21
from executorch .extension .pybindings .portable_lib import ( # @manual
21
22
_load_for_executorch_from_buffer ,
22
23
)
24
+ from torch .export import export
23
25
from torch .utils ._pytree import tree_flatten
24
26
25
27
"""
@@ -101,16 +103,15 @@ def test_delegate_whole_program(self):
101
103
102
104
simple_net = self .get_a_simple_net ()
103
105
simple_net_input = simple_net .get_example_inputs ()
104
- exported_program = exir .capture (
105
- simple_net , simple_net_input , exir .CaptureConfig ()
106
- ).to_edge (
107
- exir .EdgeCompileConfig (
106
+ exported_program = to_edge (
107
+ export (simple_net , simple_net_input ),
108
+ compile_config = exir .EdgeCompileConfig (
108
109
_check_ir_validity = False ,
109
- )
110
+ ),
110
111
)
111
112
# delegate the whole graph to the client executor
112
113
lowered_module = to_backend (
113
- ExecutorBackend .__name__ , exported_program .exported_program , []
114
+ ExecutorBackend .__name__ , exported_program .exported_program () , []
114
115
)
115
116
116
117
class CompositeModule (torch .nn .Module ):
@@ -123,11 +124,7 @@ def forward(self, *args):
123
124
124
125
composite_model = CompositeModule ()
125
126
126
- exec_prog = (
127
- exir .capture (composite_model , simple_net_input , exir .CaptureConfig ())
128
- .to_edge ()
129
- .to_executorch ()
130
- )
127
+ exec_prog = to_edge (export (composite_model , simple_net_input )).to_executorch ()
131
128
132
129
executorch_module = _load_for_executorch_from_buffer (exec_prog .buffer )
133
130
@@ -162,18 +159,14 @@ def forward(self, a, x, b):
162
159
model = Model ()
163
160
inputs = (torch .ones (2 , 2 ), torch .ones (2 , 2 ), torch .ones (2 , 2 ))
164
161
165
- exported_program = exir . capture ( model , inputs , exir . CaptureConfig ()). to_edge ( )
162
+ exported_program = to_edge ( export ( model , inputs ) )
166
163
167
164
# First lower to demo backend
168
- demo_backend_lowered = exported_program
169
- demo_backend_lowered .exported_program = to_backend (
170
- exported_program .exported_program , AddMulPartitionerDemo ()
171
- )
165
+ demo_backend_lowered = exported_program .to_backend (AddMulPartitionerDemo ())
172
166
173
167
# Then lower to executor backend
174
- executor_backend_lowered = demo_backend_lowered
175
- executor_backend_lowered .exported_program = to_backend (
176
- demo_backend_lowered .exported_program , ExecutorBackendPartitioner ()
168
+ executor_backend_lowered = demo_backend_lowered .to_backend (
169
+ ExecutorBackendPartitioner ()
177
170
)
178
171
179
172
prog_buffer = executor_backend_lowered .to_executorch ()
0 commit comments