Skip to content

Commit 412c435

Browse files
Olivia-liufacebook-github-bot
authored andcommitted
Add a default delegate time scale converter (#5076)
Summary: Pull Request resolved: #5076 By default, the non-delegated events have a time scale converter, but delegated events do not, and this has caused confusion for users: [post](https://fb.workplace.com/groups/pytorch.edge.users/permalink/1562687731268181/), [Issue #4504](#4504). This diff gives a quick solution for the problem to unblock ET Beta. The rationale is that since for non-delegated ops, we have the default time scale: ``` source_time_scale: TimeScale = TimeScale.NS, target_time_scale: TimeScale = TimeScale.MS, ``` And the conversion rate is 10^6 (because 1 MS = 10^6 NS), so it makes sense to set a default converter function for delegated ops to be `input_time/(1000 * 1000)` as well. Similar converter functions have been used by [coreml](https://www.internalfb.com/code/fbsource/[76be64aab17c]/fbcode/executorch/examples/apple/coreml/scripts/inspector_utils.py?lines=259-262) and [vulkan](https://fburl.com/code/5cu6fx2b) already. The proper solution to write the convertion in etdump is tracked by T198369344 and T198369419 Differential Revision: D62160650
1 parent 8781604 commit 412c435

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

devtools/inspector/_inspector.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from executorch.devtools.etrecord import ETRecord, parse_etrecord
4141
from executorch.devtools.inspector._inspector_utils import (
4242
create_debug_handle_to_op_node_mapping,
43+
default_delegate_time_scale_converter,
4344
EDGE_DIALECT_GRAPH_KEY,
4445
EXCLUDED_COLUMNS_WHEN_PRINTING,
4546
EXCLUDED_EVENTS_WHEN_PRINTING,
@@ -949,9 +950,9 @@ def __init__(
949950
delegate_metadata_parser: Optional[
950951
Callable[[List[str]], Dict[str, Any]]
951952
] = None,
952-
delegate_time_scale_converter: Optional[
953-
Callable[[Union[int, str], Union[int, float]], Union[int, float]]
954-
] = None,
953+
delegate_time_scale_converter: Callable[
954+
[Union[int, str], Union[int, float]], Union[int, float]
955+
] = default_delegate_time_scale_converter,
955956
enable_module_hierarchy: bool = False,
956957
) -> None:
957958
r"""
@@ -966,6 +967,8 @@ def __init__(
966967
debug_buffer_path: Debug buffer file path that contains the debug data referenced by ETDump for intermediate and program outputs.
967968
delegate_metadata_parser: Optional function to parse delegate metadata from an Profiling Event. Expected signature of the function is:
968969
(delegate_metadata_list: List[bytes]) -> Union[List[str], Dict[str, Any]]
970+
delegate_time_scale_converter: The function to convert the time scale of delegate profiling data. Default to dividing by 10^6.
971+
enable_module_hierarchy: Enable submodules in the operator graph. Defaults to False.
969972
970973
Returns:
971974
None

devtools/inspector/_inspector_utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,17 @@ def compare_results(
429429
print("\n")
430430

431431
return results
432+
433+
434+
def default_delegate_time_scale_converter(
435+
event_name: Union[str, int], input_time: Union[int, float]
436+
) -> Union[int, float]:
437+
"""
438+
Default time scale converter for delegate events. This function divides the input time by 10^6.
439+
Args:
440+
event_name (Union[str, int]): The name of the event. Notice that this is intentionally ignored in this function.
441+
input_time (Union[int, float]): The raw input time.
442+
Returns:
443+
Union[int, float]: The converted time.
444+
"""
445+
return input_time / (1000 * 1000)

devtools/inspector/tests/inspector_utils_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from executorch.devtools.etrecord.tests.etrecord_test import TestETRecord
2525
from executorch.devtools.inspector._inspector_utils import (
2626
create_debug_handle_to_op_node_mapping,
27+
default_delegate_time_scale_converter,
2728
EDGE_DIALECT_GRAPH_KEY,
2829
find_populated_event,
2930
gen_graphs_from_etrecord,
@@ -170,6 +171,9 @@ def test_is_inference_output_equal_returns_true_for_same_strs(self):
170171
)
171172
)
172173

174+
def test_default_delegate_time_scale_converter(self):
175+
self.assertEqual(default_delegate_time_scale_converter("op_name", 10000000), 10)
176+
173177

174178
def gen_mock_operator_graph_with_expected_map() -> (
175179
Tuple[OperatorGraph, Dict[int, OperatorNode]]

0 commit comments

Comments
 (0)