Skip to content

Commit ce4c066

Browse files
author
Martin Yuan
committed
Print delegation info in export_llama in verbose
1 parent fedb035 commit ce4c066

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

examples/models/llama/export_llama_lib.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import torch
2424

2525
from executorch.devtools.etrecord import generate_etrecord
26+
from executorch.devtools.backend_debug import get_delegation_info
27+
from tabulate import tabulate
2628
from executorch.exir.passes.init_mutable_pass import InitializedMutableBufferPass
2729

2830
from executorch.extension.llm.export.builder import DType, LLMEdgeManager
@@ -777,6 +779,12 @@ def _export_llama(args) -> LLMEdgeManager: # noqa: C901
777779
for partitioner in partitioners:
778780
logging.info(f"--> {partitioner.__class__.__name__}")
779781

782+
def print_delegation_info(graph_module: torch.fx.GraphModule):
783+
delegation_info = get_delegation_info(graph_module)
784+
print(delegation_info.get_summary())
785+
df = delegation_info.get_operator_delegation_dataframe()
786+
print(tabulate(df, headers="keys", tablefmt="fancy_grid"))
787+
780788
additional_passes = []
781789
if args.model in TORCHTUNE_DEFINED_MODELS:
782790
additional_passes = [InitializedMutableBufferPass(["kv_cache_pos"])]
@@ -788,6 +796,8 @@ def _export_llama(args) -> LLMEdgeManager: # noqa: C901
788796
# Copy the edge manager which will be serialized into etrecord. This is memory-wise expensive.
789797
edge_manager_copy = copy.deepcopy(builder_exported_to_edge.edge_manager)
790798
builder = builder_exported_to_edge.to_backend(partitioners)
799+
if args.verbose:
800+
print_delegation_info(builder.edge_manager.exported_program().graph_module)
791801
if args.num_sharding > 0 and args.qnn:
792802
from executorch.backends.qualcomm.utils.utils import canonicalize_program
793803

@@ -808,6 +818,8 @@ def _export_llama(args) -> LLMEdgeManager: # noqa: C901
808818
logging.info("Generated etrecord.bin")
809819
else:
810820
builder = builder_exported_to_edge.to_backend(partitioners)
821+
if args.verbose:
822+
print_delegation_info(builder.edge_manager.exported_program().graph_module)
811823
if args.num_sharding > 0 and args.qnn:
812824
from executorch.backends.qualcomm.utils.utils import canonicalize_program
813825

0 commit comments

Comments
 (0)