Repository: pytorch
Issue: torch.compile 路径处理错误导致 C++ 编译失败
Labels: module: windows,triaged,oncall: pt2

### 🐛 Describe the bug

torch.compile自己创建的临时文件自己找不到路径。windows10  自己生成一个\t....什么的路径，然后转义字符导致路径出问题，希望修复一下，然后自己生成了一个随机的2个字符的文件夹，gcc路径里又跟文件名连在一起，又不加斜杠分隔符。


import torch
import os
# os.environ['TORCH_LOGS'] = '+dynamo'
# os.environ['TORCHDYNAMO_VERBOSE'] = '1'

import tempfile
# tempfile.tempdir = r'C:\\temp\\lemontorchinductor_lemon\\'
def softtanh(x):
    return x / (1 + torch.abs(x))
xtmain = torch.tensor([[12,2],[3,4]], dtype = torch.float, requires_grad = True)
wi = torch.tensor([[12,2],[3,4]], dtype = torch.float, requires_grad = True)
wf = torch.tensor([[12,2],[3,4]], dtype = torch.float, requires_grad = True)
wc = torch.tensor([[12,2],[3,4]], dtype = torch.float, requires_grad = True)
wo = torch.tensor([[12,2],[3,4]], dtype = torch.float, requires_grad = True)
bi = torch.tensor([[12,2],[3,4]], dtype = torch.float, requires_grad = True)
bf = torch.tensor([[12,2],[3,4]], dtype = torch.float, requires_grad = True)
bc = torch.tensor([[12,2],[3,4]], dtype = torch.float, requires_grad = True)
bo = torch.tensor([[12,2],[3,4]], dtype = torch.float, requires_grad = True)
ct = torch.tensor([[12,2],[3,4]], dtype = torch.float, requires_grad = True)

def fun(xtmain, wi, wf, wc, wo, bi, bf, bc, bo, ct):
    xtmain = softtanh(xtmain)
    i = torch.sigmoid_(wi @ xtmain + bi)
    f = torch.sigmoid_(wf @ xtmain + bf)
    g = softtanh(wc @ xtmain + bc)
    o = torch.sigmoid_(wo @ xtmain + bo)
    x = f * ct
    x1 = i * g
    cell = x + x1
    s = softtanh(cell)
    ht = s * o

    return ht

fun_compile = torch.compile(fun)
print(fun_compile(xtmain, wi, wf, wc, wo, bi, bf, bc, bo, ct))


E:\pythonproject\s309\venv\Scripts\python.exe E:/pythonproject/s309/testarea/testtorchcompile.py
Traceback (most recent call last):
  File "E:/pythonproject/s309/testarea/testtorchcompile.py", line 37, in <module>
    print(fun_compile(xtmain, wi, wf, wc, wo, bi, bf, bc, bo, ct))
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\eval_frame.py", line 433, in _fn
    return fn(*args, **kwargs)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\convert_frame.py", line 1116, in __call__
    return self._torchdynamo_orig_callable(
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\convert_frame.py", line 948, in __call__
    result = self._inner_convert(
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\convert_frame.py", line 472, in __call__
    return _compile(
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_utils_internal.py", line 84, in wrapper_function
    return StrobelightCompileTimeProfiler.profile_compile_time(
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_strobelight\compile_time_profiler.py", line 129, in profile_compile_time
    return func(*args, **kwargs)
  File "C:\python38\lib\contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\convert_frame.py", line 817, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\utils.py", line 231, in time_wrapper
    r = func(*args, **kwargs)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\convert_frame.py", line 636, in compile_inner
    out_code = transform_code_object(code, transform)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\bytecode_transformation.py", line 1185, in transform_code_object
    transformations(instructions, code_options)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\convert_frame.py", line 178, in _fn
    return fn(*args, **kwargs)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\convert_frame.py", line 582, in transform
    tracer.run()
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\symbolic_convert.py", line 2451, in run
    super().run()
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\symbolic_convert.py", line 893, in run
    while self.step():
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\symbolic_convert.py", line 805, in step
    self.dispatch_table[inst.opcode](self, inst)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\symbolic_convert.py", line 2642, in RETURN_VALUE
    self._return(inst)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\symbolic_convert.py", line 2627, in _return
    self.output.compile_subgraph(
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\output_graph.py", line 1098, in compile_subgraph
    self.compile_and_call_fx_graph(tx, list(reversed(stack_values)), root)
  File "C:\python38\lib\contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\output_graph.py", line 1318, in compile_and_call_fx_graph
    compiled_fn = self.call_user_compiler(gm)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\utils.py", line 231, in time_wrapper
    r = func(*args, **kwargs)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\output_graph.py", line 1409, in call_user_compiler
    raise BackendCompilerFailed(self.compiler_fn, e).with_traceback(
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\output_graph.py", line 1390, in call_user_compiler
    compiled_fn = compiler_fn(gm, self.example_inputs())
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\repro\after_dynamo.py", line 129, in __call__
    compiled_gm = compiler_fn(gm, example_inputs)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\__init__.py", line 1951, in __call__
    return compile_fx(model_, inputs_, config_patches=self.config)
  File "C:\python38\lib\contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_inductor\compile_fx.py", line 1505, in compile_fx
    return aot_autograd(
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\backends\common.py", line 69, in __call__
    cg = aot_module_simplified(gm, example_inputs, **self.kwargs)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_functorch\aot_autograd.py", line 954, in aot_module_simplified
    compiled_fn, _ = create_aot_dispatcher_function(
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\utils.py", line 231, in time_wrapper
    r = func(*args, **kwargs)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_functorch\aot_autograd.py", line 687, in create_aot_dispatcher_function
    compiled_fn, fw_metadata = compiler_fn(
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_functorch\_aot_autograd\jit_compile_runtime_wrappers.py", line 461, in aot_dispatch_autograd
    compiled_fw_func = aot_config.fw_compiler(fw_module, adjusted_flat_args)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\utils.py", line 231, in time_wrapper
    r = func(*args, **kwargs)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_inductor\compile_fx.py", line 1410, in fw_compiler_base
    return inner_compile(
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\repro\after_aot.py", line 84, in debug_wrapper
    inner_compiled_fn = compiler_fn(gm, example_inputs)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_inductor\debug.py", line 304, in inner
    return fn(*args, **kwargs)
  File "C:\python38\lib\contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "C:\python38\lib\contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\utils.py", line 231, in time_wrapper
    r = func(*args, **kwargs)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_inductor\compile_fx.py", line 527, in compile_fx_inner
    compiled_graph = fx_codegen_and_compile(
  File "C:\python38\lib\contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_inductor\compile_fx.py", line 831, in fx_codegen_and_compile
    compiled_fn = graph.compile_to_fn()
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_inductor\graph.py", line 1751, in compile_to_fn
    return self.compile_to_module().call
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_dynamo\utils.py", line 231, in time_wrapper
    r = func(*args, **kwargs)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_inductor\graph.py", line 1701, in compile_to_module
    mod = PyCodeCache.load_by_key_path(
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_inductor\codecache.py", line 3073, in load_by_key_path
    mod = _reload_python_module(key, path)
  File "E:\pythonproject\s309\venv\lib\site-packages\torch\_inductor\runtime\compile_tasks.py", line 39, in _reload_python_module
    raise RuntimeError(
torch._dynamo.exc.BackendCompilerFailed: backend='inductor' raised:
RuntimeError: Failed to import C:\Users\lemon\AppData\Local\Temp\torchinductor_lemon\a2\ca2xet7uhjitb3vnzqyh33fbdvhakqnkhrrsdeo3frxtmyxg5ei6.py
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 13-14: truncated \UXXXXXXXX escape (ca2xet7uhjitb3vnzqyh33fbdvhakqnkhrrsdeo3frxtmyxg5ei6.py, line 30)

Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information


You can suppress this exception and fall back to eager by setting:
    import torch._dynamo
    torch._dynamo.config.suppress_errors = True


cpp_fused_abs_add_div_0 = async_compile.cpp_pybinding(['const float*', 'float*'], '''
#include "C:\Users\lemon\AppData\Local\Temp\torchinductor_lemon\sk\cskh5dx62fglpphcrl6723dnmowdabouerrzy3dmqcngbxwfa7bv.h"

生成的临时文件里这个 \t是不是要出问题？

### Versions

window10                       minGW x86_64-8.1.0-release-win32-seh-rt_v6-rev0                 pycharm2020                  python3.8

cc @peterjc123 @mszhanyi @skyline75489 @nbcsm @iremyux @Blackhex @chauhang @penguinwu