Skip to content

Commit df6622b

Browse files
jamesjwufacebook-github-bot
authored andcommitted
Make CompileEventLogger more defensive w.r.t to AOTAutogradCache and FXGraphCache (#150423)
Summary: This PR makes it so that we don't crash due to logging if we invoke AOTAutogradCache/FXGraphCache without using dynamo. This is preparation for supporting certain VLLM use cases where they store graph modules and have special handling in conjunection with the caches. X-link: pytorch/pytorch#150423 Approved by: https://github.com/oulgen Reviewed By: atalman Differential Revision: D72453905 fbshipit-source-id: 77da32a50b8020e03e97d3098b9c6b7d2546f13f
1 parent 942979e commit df6622b

File tree

1 file changed

+16
-1
lines changed
  • userbenchmark/dynamo/dynamobench/_dynamo

1 file changed

+16
-1
lines changed

userbenchmark/dynamo/dynamobench/_dynamo/utils.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,12 +579,27 @@ def instant(
579579
@staticmethod
580580
def try_add_pt2_compile(event_name: str, **metadata: object):
581581
"""
582-
Adds to an existing pt2_compile event, but silently returns if the event doesn't exist.
582+
Adds to an existing pt2_compile event, but silently returns if the event doesn't exist
583+
or ChromiumEventLogger is not initialized.
583584
This function is syntactic sugar for chromium_event_logger().try_add_event_data.
584585
"""
586+
if CHROMIUM_EVENT_LOG is None:
587+
return
585588
chromium_log = get_chromium_event_logger()
586589
chromium_log.try_add_event_data(event_name, **metadata)
587590

591+
@staticmethod
592+
def try_(method_fn, *args, **kwargs):
593+
"""
594+
Special function that quietly runs a given method, returning if CHROMIUM_EVENT_LOG is None or metrics context is not set
595+
"""
596+
if CHROMIUM_EVENT_LOG is None:
597+
return
598+
metrics_context = get_metrics_context()
599+
if not metrics_context.in_progress():
600+
return
601+
method_fn(*args, **kwargs)
602+
588603

589604
@contextmanager
590605
def dynamo_timed(

0 commit comments

Comments
 (0)