Skip to content

Commit 4617d91

Browse files
jamesjwufacebook-github-bot
authored andcommitted
Fix CHROMIUM_EVENT_LOG being none
Summary: X-link: pytorch/pytorch#154258 It turns out if you import something that's None at import time in python, and later update the value, the one you imported stays none: ``` import torch from torch._dynamo.utils import CHROMIUM_EVENT_LOG class Foo: pass torch._dynamo.utils.CHROMIUM_EVENT_LOG = Foo() print(CHROMIUM_EVENT_LOG) # None ``` This fixes teh bug so we get AOTAutogradCache instant events again ghstack-source-id: 285913063 exported-using-ghexport Reviewed By: Myrthan, oulgen Differential Revision: D75305770 fbshipit-source-id: b2e1692b80216ae59e7409472565a903ffbc64d2
1 parent 6693f58 commit 4617d91

File tree

1 file changed

+7
-2
lines changed
  • userbenchmark/dynamo/dynamobench/_dynamo

1 file changed

+7
-2
lines changed

userbenchmark/dynamo/dynamobench/_dynamo/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def try_add_pt2_compile(event_name: str, **metadata: object):
592592
or ChromiumEventLogger is not initialized.
593593
This function is syntactic sugar for chromium_event_logger().try_add_event_data.
594594
"""
595-
if CHROMIUM_EVENT_LOG is None:
595+
if not chromium_event_log_active():
596596
return
597597
chromium_log = get_chromium_event_logger()
598598
chromium_log.try_add_event_data(event_name, **metadata)
@@ -602,7 +602,7 @@ def try_(method_fn, *args, **kwargs):
602602
"""
603603
Special function that quietly runs a given method, returning if CHROMIUM_EVENT_LOG is None or metrics context is not set
604604
"""
605-
if CHROMIUM_EVENT_LOG is None:
605+
if not chromium_event_log_active():
606606
return
607607
metrics_context = get_metrics_context()
608608
if not metrics_context.in_progress():
@@ -1923,6 +1923,11 @@ def get_chromium_event_logger() -> ChromiumEventLogger:
19231923
return CHROMIUM_EVENT_LOG
19241924

19251925

1926+
def chromium_event_log_active() -> bool:
1927+
global CHROMIUM_EVENT_LOG
1928+
return CHROMIUM_EVENT_LOG is not None
1929+
1930+
19261931
@contextmanager
19271932
def chromium_event_timed(
19281933
event_name: str,

0 commit comments

Comments
 (0)