Skip to content

Commit 3c97772

Browse files
tarun292facebook-github-bot
authored andcommitted
Add scuba logging to edge API's (#7103)
Summary: Pull Request resolved: #7103 Differential Revision: D66385141
1 parent d136206 commit 3c97772

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,24 @@
7575

7676
Val = Any
7777

78+
from typing import Any, Callable
79+
7880
from torch.library import Library
7981

82+
try:
83+
from executorch.exir.program.fb.logger import et_logger
84+
except ImportError:
85+
# Define a stub decorator that does nothing
86+
def et_logger(api_name: str) -> Callable[[Any], Any]:
87+
def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
88+
def wrapper(self: Any, *args: Any, **kwargs: Any) -> Any:
89+
return func(self, *args, **kwargs)
90+
91+
return wrapper
92+
93+
return decorator
94+
95+
8096
# This is the reserved namespace that is used to register ops to that will
8197
# be prevented from being decomposed during to_edge_transform_and_lower.
8298
edge_no_decomp_namespace = "EDGE_DO_NOT_DECOMP"
@@ -957,6 +973,7 @@ def _gen_edge_manager_for_partitioners(
957973
return edge_manager
958974

959975

976+
@et_logger("to_edge_transform_and_lower")
960977
def to_edge_transform_and_lower(
961978
programs: Union[ExportedProgram, Dict[str, ExportedProgram]],
962979
transform_passes: Optional[
@@ -1110,6 +1127,7 @@ def to_edge_with_preserved_ops(
11101127
)
11111128

11121129

1130+
@et_logger("to_edge")
11131131
def to_edge(
11141132
programs: Union[ExportedProgram, Dict[str, ExportedProgram]],
11151133
constant_methods: Optional[Dict[str, Any]] = None,
@@ -1204,8 +1222,10 @@ def exported_program(self, method_name: str = "forward") -> ExportedProgram:
12041222
"""
12051223
Returns the ExportedProgram specified by 'method_name'.
12061224
"""
1225+
12071226
return self._edge_programs[method_name]
12081227

1228+
@et_logger("transform")
12091229
def transform(
12101230
self,
12111231
passes: Union[Sequence[PassType], Dict[str, Sequence[PassType]]],
@@ -1253,6 +1273,7 @@ def transform(
12531273
new_programs, copy.deepcopy(self._config_methods), compile_config
12541274
)
12551275

1276+
@et_logger("to_backend")
12561277
def to_backend(
12571278
self, partitioner: Union[Partitioner, Dict[str, Partitioner]]
12581279
) -> "EdgeProgramManager":
@@ -1296,6 +1317,7 @@ def to_backend(
12961317
new_edge_programs, copy.deepcopy(self._config_methods), config
12971318
)
12981319

1320+
@et_logger("to_executorch")
12991321
def to_executorch(
13001322
self,
13011323
config: Optional[ExecutorchBackendConfig] = None,

0 commit comments

Comments
 (0)