Skip to content

Commit

Permalink
cleanup chromium event log on dynamo exit rather than on entry (pytor…
Browse files Browse the repository at this point in the history
…ch#143175)

clearing at dynamo start is an issue because it throws away events from compiled autograd

Pull Request resolved: pytorch#143175
Approved by: https://github.com/Skylion007, https://github.com/jamesjwu
ghstack dependencies: pytorch#141907
  • Loading branch information
xmfan authored and pytorchmergebot committed Dec 21, 2024
1 parent 4ee166b commit d88ebbf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion torch/_dynamo/convert_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ def count_args(code: CodeType) -> int:
with _use_lazy_graph_module(config.use_lazy_graph_module), compile_context(
CompileContext(compile_id)
), chromium_event_timed(
"dynamo", reset_event_log=True, log_pt2_compile_event=True
"dynamo", reset_event_log_on_exit=True, log_pt2_compile_event=True
), metrics_context:
restart_reasons: set[str] = set()
# This is shared across restarts
Expand Down
8 changes: 4 additions & 4 deletions torch/_dynamo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ def log_event_start(
:param str event_name Name of event to appear in trace
:param time_ns Timestamp in nanoseconds
:param metadata: Any extra metadata associated with this event
:param log_pt_compile_event: If True, log to pt2_compile_events
:param log_pt2_compile_event: If True, log to pt2_compile_events
:param compile_id: Explicit compile_id (rather than using the current context)
"""
compile_id = compile_id or torch._guards.CompileContext.current_compile_id()
Expand Down Expand Up @@ -1440,7 +1440,7 @@ def get_chromium_event_logger() -> ChromiumEventLogger:
@contextmanager
def chromium_event_timed(
event_name: str,
reset_event_log: bool = False,
reset_event_log_on_exit: bool = False,
log_pt2_compile_event: bool = False,
) -> Generator[Any, None, None]:
"""
Expand All @@ -1449,8 +1449,6 @@ def chromium_event_timed(
instead. Use this context manager only if you want to avoid dynamo_timed.
"""
chromium_event_log = get_chromium_event_logger()
if reset_event_log:
chromium_event_log.reset()
chromium_start_time = time.time_ns()
chromium_event_log.log_event_start(
event_name,
Expand All @@ -1468,6 +1466,8 @@ def chromium_event_timed(
chromium_start_time,
log_pt2_compile_event,
)
if reset_event_log_on_exit:
chromium_event_log.reset()


@dataclasses.dataclass
Expand Down

0 comments on commit d88ebbf

Please sign in to comment.