Skip to content

Commit

Permalink
Arm backend: Show delegation info from aot_arm_compiler (pytorch#5981)
Browse files Browse the repository at this point in the history
Summary:
This shows what operators are delegated and not.

Pull Request resolved: pytorch#5981

Reviewed By: mergennachin

Differential Revision: D64048404

Pulled By: digantdesai

fbshipit-source-id: 8c79c4384e7df771bc7b0fd041c76625b8d87552
  • Loading branch information
zingo authored and facebook-github-bot committed Oct 8, 2024
1 parent cf18ced commit 2435364
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions examples/arm/aot_arm_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import argparse
import logging
import os
from typing import Optional

import torch

Expand All @@ -19,8 +20,11 @@
ArmQuantizer,
get_symmetric_quantization_config,
)

from executorch.devtools.backend_debug import get_delegation_info
from executorch.exir import EdgeCompileConfig, ExecutorchBackendConfig
from executorch.extension.export_util.utils import export_to_edge, save_pte_program
from tabulate import tabulate

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


def dump_delegation_info(edge, intermediate_files_folder: Optional[str] = None):
graph_module = edge.exported_program().graph_module
delegation_info = get_delegation_info(graph_module)
df = delegation_info.get_operator_delegation_dataframe()
table = tabulate(df, headers="keys", tablefmt="fancy_grid")
delegation_info_string = f"Delegation info:\n{delegation_info.get_summary()}\nDelegation table:\n{table}\n"
logging.info(delegation_info_string)
if intermediate_files_folder is not None:
delegation_file_path = os.path.join(
intermediate_files_folder, "delegation_info.txt"
)
with open(delegation_file_path, "w") as file:
file.write(delegation_info_string)


def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down Expand Up @@ -313,6 +332,9 @@ def get_args():
logging.debug(f"Exported graph:\n{edge.exported_program().graph}")
if args.delegate is True:
edge = edge.to_backend(ArmPartitioner(compile_spec))

dump_delegation_info(edge, args.intermediates)

logging.debug(f"Lowered graph:\n{edge.exported_program().graph}")

try:
Expand Down

0 comments on commit 2435364

Please sign in to comment.