23
23
from executorch .backends .nxp .quantizer .neutron_quantizer import NeutronQuantizer
24
24
from executorch .examples .models import MODEL_NAME_TO_MODEL
25
25
from executorch .examples .models .model_factory import EagerModelFactory
26
- from executorch .exir import EdgeCompileConfig , ExecutorchBackendConfig
26
+ from executorch .exir import (
27
+ EdgeCompileConfig ,
28
+ ExecutorchBackendConfig ,
29
+ to_edge_transform_and_lower ,
30
+ )
27
31
from executorch .extension .export_util import save_pte_program
28
- from executorch . extension . export_util . utils import export_to_edge
32
+ from torch . export import export
29
33
from torchao .quantization .pt2e .quantize_pt2e import convert_pt2e , prepare_pt2e
30
34
31
35
from .experimental .cifar_net .cifar_net import CifarNet , test_cifarnet_model
@@ -249,37 +253,28 @@ def _get_batch_size(data):
249
253
quantized_str = "quantized " if args .quantize else ""
250
254
print (f"\n Accuracy of the { quantized_str } `{ args .model_name } `: { accuracy } \n " )
251
255
252
- # 4. Export to edge program
253
- edge_compile_config = EdgeCompileConfig ()
254
- edge_program_manager = export_to_edge (
255
- module ,
256
- example_inputs ,
257
- edge_compile_config = edge_compile_config ,
256
+ # 4. Transform and lower
257
+
258
+ compile_spec = generate_neutron_compile_spec (
259
+ args . target ,
260
+ operators_not_to_delegate = args . operators_not_to_delegate ,
261
+ neutron_converter_flavor = args . neutron_converter_flavor ,
258
262
)
263
+ partitioners = [NeutronPartitioner (compile_spec )] if args .delegate else []
259
264
260
- logging .debug (f"Exported graph:\n { edge_program_manager .exported_program ().graph } " )
265
+ edge_program_manager = to_edge_transform_and_lower (
266
+ export (module , example_inputs , strict = True ),
267
+ partitioner = partitioners ,
268
+ compile_config = EdgeCompileConfig (),
269
+ )
261
270
262
271
edge_program_manager = NeutronEdgePassManager (
263
272
remove_io_quant_ops = args .remove_quant_io_ops
264
273
)(edge_program_manager )
265
274
266
- # 5. Delegate to Neutron
267
- if args .delegate :
268
- logging .info ("Executing Neutron Partitioner and Delegate" )
269
-
270
- compile_spec = generate_neutron_compile_spec (
271
- args .target ,
272
- operators_not_to_delegate = args .operators_not_to_delegate ,
273
- neutron_converter_flavor = args .neutron_converter_flavor ,
274
- )
275
- partitioner = NeutronPartitioner (compile_spec )
276
-
277
- edge_program_manager = edge_program_manager .to_backend (partitioner )
278
- logging .debug (
279
- f"Lowered graph:\n { edge_program_manager .exported_program ().graph } "
280
- )
275
+ logging .debug (f"Lowered graph:\n { edge_program_manager .exported_program ().graph } " )
281
276
282
- # 6 . Export to ExecuTorch program
277
+ # 5 . Export to ExecuTorch program
283
278
try :
284
279
exec_prog = edge_program_manager .to_executorch (
285
280
config = ExecutorchBackendConfig (extract_delegate_segments = False )
@@ -301,7 +296,7 @@ def executorch_program_to_str(ep, verbose=False):
301
296
302
297
logging .debug (f"Executorch program:\n { executorch_program_to_str (exec_prog )} " )
303
298
304
- # 7 . Serialize to *.pte
299
+ # 6 . Serialize to *.pte
305
300
model_name = f"{ args .model_name } " + (
306
301
"_nxp_delegate" if args .delegate is True else ""
307
302
)
0 commit comments