15
15
import executorch .kernels .quantized # noqa F401
16
16
17
17
import torch
18
- from executorch .backends .nxp .edge_passes .remove_io_quant_ops_pass import (
19
- RemoveIOQuantOpsPass ,
18
+ from executorch .backends .nxp .edge_passes .neutron_edge_pass_manager import (
19
+ NeutronEdgePassManager ,
20
20
)
21
21
from executorch .backends .nxp .neutron_partitioner import NeutronPartitioner
22
22
from executorch .backends .nxp .nxp_backend import generate_neutron_compile_spec
33
33
from torchao .quantization .pt2e .quantize_pt2e import convert_pt2e , prepare_pt2e
34
34
35
35
from .experimental .cifar_net .cifar_net import CifarNet , test_cifarnet_model
36
-
37
36
from .models .mobilenet_v2 import MobilenetV2
38
37
39
38
FORMAT = "[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s"
@@ -228,7 +227,7 @@ def _get_batch_size(data):
228
227
229
228
module = exported_program .module ()
230
229
231
- # 4 . Quantize if required
230
+ # 3 . Quantize if required
232
231
if args .quantize :
233
232
if calibration_inputs is None :
234
233
logging .warning (
@@ -254,39 +253,30 @@ def _get_batch_size(data):
254
253
quantized_str = "quantized " if args .quantize else ""
255
254
print (f"\n Accuracy of the { quantized_str } `{ args .model_name } `: { accuracy } \n " )
256
255
257
- # 5. Export to edge program
258
- partitioner_list = []
259
- if args .delegate is True :
260
- partitioner_list = [
261
- NeutronPartitioner (
262
- generate_neutron_compile_spec (
263
- args .target ,
264
- args .neutron_converter_flavor ,
265
- operators_not_to_delegate = args .operators_not_to_delegate ,
266
- )
267
- )
268
- ]
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 ,
262
+ )
263
+ partitioners = [NeutronPartitioner (compile_spec )] if args .delegate else []
269
264
270
- edge_program = to_edge_transform_and_lower (
265
+ edge_program_manager = to_edge_transform_and_lower (
271
266
export (module , example_inputs , strict = True ),
272
- partitioner = partitioner_list ,
273
- compile_config = EdgeCompileConfig (
274
- _check_ir_validity = False ,
275
- ),
267
+ partitioner = partitioners ,
268
+ compile_config = EdgeCompileConfig (),
276
269
)
277
- logging .debug (f"Exported graph:\n { edge_program .exported_program ().graph } " )
278
270
279
- if args .remove_quant_io_ops :
280
- edge_program = edge_program .transform (
281
- [RemoveIOQuantOpsPass (edge_program_manager = edge_program )]
282
- )
283
- logging .debug (
284
- f"Exported graph (RemoveIOQuantOpsPass):\n { edge_program .exported_program ().graph } "
285
- )
271
+ edge_program_manager = NeutronEdgePassManager (
272
+ remove_io_quant_ops = args .remove_quant_io_ops
273
+ )(edge_program_manager )
274
+
275
+ logging .debug (f"Lowered graph:\n { edge_program_manager .exported_program ().graph } " )
286
276
287
- # 6 . Export to ExecuTorch program
277
+ # 5 . Export to ExecuTorch program
288
278
try :
289
- exec_prog = edge_program .to_executorch (
279
+ exec_prog = edge_program_manager .to_executorch (
290
280
config = ExecutorchBackendConfig (extract_delegate_segments = False )
291
281
)
292
282
except RuntimeError as e :
@@ -306,7 +296,7 @@ def executorch_program_to_str(ep, verbose=False):
306
296
307
297
logging .debug (f"Executorch program:\n { executorch_program_to_str (exec_prog )} " )
308
298
309
- # 7 . Serialize to *.pte
299
+ # 6 . Serialize to *.pte
310
300
model_name = f"{ args .model_name } " + (
311
301
"_nxp_delegate" if args .delegate is True else ""
312
302
)
0 commit comments