What requirements do I need to use Torch.compile?

Hi, everyone.

I’m using Python 3.13.9.
With PyTorch 2.9 and CUDA 13.0, my GPU is an RTX 380 12 GB.
from this link
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu130

But I can’t use it; I’m always getting an error.

Exception has occurred: InductorError

CppCompileError: C++ compile error Command: cl /I c:/Users/Emad Younan/AppData/Local/Programs/Python/Python313/Include /I c:/Users/Emad Younan/AppData/Local/Programs/Python/Python313/Lib/site-packages/torch/include /I c:/Users/Emad Younan/AppData/Local/Programs/Python/Python313/Lib/site-packages/torch/include/torch/csrc/api/include /D NOMINMAX /D TORCH_INDUCTOR_CPP_WRAPPER /D STANDALONE_TORCH_HEADER /D C10_USING_CUSTOM_GENERATED_MACROS /O2 /DLL /MD /std:c++20 /wd4819 /wd4251 /wd4244 /wd4267 /wd4275 /wd4018 /wd4190 /wd4624 /wd4067 /wd4068 /EHsc /Zc:__cplusplus /permissive- /openmp /openmp:experimental C:/temp/torch_compile/bi/cbil2ud2wplsgzj6esiu72j2t7zq6phvrdyun5pl56vn2g26y5qg.main.cpp /FeC:/temp/torch_compile/bi/cbil2ud2wplsgzj6esiu72j2t7zq6phvrdyun5pl56vn2g26y5qg.main.pyd /LD /link /LIBPATH:c:/Users/Emad Younan/AppData/Local/Programs/Python/Python313/libs /LIBPATH:c:/Users/Emad Younan/AppData/Local/Programs/Python/Python313/Lib/site-packages/torch/lib torch.lib torch_cpu.lib torch_python.lib sleef.lib c10.lib Output: Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35219 for x64 Copyright (C) Microsoft Corporation. All rights reserved. cl : Command line warning D9025 : overriding ‘/openmp’ with ‘/openmp:experimental’ cbil2ud2wplsgzj6esiu72j2t7zq6phvrdyun5pl56vn2g26y5qg.main.cpp c:/Users/Emad Younan/AppData/Local/Programs/Python/Python313/Lib/site-packages/torch/include\torch/csrc/inductor/cpp_prefix.h(3): fatal error C1083: Cannot open include file: ‘omp.h’: No such file or directory

  • I followed up on those instructions, but still getting the same error
  • MSVC v143 - VS 2022 C++ x64/x86 build tools
  • Windows 11 SDK
  • C++ CMake tools for Windows
  • C++ core features
That’s the script I used.

import os
import torch

# Create a temp directory without spaces

temp_dir = r"C:\temp\torch_compile"

os.makedirs(temp_dir, exist_ok=True)

# Set PyTorch to use this temp directory

os.environ['TORCHINDUCTOR_CACHE_DIR'] = temp_dir

os.environ['TORCH_COMPILE_DEBUG'] = '0'

# Add MSVC to PATH

msvc_path = r"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64"

os.environ["PATH"] = msvc_path + ";" + os.environ["PATH"]

def foo(x, y):

    a = torch.sin(x)

    b = torch.cos(y)

    return a + b

opt_foo = torch.compile(foo)

result = opt_foo(torch.randn(10, 10), torch.randn(10, 10))

print("Success! Result shape:", result.shape)