From dcdc236d0fa9147ddac0067ef8ca397559de398d Mon Sep 17 00:00:00 2001 From: penknife6153 Date: Sun, 15 Jun 2025 00:00:45 -0500 Subject: [PATCH 1/2] Initiate function to support getting delegated payload. --- exir/backend/utils.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/exir/backend/utils.py b/exir/backend/utils.py index eb9aeb19756..c4afdd7d535 100644 --- a/exir/backend/utils.py +++ b/exir/backend/utils.py @@ -11,7 +11,7 @@ import operator from collections import defaultdict, OrderedDict from functools import lru_cache -from typing import Dict, Iterable, List, Optional, Set, Tuple, Union +from typing import Dict, Iterable, List, Optional, Set, Tuple, Union, Any import torch from executorch.exir.backend.backend_details import ExportedProgram @@ -22,6 +22,9 @@ from executorch.exir.delegate import executorch_call_delegate from executorch.exir.dialects._ops import ops as exir_ops +# get Executorch +from executorch.exir import ExecutorchProgram + from executorch.exir.lowered_backend_module import create_submodule_from_nodes from tabulate import tabulate from torch._export.utils import is_buffer, is_lifted_tensor_constant, is_param @@ -430,6 +433,21 @@ def is_shape_dynamic(node: torch.fx.Node) -> bool: return has_free_symbols(node.meta["val"].shape) +def get_delegated_payload(exec_program: ExecutorchProgram) -> Dict[str, Any]: + """ + Get the payload of the executorch program which contains all the delegated modules. + """ + delegated_payload_list = {} + for delegate in exec_program.executorch_program.execution_plan[0].delegates: + backend_id = delegate.id + delegate_index = delegate.processed.index + # delegate_data_size[delegate_index] = (delegate.id, len(data)) + delegated_payload_list[delegate_index] = ( + backend_id, + delegate.compile_specs, + exec_program.executorch_program.backend_delegate_data[delegate_index].data, + ) + return delegated_payload_list # TODO - style: use templated types class DelegateMappingBuilder: From 8ffd99a594db51a31daa5f6e9e8edc322ae6b8eb Mon Sep 17 00:00:00 2001 From: penknife6153 Date: Sun, 15 Jun 2025 00:02:30 -0500 Subject: [PATCH 2/2] Fix lint errors. --- exir/backend/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exir/backend/utils.py b/exir/backend/utils.py index c4afdd7d535..57847f8ebb0 100644 --- a/exir/backend/utils.py +++ b/exir/backend/utils.py @@ -433,6 +433,7 @@ def is_shape_dynamic(node: torch.fx.Node) -> bool: return has_free_symbols(node.meta["val"].shape) + def get_delegated_payload(exec_program: ExecutorchProgram) -> Dict[str, Any]: """ Get the payload of the executorch program which contains all the delegated modules. @@ -449,6 +450,7 @@ def get_delegated_payload(exec_program: ExecutorchProgram) -> Dict[str, Any]: ) return delegated_payload_list + # TODO - style: use templated types class DelegateMappingBuilder: """