Skip to content

Commit 2435364

Browse files
zingofacebook-github-bot
authored andcommitted
Arm backend: Show delegation info from aot_arm_compiler (#5981)
Summary: This shows what operators are delegated and not. Pull Request resolved: #5981 Reviewed By: mergennachin Differential Revision: D64048404 Pulled By: digantdesai fbshipit-source-id: 8c79c4384e7df771bc7b0fd041c76625b8d87552
1 parent cf18ced commit 2435364

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

examples/arm/aot_arm_compiler.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import argparse
1111
import logging
1212
import os
13+
from typing import Optional
1314

1415
import torch
1516

@@ -19,8 +20,11 @@
1920
ArmQuantizer,
2021
get_symmetric_quantization_config,
2122
)
23+
24+
from executorch.devtools.backend_debug import get_delegation_info
2225
from executorch.exir import EdgeCompileConfig, ExecutorchBackendConfig
2326
from executorch.extension.export_util.utils import export_to_edge, save_pte_program
27+
from tabulate import tabulate
2428

2529
# Quantize model if required using the standard export quantizaion flow.
2630
from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e
@@ -198,6 +202,21 @@ def get_compile_spec(target: str, intermediates: bool) -> ArmCompileSpecBuilder:
198202
return spec_builder.build()
199203

200204

205+
def dump_delegation_info(edge, intermediate_files_folder: Optional[str] = None):
206+
graph_module = edge.exported_program().graph_module
207+
delegation_info = get_delegation_info(graph_module)
208+
df = delegation_info.get_operator_delegation_dataframe()
209+
table = tabulate(df, headers="keys", tablefmt="fancy_grid")
210+
delegation_info_string = f"Delegation info:\n{delegation_info.get_summary()}\nDelegation table:\n{table}\n"
211+
logging.info(delegation_info_string)
212+
if intermediate_files_folder is not None:
213+
delegation_file_path = os.path.join(
214+
intermediate_files_folder, "delegation_info.txt"
215+
)
216+
with open(delegation_file_path, "w") as file:
217+
file.write(delegation_info_string)
218+
219+
201220
def get_args():
202221
parser = argparse.ArgumentParser()
203222
parser.add_argument(
@@ -313,6 +332,9 @@ def get_args():
313332
logging.debug(f"Exported graph:\n{edge.exported_program().graph}")
314333
if args.delegate is True:
315334
edge = edge.to_backend(ArmPartitioner(compile_spec))
335+
336+
dump_delegation_info(edge, args.intermediates)
337+
316338
logging.debug(f"Lowered graph:\n{edge.exported_program().graph}")
317339

318340
try:

0 commit comments

Comments
 (0)