Skip to content

Commit 0a5ce34

Browse files
tarun292facebook-github-bot
authored andcommitted
Add scuba logging to edge API's
Differential Revision: D66385141
1 parent d679ad7 commit 0a5ce34

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

exir/program/TARGETS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@fbcode_macros//build_defs:python_library.bzl", "python_library")
2+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
23

34
oncall("executorch")
45

@@ -43,7 +44,7 @@ python_library(
4344
"//executorch/exir/passes:spec_prop_pass",
4445
"//executorch/exir/passes:weights_to_outputs_pass",
4546
"//executorch/exir/verification:verifier",
46-
],
47+
] + (["//executorch/exir/program/fb:logger"] if not runtime.is_oss else [])
4748
)
4849

4950
python_library(

exir/program/_program.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@
7777

7878
from torch.library import Library
7979

80+
from typing import Callable, Any
81+
try:
82+
from executorch.exir.program.fb.logger import et_logger
83+
except ImportError:
84+
# Define a stub decorator that does nothing
85+
def et_logger(api_name: str) -> Callable[[Any], Any]:
86+
def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
87+
def wrapper(self: Any, *args: Any, **kwargs: Any) -> Any:
88+
return func(self, *args, **kwargs)
89+
return wrapper
90+
return decorator
91+
8092
# This is the reserved namespace that is used to register ops to that will
8193
# be prevented from being decomposed during to_edge_transform_and_lower.
8294
edge_no_decomp_namespace = "EDGE_DO_NOT_DECOMP"
@@ -956,7 +968,7 @@ def _gen_edge_manager_for_partitioners(
956968
)
957969
return edge_manager
958970

959-
971+
@et_logger("to_edge_transform_and_lower")
960972
def to_edge_transform_and_lower(
961973
programs: Union[ExportedProgram, Dict[str, ExportedProgram]],
962974
transform_passes: Optional[
@@ -1109,7 +1121,7 @@ def to_edge_with_preserved_ops(
11091121
edge_programs, constant_methods, config, list(preserve_ops)
11101122
)
11111123

1112-
1124+
@et_logger("to_edge")
11131125
def to_edge(
11141126
programs: Union[ExportedProgram, Dict[str, ExportedProgram]],
11151127
constant_methods: Optional[Dict[str, Any]] = None,
@@ -1204,8 +1216,10 @@ def exported_program(self, method_name: str = "forward") -> ExportedProgram:
12041216
"""
12051217
Returns the ExportedProgram specified by 'method_name'.
12061218
"""
1219+
12071220
return self._edge_programs[method_name]
12081221

1222+
@et_logger("transform")
12091223
def transform(
12101224
self,
12111225
passes: Union[Sequence[PassType], Dict[str, Sequence[PassType]]],
@@ -1253,6 +1267,7 @@ def transform(
12531267
new_programs, copy.deepcopy(self._config_methods), compile_config
12541268
)
12551269

1270+
@et_logger("to_backend")
12561271
def to_backend(
12571272
self, partitioner: Union[Partitioner, Dict[str, Partitioner]]
12581273
) -> "EdgeProgramManager":
@@ -1296,6 +1311,7 @@ def to_backend(
12961311
new_edge_programs, copy.deepcopy(self._config_methods), config
12971312
)
12981313

1314+
@et_logger("to_executorch")
12991315
def to_executorch(
13001316
self,
13011317
config: Optional[ExecutorchBackendConfig] = None,

0 commit comments

Comments
 (0)