|
18 | 18 |
|
19 | 19 | import torch
|
20 | 20 | from examples.devtools.scripts.export_bundled_program import save_bundled_program
|
| 21 | +from executorch.backends.arm.common.arm_compile_spec import ArmCompileSpec |
21 | 22 | from executorch.backends.arm.ethosu import EthosUCompileSpec, EthosUPartitioner
|
22 | 23 | from executorch.backends.arm.quantizer import (
|
23 | 24 | EthosUQuantizer,
|
@@ -386,6 +387,7 @@ def get_compile_spec(
|
386 | 387 | memory_mode: Optional[str] = None,
|
387 | 388 | quantize: bool = False,
|
388 | 389 | config: Optional[str] = None,
|
| 390 | + debug_mode: Optional[str] = None, |
389 | 391 | ) -> TosaCompileSpec | EthosUCompileSpec | VgfCompileSpec:
|
390 | 392 | compile_spec = None
|
391 | 393 | if target.startswith("TOSA"):
|
@@ -414,6 +416,10 @@ def get_compile_spec(
|
414 | 416 | if intermediates is not None:
|
415 | 417 | compile_spec.dump_intermediate_artifacts_to(intermediates)
|
416 | 418 |
|
| 419 | + if debug_mode is not None: |
| 420 | + mode = ArmCompileSpec.DebugMode[debug_mode.upper()] |
| 421 | + compile_spec.dump_debug_info(mode) |
| 422 | + |
417 | 423 | return compile_spec
|
418 | 424 |
|
419 | 425 |
|
@@ -601,6 +607,12 @@ def get_args():
|
601 | 607 | action="store_true",
|
602 | 608 | help="Enable the QuantizedOpFusionPass fusion step",
|
603 | 609 | )
|
| 610 | + parser.add_argument( |
| 611 | + "--enable_debug_mode", |
| 612 | + required=False, |
| 613 | + choices=["json", "tosa"], |
| 614 | + help="Flag to enable ATen-to-TOSA debug mode.", |
| 615 | + ) |
604 | 616 | args = parser.parse_args()
|
605 | 617 |
|
606 | 618 | if args.evaluate and (
|
@@ -735,6 +747,7 @@ def to_edge_TOSA_delegate(
|
735 | 747 | args.memory_mode,
|
736 | 748 | args.quantize,
|
737 | 749 | args.config,
|
| 750 | + args.enable_debug_mode, |
738 | 751 | )
|
739 | 752 |
|
740 | 753 | model_int8 = None
|
@@ -776,6 +789,7 @@ def to_edge_no_delegate(exported_program, args, model: torch.nn.Module, example_
|
776 | 789 | args.memory_mode,
|
777 | 790 | args.quantize,
|
778 | 791 | args.config,
|
| 792 | + args.enable_debug_mode, |
779 | 793 | )
|
780 | 794 | model, exported_program = quantize_model(
|
781 | 795 | args, model, example_inputs, compile_spec
|
@@ -824,12 +838,21 @@ def transform_for_cortex_m_backend(edge, args):
|
824 | 838 | exported_program = torch.export.export(
|
825 | 839 | model, example_inputs, strict=args.strict_export
|
826 | 840 | )
|
| 841 | + |
827 | 842 | model = exported_program.module()
|
828 | 843 | model_fp32 = model
|
829 | 844 |
|
| 845 | + model_name = os.path.basename(os.path.splitext(args.model_name)[0]) |
830 | 846 | if args.intermediates:
|
831 | 847 | os.makedirs(args.intermediates, exist_ok=True)
|
832 | 848 |
|
| 849 | + # We only support Python3.10 and above, so use a later pickle protocol |
| 850 | + torch.export.save( |
| 851 | + exported_program, |
| 852 | + f"{args.intermediates}/{model_name}_exported_program.pt2", |
| 853 | + pickle_protocol=5, |
| 854 | + ) |
| 855 | + |
833 | 856 | # Quantize if required
|
834 | 857 | model_int8 = None
|
835 | 858 | if args.delegate:
|
@@ -862,7 +885,6 @@ def transform_for_cortex_m_backend(edge, args):
|
862 | 885 | else:
|
863 | 886 | raise e
|
864 | 887 |
|
865 |
| - model_name = os.path.basename(os.path.splitext(args.model_name)[0]) |
866 | 888 | output_name = f"{model_name}" + (
|
867 | 889 | f"_arm_delegate_{args.target}"
|
868 | 890 | if args.delegate is True
|
|
0 commit comments