|
10 | 10 | import argparse
|
11 | 11 | import logging
|
12 | 12 | import os
|
| 13 | +from typing import Optional |
13 | 14 |
|
14 | 15 | import torch
|
15 | 16 |
|
|
19 | 20 | ArmQuantizer,
|
20 | 21 | get_symmetric_quantization_config,
|
21 | 22 | )
|
| 23 | + |
| 24 | +from executorch.devtools.backend_debug import get_delegation_info |
22 | 25 | from executorch.exir import EdgeCompileConfig, ExecutorchBackendConfig
|
23 | 26 | from executorch.extension.export_util.utils import export_to_edge, save_pte_program
|
| 27 | +from tabulate import tabulate |
24 | 28 |
|
25 | 29 | # Quantize model if required using the standard export quantizaion flow.
|
26 | 30 | from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e
|
@@ -198,6 +202,21 @@ def get_compile_spec(target: str, intermediates: bool) -> ArmCompileSpecBuilder:
|
198 | 202 | return spec_builder.build()
|
199 | 203 |
|
200 | 204 |
|
| 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 | + |
201 | 220 | def get_args():
|
202 | 221 | parser = argparse.ArgumentParser()
|
203 | 222 | parser.add_argument(
|
@@ -313,6 +332,9 @@ def get_args():
|
313 | 332 | logging.debug(f"Exported graph:\n{edge.exported_program().graph}")
|
314 | 333 | if args.delegate is True:
|
315 | 334 | edge = edge.to_backend(ArmPartitioner(compile_spec))
|
| 335 | + |
| 336 | + dump_delegation_info(edge, args.intermediates) |
| 337 | + |
316 | 338 | logging.debug(f"Lowered graph:\n{edge.exported_program().graph}")
|
317 | 339 |
|
318 | 340 | try:
|
|
0 commit comments