Fix windows path escape characters (#162761)

Fixes #135954
Torch Inductor Windows Path Escape Characters

Pull Request resolved: https://github.com/pytorch/pytorch/pull/162761
Approved by: https://github.com/jansel, https://github.com/mlazos
This commit is contained in:
ghostspiders 2025-09-17 23:39:35 +00:00 committed by PyTorch MergeBot
parent 28c42cc280
commit 26eefd5ae2
2 changed files with 4 additions and 3 deletions

View File

@ -5421,7 +5421,7 @@ class CppScheduling(BaseScheduling):
_, _, arg_types = args.cpp_argdefs()
if not V.graph.cpp_wrapper:
compile_wrapper.writeline(
f"async_compile.cpp_pybinding({arg_types!r}, '''"
f"async_compile.cpp_pybinding({arg_types!r}, r'''"
)
compile_wrapper.splice(src_code, strip=True)
if not V.graph.cpp_wrapper:

View File

@ -6,6 +6,7 @@ import ctypes
import errno
import functools
import json
import locale
import logging
import os
import platform
@ -67,7 +68,7 @@ _IS_LINUX = sys.platform.startswith("linux")
_IS_MACOS = sys.platform.startswith("darwin")
_IS_WINDOWS = sys.platform == "win32"
SUBPROCESS_DECODE_ARGS = ("utf-8",) if _IS_WINDOWS else ()
SUBPROCESS_DECODE_ARGS = (locale.getpreferredencoding(),) if _IS_WINDOWS else ()
log = logging.getLogger(__name__)
@ -572,7 +573,7 @@ def _run_compile_cmd(cmd_line: str, cwd: str) -> None:
cmd, cwd=cwd, check=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
except subprocess.CalledProcessError as e:
output = e.stdout.decode("utf-8")
output = e.stdout.decode(*SUBPROCESS_DECODE_ARGS)
openmp_problem = "'omp.h' file not found" in output or "libomp" in output
if openmp_problem and sys.platform == "darwin":
instruction = (