Fix _is_compiling dynamo tracing: import torch instead of sys.modules lookup (#36573)
This commit is contained in:
@@ -1265,9 +1265,12 @@ _RECORD_DUMP_REGISTERED = False
|
|||||||
def _is_compiling() -> bool:
|
def _is_compiling() -> bool:
|
||||||
# Recording has Python side effects (set mutation, file I/O, atexit) that
|
# Recording has Python side effects (set mutation, file I/O, atexit) that
|
||||||
# must never run under tracing; torch.compiler.is_compiling() is dynamo's
|
# must never run under tracing; torch.compiler.is_compiling() is dynamo's
|
||||||
# sanctioned probe. The lazy lookup keeps this module import-light.
|
# sanctioned probe. The function-level import keeps this module
|
||||||
torch = sys.modules.get("torch")
|
# import-light; a sys.modules lookup here breaks fullgraph tracing (dynamo
|
||||||
return torch is not None and torch.compiler.is_compiling()
|
# enumerates the dict, which other imports mutate mid-trace).
|
||||||
|
import torch
|
||||||
|
|
||||||
|
return torch.compiler.is_compiling()
|
||||||
|
|
||||||
|
|
||||||
def _ensure_record_dump_registered() -> None:
|
def _ensure_record_dump_registered() -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user