Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion backends/arm/operators/op_abs.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def define_node(
abs_output = output

# Do the INT32 Abs
tosa_graph.addOperator(
self._serialize_operator(
node,
tosa_graph,
ts.TosaOp.Op().ABS,
[
rescaled_inputs[0].name,
Expand Down
8 changes: 6 additions & 2 deletions backends/arm/operators/op_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def define_node(
dtype=ts.DType.INT32,
)

tosa_graph.addOperator(
self._serialize_operator(
node,
tosa_graph,
ts.TosaOp.Op().REDUCE_SUM,
[rescaled_inputs[0].name],
[intermediate.name],
Expand Down Expand Up @@ -111,7 +113,9 @@ def define_node(
attr = ts.TosaSerializerAttribute()
attr.ReduceSumAttribute(tensor.dim_order.index(dim))

tosa_graph.addOperator(
self._serialize_operator(
node,
tosa_graph,
ts.TosaOp.Op().REDUCE_SUM,
[tensor.name],
[output.name],
Expand Down
24 changes: 23 additions & 1 deletion examples/arm/aot_arm_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import torch
from examples.devtools.scripts.export_bundled_program import save_bundled_program
from executorch.backends.arm.common.arm_compile_spec import ArmCompileSpec
from executorch.backends.arm.ethosu import EthosUCompileSpec, EthosUPartitioner
from executorch.backends.arm.quantizer import (
EthosUQuantizer,
Expand Down Expand Up @@ -386,6 +387,7 @@ def get_compile_spec(
memory_mode: Optional[str] = None,
quantize: bool = False,
config: Optional[str] = None,
debug_mode: Optional[str] = None,
) -> TosaCompileSpec | EthosUCompileSpec | VgfCompileSpec:
compile_spec = None
if target.startswith("TOSA"):
Expand Down Expand Up @@ -414,6 +416,10 @@ def get_compile_spec(
if intermediates is not None:
compile_spec.dump_intermediate_artifacts_to(intermediates)

if debug_mode is not None:
mode = ArmCompileSpec.DebugMode[debug_mode.upper()]
compile_spec.dump_debug_info(mode)

return compile_spec


Expand Down Expand Up @@ -601,6 +607,12 @@ def get_args():
action="store_true",
help="Enable the QuantizedOpFusionPass fusion step",
)
parser.add_argument(
"--enable_debug_mode",
required=False,
choices=["json", "tosa"],
help="Flag to enable ATen-to-TOSA debug mode.",
)
args = parser.parse_args()

if args.evaluate and (
Expand Down Expand Up @@ -735,6 +747,7 @@ def to_edge_TOSA_delegate(
args.memory_mode,
args.quantize,
args.config,
args.enable_debug_mode,
)

model_int8 = None
Expand Down Expand Up @@ -776,6 +789,7 @@ def to_edge_no_delegate(exported_program, args, model: torch.nn.Module, example_
args.memory_mode,
args.quantize,
args.config,
args.enable_debug_mode,
)
model, exported_program = quantize_model(
args, model, example_inputs, compile_spec
Expand Down Expand Up @@ -824,12 +838,21 @@ def transform_for_cortex_m_backend(edge, args):
exported_program = torch.export.export(
model, example_inputs, strict=args.strict_export
)

model = exported_program.module()
model_fp32 = model

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

# We only support Python3.10 and above, so use a later pickle protocol
torch.export.save(
exported_program,
f"{args.intermediates}/{model_name}_exported_program.pt2",
pickle_protocol=5,
)

# Quantize if required
model_int8 = None
if args.delegate:
Expand Down Expand Up @@ -862,7 +885,6 @@ def transform_for_cortex_m_backend(edge, args):
else:
raise e

model_name = os.path.basename(os.path.splitext(args.model_name)[0])
output_name = f"{model_name}" + (
f"_arm_delegate_{args.target}"
if args.delegate is True
Expand Down
Loading