Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyTorch Error checking compiler version for cl (cpp_extension.py)

I'm using Anaconda and I have installed PyTorch using the following command: pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116

Now I'm getting the following error in torch/utils/cpp_extension.py:

UserWarning: Error checking compiler version for cl: [WinError 2] The system cannot find the file specified

I'm using Windows 10 and I have installed Visual Studio Community 2022 and Visual Studio Build Tools 2022, please see screenshots below.

Does somebody what is wrong or missing?

enter image description here

enter image description here

Edit: I'm using Cuda 11.6. I have now also installed Visual Studio 2019 including the build tools. Now the above error is gone but I have a new error:

Traceback (most recent call last):
  File "C:\Users\myUser\Anaconda3\envs\parlai\lib\site-packages\torch\utils\cpp_extension.py", line 1808, in _run_ninja_build
    subprocess.run(
  File "C:\Users\myUser\Anaconda3\envs\parlai\lib\subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\myUser\ParlAI\server\server.py", line 3, in <module>
    from parlai.utils.safety import OffensiveStringMatcher, OffensiveLanguageClassifier
  File "c:\users\myUser\parlai\parlai\utils\safety.py", line 10, in <module>
    from parlai.agents.transformer.transformer import TransformerClassifierAgent
  File "c:\users\myUser\parlai\parlai\agents\transformer\transformer.py", line 15, in <module>
    from parlai.core.torch_generator_agent import TorchGeneratorAgent
  File "c:\users\myUser\parlai\parlai\core\torch_generator_agent.py", line 48, in <module>
    from parlai.ops.ngram_repeat_block import NGramRepeatBlock
  File "c:\users\myUser\parlai\parlai\ops\ngram_repeat_block.py", line 23, in <module>
    ngram_repeat_block_cuda = load(
  File "C:\Users\myUser\Anaconda3\envs\parlai\lib\site-packages\torch\utils\cpp_extension.py", line 1202, in load
    return _jit_compile(
  File "C:\Users\myUser\Anaconda3\envs\parlai\lib\site-packages\torch\utils\cpp_extension.py", line 1425, in _jit_compile
    _write_ninja_file_and_build_library(
  File "C:\Users\myUser\Anaconda3\envs\parlai\lib\site-packages\torch\utils\cpp_extension.py", line 1537, in _write_ninja_file_and_build_library
    _run_ninja_build(
  File "C:\Users\myUser\Anaconda3\envs\parlai\lib\site-packages\torch\utils\cpp_extension.py", line 1824, in _run_ninja_build
    raise RuntimeError(message) from e
RuntimeError: Error building extension 'ngram_repeat_block_cuda': [1/2] C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin\nvcc --generate-dependencies-with-compile --dependency-output ngram_repeat_block_cuda_kernel.cuda.o.d -Xcudafe --diag_suppress=dll_interface_conflict_dllexport_assumed -Xcudafe --diag_suppress=dll_interface_conflict_none_assumed -Xcudafe --diag_suppress=field_without_dll_interface -Xcudafe --diag_suppress=base_class_has_different_dll_interface -Xcompiler /EHsc -Xcompiler /wd4190 -Xcompiler /wd4018 -Xcompiler /wd4275 -Xcompiler /wd4267 -Xcompiler /wd4244 -Xcompiler /wd4251 -Xcompiler /wd4819 -Xcompiler /MD -DTORCH_EXTENSION_NAME=ngram_repeat_block_cuda -DTORCH_API_INCLUDE_EXTENSION_H -IC:\Users\myUser\Anaconda3\envs\parlai\lib\site-packages\torch\include -IC:\Users\myUser\Anaconda3\envs\parlai\lib\site-packages\torch\include\torch\csrc\api\include -IC:\Users\myUser\Anaconda3\envs\parlai\lib\site-packages\torch\include\TH -IC:\Users\myUser\Anaconda3\envs\parlai\lib\site-packages\torch\include\THC "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\include" -IC:\Users\myUser\Anaconda3\envs\parlai\Include -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_86,code=compute_86 -gencode=arch=compute_86,code=sm_86 -c c:\users\myUser\parlai\parlai\clib\cuda\ngram_repeat_block_cuda_kernel.cu -o ngram_repeat_block_cuda_kernel.cuda.o
FAILED: ngram_repeat_block_cuda_kernel.cuda.o
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin\nvcc --generate-dependencies-with-compile --dependency-output ngram_repeat_block_cuda_kernel.cuda.o.d -Xcudafe --diag_suppress=dll_interface_conflict_dllexport_assumed -Xcudafe --diag_suppress=dll_interface_conflict_none_assumed -Xcudafe --diag_suppress=field_without_dll_interface -Xcudafe --diag_suppress=base_class_has_different_dll_interface -Xcompiler /EHsc -Xcompiler /wd4190 -Xcompiler /wd4018 -Xcompiler /wd4275 -Xcompiler /wd4267 -Xcompiler /wd4244 -Xcompiler /wd4251 -Xcompiler /wd4819 -Xcompiler /MD -DTORCH_EXTENSION_NAME=ngram_repeat_block_cuda -DTORCH_API_INCLUDE_EXTENSION_H -IC:\Users\myUser\Anaconda3\envs\parlai\lib\site-packages\torch\include -IC:\Users\myUser\Anaconda3\envs\parlai\lib\site-packages\torch\include\torch\csrc\api\include -IC:\Users\myUser\Anaconda3\envs\parlai\lib\site-packages\torch\include\TH -IC:\Users\myUser\Anaconda3\envs\parlai\lib\site-packages\torch\include\THC "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\include" -IC:\Users\myUser\Anaconda3\envs\parlai\Include -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_86,code=compute_86 -gencode=arch=compute_86,code=sm_86 -c c:\users\myUser\parlai\parlai\clib\cuda\ngram_repeat_block_cuda_kernel.cu -o ngram_repeat_block_cuda_kernel.cuda.o
C:/Users/myUser/Anaconda3/envs/parlai/lib/site-packages/torch/include\c10/macros/Macros.h(143): warning C4067: unexpected tokens following preprocessor directive - expected a newline
C:/Users/myUser/Anaconda3/envs/parlai/lib/site-packages/torch/include\c10/macros/Macros.h(143): warning C4067: unexpected tokens following preprocessor directive - expected a newline
C:/Users/myUser/Anaconda3/envs/parlai/lib/site-packages/torch/include\c10/core/SymInt.h(84): warning #68-D: integer conversion resulted in a change of sign

C:\Users\myUser\Anaconda3\envs\parlai\lib\site-packages\torch\include\pybind11\cast.h(1429): error: too few arguments for template template parameter "Tuple"
          detected during instantiation of class "pybind11::detail::tuple_caster<Tuple, Ts...> [with Tuple=std::pair, Ts=<T1, T2>]"
(1507): here

C:\Users\myUser\Anaconda3\envs\parlai\lib\site-packages\torch\include\pybind11\cast.h(1503): error: too few arguments for template template parameter "Tuple"
          detected during instantiation of class "pybind11::detail::tuple_caster<Tuple, Ts...> [with Tuple=std::pair, Ts=<T1, T2>]"
(1507): here

2 errors detected in the compilation of "c:/users/myUser/parlai/parlai/clib/cuda/ngram_repeat_block_cuda_kernel.cu".
ngram_repeat_block_cuda_kernel.cu
ninja: build stopped: subcommand failed.
like image 886
BlackHawk Avatar asked Jun 27 '26 09:06

BlackHawk


1 Answers

I had the same issue, but I could resolve by following instructions below. The idea is to find the compiler cl in your windows system and add the directory to the path

  1. Make sure you have installed Microsoft Visual Studio BuildTools.
  2. Press Windows Button and type x86, you will get something called - x86 Native tools command prompt for vs 2022. Select that option. It will open a command prompt
  3. Type cl in that command prompt. Make sure it is installed
  4. Now type where cl to get the path of the compiler
  5. Now go to Environment Variables PATH and add this directory to it.
  6. Restart VS code, it should work
like image 107
Karthik Sunil Avatar answered Jun 29 '26 23:06

Karthik Sunil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!