Skip to content

Commit

Permalink
Log compile ids to pt2_remote_cache and pt2_compile_events
Browse files Browse the repository at this point in the history
Summary:
X-link: pytorch/pytorch#137431

Log the current compilation id for all relevant samples for these two tables, so we can have a 1:1 analog with dynamo_compile.
ghstack-source-id: 246618821
exported-using-ghexport

Reviewed By: oulgen

Differential Revision: D63900826

fbshipit-source-id: 3f2896287777c94344960e7cad131f71aaf0210f
  • Loading branch information
jamesjwu authored and facebook-github-bot committed Oct 8, 2024
1 parent 1ac701f commit 85c33e5
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions userbenchmark/dynamo/dynamobench/_dynamo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,13 +905,20 @@ def log_event_start(
:param time_ns Timestamp in nanoseconds
:param metadata: Any extra metadata associated with this event
"""

# Add compile id to metadata
if metadata is None:
metadata = {}
compile_id = str(torch._guards.CompileContext.current_compile_id())
metadata["compile_id"] = compile_id

event = self._log_timed_event(
event_name,
time_ns,
"B",
metadata,
)
log_chromium_event_internal(event, self.get_stack(), self.id_)
log_chromium_event_internal(event, self.get_stack(), compile_id, self.id_)
self.get_stack().append(event_name)

def reset(self) -> None:
Expand All @@ -935,6 +942,12 @@ def log_event_end(
:param time_ns: Timestamp in nanoseconds
:param metadata: Any extra metadata associated with this event
"""
# Add compile id to metadata
if metadata is None:
metadata = {}
compile_id = str(torch._guards.CompileContext.current_compile_id())
metadata["compile_id"] = compile_id

# These stack health checks currently never happen,
# but they're written this way to future proof any weird event
# overlaps in the future.
Expand All @@ -961,7 +974,7 @@ def log_event_end(
)
stack.pop()

log_chromium_event_internal(event, stack, self.id_, start_time_ns)
log_chromium_event_internal(event, stack, compile_id, self.id_, start_time_ns)
# Finally pop the actual event off the stack
stack.pop()

Expand Down Expand Up @@ -1006,6 +1019,10 @@ def log_instant_event(
:param Optional[Dict[str, Any]] metadata: Any extra metadata associated with this event
:param str cname optional color for the arrow in the trace
"""
if metadata is None:
metadata = {}
compile_id = str(torch._guards.CompileContext.current_compile_id())
metadata["compile_id"] = compile_id
event = {
"name": event_name,
"ts": time_ns / 1000,
Expand All @@ -1024,7 +1041,7 @@ def log_instant_event(
expect_trace_id=True,
)
# Log an instant event with the same start and end time
log_chromium_event_internal(event, self.get_stack(), self.id_)
log_chromium_event_internal(event, self.get_stack(), compile_id, self.id_)


CHROMIUM_EVENT_LOG: Optional[ChromiumEventLogger] = None
Expand Down

0 comments on commit 85c33e5

Please sign in to comment.