Skip to content

Commit 3156f34

Browse files
iseeyuanMartin Yuan
authored andcommitted
Print delegation info in export_llama in verbose (#7803)
Co-authored-by: Martin Yuan <[email protected]>
1 parent 12f7efd commit 3156f34

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
@@ -21,6 +21,7 @@
2121

2222
import pkg_resources
2323
import torch
24+
from executorch.devtools.backend_debug import get_delegation_info
2425

2526
from executorch.devtools.etrecord import generate_etrecord
2627
from executorch.exir.passes.init_mutable_pass import InitializedMutableBufferPass
@@ -43,6 +44,7 @@
4344
get_vulkan_quantizer,
4445
)
4546
from executorch.util.activation_memory_profiler import generate_memory_trace
47+
from tabulate import tabulate
4648

4749
from ..model_factory import EagerModelFactory
4850
from .source_transformation.apply_spin_quant_r1_r2 import (
@@ -800,6 +802,12 @@ def _export_llama(args) -> LLMEdgeManager: # noqa: C901
800802
for partitioner in partitioners:
801803
logging.info(f"--> {partitioner.__class__.__name__}")
802804

805+
def print_delegation_info(graph_module: torch.fx.GraphModule):
806+
delegation_info = get_delegation_info(graph_module)
807+
print(delegation_info.get_summary())
808+
df = delegation_info.get_operator_delegation_dataframe()
809+
print(tabulate(df, headers="keys", tablefmt="fancy_grid"))
810+
803811
additional_passes = []
804812
if args.model in TORCHTUNE_DEFINED_MODELS:
805813
additional_passes = [InitializedMutableBufferPass(["kv_cache_pos"])]
@@ -811,6 +819,8 @@ def _export_llama(args) -> LLMEdgeManager: # noqa: C901
811819
# Copy the edge manager which will be serialized into etrecord. This is memory-wise expensive.
812820
edge_manager_copy = copy.deepcopy(builder_exported_to_edge.edge_manager)
813821
builder = builder_exported_to_edge.to_backend(partitioners)
822+
if args.verbose:
823+
print_delegation_info(builder.edge_manager.exported_program().graph_module)
814824
if args.num_sharding > 0 and args.qnn:
815825
from executorch.backends.qualcomm.utils.utils import canonicalize_program
816826

@@ -831,6 +841,8 @@ def _export_llama(args) -> LLMEdgeManager: # noqa: C901
831841
logging.info("Generated etrecord.bin")
832842
else:
833843
builder = builder_exported_to_edge.to_backend(partitioners)
844+
if args.verbose:
845+
print_delegation_info(builder.edge_manager.exported_program().graph_module)
834846
if args.num_sharding > 0 and args.qnn:
835847
from executorch.backends.qualcomm.utils.utils import canonicalize_program
836848

0 commit comments

Comments
 (0)