Skip to content

Commit be908b3

Browse files
anijain2305facebook-github-bot
authored andcommitted
Log guard latency (#145132)
Summary: X-link: pytorch/pytorch#145132 Approved by: https://github.com/ezyang ghstack dependencies: #145509 Reviewed By: ZainRizvi Differential Revision: D68685480 fbshipit-source-id: fe35b627407e32a580f78027562b092083043d99
1 parent 4b95e3a commit be908b3

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

userbenchmark/dynamo/dynamobench/_dynamo/testing.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -181,30 +181,32 @@ def insert_nops(instructions: list[Any], code_options: Any) -> None:
181181
instructions.insert(0, create_instruction("NOP"))
182182
instructions.insert(0, create_instruction("NOP"))
183183

184-
if is_generator(frame.f_code):
185-
return None
186-
187-
debug_checks(frame.f_code)
188-
code = transform_code_object(frame.f_code, insert_nops)
189-
graph = OutputGraph(
190-
code_options={},
191-
compiler_fn=None,
192-
root_tx=None,
193-
export=False,
194-
export_constraints=None,
195-
frame_state={"_id": 0},
196-
# TODO: shouldn't this be f_locals/f_globals from frame?
197-
local_scope=locals(),
198-
global_scope=globals(),
199-
f_code=frame.f_code,
200-
torch_function_mode_stack=[],
201-
)
184+
metrics_context = torch._dynamo.utils.get_metrics_context()
185+
with torch._dynamo.utils.dynamo_timed("debug_insert_nops"), metrics_context:
186+
if is_generator(frame.f_code):
187+
return None
188+
189+
debug_checks(frame.f_code)
190+
code = transform_code_object(frame.f_code, insert_nops)
191+
graph = OutputGraph(
192+
code_options={},
193+
compiler_fn=None,
194+
root_tx=None,
195+
export=False,
196+
export_constraints=None,
197+
frame_state={"_id": 0},
198+
# TODO: shouldn't this be f_locals/f_globals from frame?
199+
local_scope=locals(),
200+
global_scope=globals(),
201+
f_code=frame.f_code,
202+
torch_function_mode_stack=[],
203+
)
202204

203-
return GuardedCode(
204-
code,
205-
CheckFunctionManager(frame.f_code, graph).guard_manager, # type: ignore[arg-type]
206-
CompileId(frame_id=0, frame_compile_id=0),
207-
)
205+
return GuardedCode(
206+
code,
207+
CheckFunctionManager(frame.f_code, graph).guard_manager, # type: ignore[arg-type]
208+
CompileId(frame_id=0, frame_compile_id=0),
209+
)
208210

209211

210212
class CompileCounter:

userbenchmark/dynamo/dynamobench/_dynamo/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,7 @@ class CompilationMetrics:
11861186
tensorify_float_attempt: Optional[bool] = None
11871187
tensorify_float_success: Optional[bool] = None
11881188
tensorify_float_failure: Optional[set[str]] = None
1189+
guard_latency_us: Optional[float] = None
11891190

11901191
@classmethod
11911192
def create(cls, metrics: dict[str, Any]):

0 commit comments

Comments
 (0)