From ccbc5ac44963fc7a3711953d116e4cc4c8112ac0 Mon Sep 17 00:00:00 2001 From: Dimitrios Bariamis Date: Tue, 17 Mar 2026 21:13:06 +0100 Subject: [PATCH] [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 1204cf0a9d0d4079183c44568dd2d6f8b46a3666) --- vllm/compilation/compiler_interface.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/vllm/compilation/compiler_interface.py b/vllm/compilation/compiler_interface.py index 2242f0304..ac63143b0 100644 --- a/vllm/compilation/compiler_interface.py +++ b/vllm/compilation/compiler_interface.py @@ -373,8 +373,15 @@ class InductorStandaloneAdaptor(CompilerInterface): break if input_fake_mode is not None: - fake_mode_ctx: Any = patch( - "torch._inductor.standalone_compile.FakeTensorMode", + # Use patch.object on the actual module from sys.modules + # 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, ) else: