[Bugfix] Fix mock.patch resolution failure for standalone_compile.FakeTensorMode on Python <= 3.10 (#37158)
Signed-off-by: Dimitrios Bariamis <12195802+dbari@users.noreply.github.com>
Co-authored-by: Dimitrios Bariamis <12195802+dbari@users.noreply.github.com>
(cherry picked from commit 1204cf0a9d)
This commit is contained in:
committed by
khluu
parent
bcf2be9612
commit
ccbc5ac449
@@ -373,8 +373,15 @@ class InductorStandaloneAdaptor(CompilerInterface):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if input_fake_mode is not None:
|
if input_fake_mode is not None:
|
||||||
fake_mode_ctx: Any = patch(
|
# Use patch.object on the actual module from sys.modules
|
||||||
"torch._inductor.standalone_compile.FakeTensorMode",
|
# because in Python <=3.10 the string-based patch() resolves
|
||||||
|
# torch._inductor.standalone_compile to the wrapper function
|
||||||
|
# (defined in __init__.py) instead of the module.
|
||||||
|
import sys
|
||||||
|
|
||||||
|
fake_mode_ctx: Any = patch.object(
|
||||||
|
sys.modules["torch._inductor.standalone_compile"],
|
||||||
|
"FakeTensorMode",
|
||||||
lambda *a, **kw: input_fake_mode,
|
lambda *a, **kw: input_fake_mode,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user