Skip to content

Commit 8c51641

Browse files
authored
Arm backend: Add --enable_debug_mode to AOT compiler (#14145)
* Add --enable_debug_mode to enable ATen to TOSA debugging * Dump ATen graph when --intermediates is enabled * Add missing _serialize_operator() calls Signed-off-by: Tom Allsop <[email protected]>
1 parent 4d6209b commit 8c51641

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

backends/arm/operators/op_abs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ def define_node(
7373
abs_output = output
7474

7575
# Do the INT32 Abs
76-
tosa_graph.addOperator(
76+
self._serialize_operator(
77+
node,
78+
tosa_graph,
7779
ts.TosaOp.Op().ABS,
7880
[
7981
rescaled_inputs[0].name,

backends/arm/operators/op_sum.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def define_node(
6767
dtype=ts.DType.INT32,
6868
)
6969

70-
tosa_graph.addOperator(
70+
self._serialize_operator(
71+
node,
72+
tosa_graph,
7173
ts.TosaOp.Op().REDUCE_SUM,
7274
[rescaled_inputs[0].name],
7375
[intermediate.name],
@@ -111,7 +113,9 @@ def define_node(
111113
attr = ts.TosaSerializerAttribute()
112114
attr.ReduceSumAttribute(tensor.dim_order.index(dim))
113115

114-
tosa_graph.addOperator(
116+
self._serialize_operator(
117+
node,
118+
tosa_graph,
115119
ts.TosaOp.Op().REDUCE_SUM,
116120
[tensor.name],
117121
[output.name],

examples/arm/aot_arm_compiler.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import torch
2020
from examples.devtools.scripts.export_bundled_program import save_bundled_program
21+
from executorch.backends.arm.common.arm_compile_spec import ArmCompileSpec
2122
from executorch.backends.arm.ethosu import EthosUCompileSpec, EthosUPartitioner
2223
from executorch.backends.arm.quantizer import (
2324
EthosUQuantizer,
@@ -386,6 +387,7 @@ def get_compile_spec(
386387
memory_mode: Optional[str] = None,
387388
quantize: bool = False,
388389
config: Optional[str] = None,
390+
debug_mode: Optional[str] = None,
389391
) -> TosaCompileSpec | EthosUCompileSpec | VgfCompileSpec:
390392
compile_spec = None
391393
if target.startswith("TOSA"):
@@ -414,6 +416,10 @@ def get_compile_spec(
414416
if intermediates is not None:
415417
compile_spec.dump_intermediate_artifacts_to(intermediates)
416418

419+
if debug_mode is not None:
420+
mode = ArmCompileSpec.DebugMode[debug_mode.upper()]
421+
compile_spec.dump_debug_info(mode)
422+
417423
return compile_spec
418424

419425

@@ -601,6 +607,12 @@ def get_args():
601607
action="store_true",
602608
help="Enable the QuantizedOpFusionPass fusion step",
603609
)
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+
)
604616
args = parser.parse_args()
605617

606618
if args.evaluate and (
@@ -735,6 +747,7 @@ def to_edge_TOSA_delegate(
735747
args.memory_mode,
736748
args.quantize,
737749
args.config,
750+
args.enable_debug_mode,
738751
)
739752

740753
model_int8 = None
@@ -776,6 +789,7 @@ def to_edge_no_delegate(exported_program, args, model: torch.nn.Module, example_
776789
args.memory_mode,
777790
args.quantize,
778791
args.config,
792+
args.enable_debug_mode,
779793
)
780794
model, exported_program = quantize_model(
781795
args, model, example_inputs, compile_spec
@@ -824,12 +838,21 @@ def transform_for_cortex_m_backend(edge, args):
824838
exported_program = torch.export.export(
825839
model, example_inputs, strict=args.strict_export
826840
)
841+
827842
model = exported_program.module()
828843
model_fp32 = model
829844

845+
model_name = os.path.basename(os.path.splitext(args.model_name)[0])
830846
if args.intermediates:
831847
os.makedirs(args.intermediates, exist_ok=True)
832848

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+
833856
# Quantize if required
834857
model_int8 = None
835858
if args.delegate:
@@ -862,7 +885,6 @@ def transform_for_cortex_m_backend(edge, args):
862885
else:
863886
raise e
864887

865-
model_name = os.path.basename(os.path.splitext(args.model_name)[0])
866888
output_name = f"{model_name}" + (
867889
f"_arm_delegate_{args.target}"
868890
if args.delegate is True

0 commit comments

Comments
 (0)