Building PyTorch from source having problems

Dear All,

I have a old GPU which has cuda capability 3.0, and the latest pytorch binaries does not support my GPU. I decided to build PyTorch, and I was able to build it using following environment.

Windows 7,
MS Visual Studio 2017
CUDA 10.2
Python 3.8

However, I am getting following error when I try to import torch.

Traceback (most recent call last):
  File "D:/repos/pytorch/pytroch_test.py", line 4, in <module>
    import torch
  File "C:\anaconda3\envs\build_src\lib\site-packages\torch\__init__.py", line 82, in <module>
    ctypes.CDLL(dll)
  File "C:\anaconda3\envs\build_src\lib\ctypes\__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError -1073741795] Windows Error 0xc000001d

It looks like, this error is related to caffe2_detectron_ops_gpu.dll file loading, however, I was not able to figure out the exact cause.

Here is the little script that people suggested running and it results.

import psutil, os
p = psutil.Process( os.getpid() )
for dll in p.memory_maps():
  print(dll.path)

import torch

Here is the result

C:\anaconda3\envs\build_src\python.exe D:/repos/pytorch/pytorch_dll.py
C:\Windows\System32\locale.nls
C:\Windows\System32\en-US\KernelBase.dll.mui
C:\Windows\Globalization\Sorting\SortDefault.nls
C:\Windows\System32\en-US\kernel32.dll.mui
C:\Windows\System32\user32.dll
C:\Windows\System32\kernel32.dll
C:\Windows\System32\ntdll.dll
C:\Windows\System32\psapi.dll
C:\anaconda3\envs\pytorch\python.exe
C:\anaconda3\envs\pytorch\python38.dll
C:\anaconda3\envs\pytorch\DLLs\_lzma.pyd
C:\Windows\System32\pdh.dll
C:\anaconda3\pkgs\vs2015_runtime-14.16.27012-hf0eaf9b_1\ucrtbase.dll
C:\anaconda3\envs\build_src\Lib\site-packages\psutil\_psutil_windows.cp38-win_amd64.pyd
C:\anaconda3\envs\pytorch\DLLs\_bz2.pyd
C:\anaconda3\envs\pytorch\DLLs\_socket.pyd
C:\anaconda3\envs\pytorch\DLLs\select.pyd
C:\anaconda3\api-ms-win-crt-filesystem-l1-1-0.dll
C:\anaconda3\envs\pytorch\python3.dll
C:\anaconda3\api-ms-win-crt-process-l1-1-0.dll
C:\anaconda3\api-ms-win-crt-conio-l1-1-0.dll
C:\anaconda3\api-ms-win-crt-time-l1-1-0.dll
C:\anaconda3\api-ms-win-crt-environment-l1-1-0.dll
C:\anaconda3\api-ms-win-crt-math-l1-1-0.dll
C:\anaconda3\api-ms-win-crt-locale-l1-1-0.dll
C:\anaconda3\api-ms-win-crt-stdio-l1-1-0.dll
C:\anaconda3\api-ms-win-crt-convert-l1-1-0.dll
C:\anaconda3\api-ms-win-crt-string-l1-1-0.dll
C:\anaconda3\api-ms-win-crt-heap-l1-1-0.dll
C:\anaconda3\api-ms-win-core-synch-l1-2-0.dll
C:\anaconda3\api-ms-win-core-file-l2-1-0.dll
C:\anaconda3\api-ms-win-core-timezone-l1-1-0.dll
C:\anaconda3\api-ms-win-core-processthreads-l1-1-1.dll
C:\anaconda3\api-ms-win-core-file-l1-2-0.dll
C:\anaconda3\api-ms-win-crt-runtime-l1-1-0.dll
C:\anaconda3\api-ms-win-core-localization-l1-2-0.dll
C:\anaconda3\pkgs\vs2015_runtime-14.16.27012-hf0eaf9b_1\vcruntime140.dll
C:\Windows\System32\winnsi.dll
C:\Windows\System32\IPHLPAPI.DLL
C:\Windows\System32\powrprof.dll
C:\Windows\System32\wtsapi32.dll
C:\Windows\System32\version.dll
C:\Windows\System32\rsaenh.dll
C:\Windows\System32\cryptsp.dll
C:\Windows\System32\cryptbase.dll
C:\Windows\System32\winsta.dll
C:\Windows\System32\cfgmgr32.dll
C:\Windows\System32\devobj.dll
C:\Windows\System32\KernelBase.dll
C:\Windows\System32\lpk.dll
C:\Windows\System32\nsi.dll
C:\Windows\System32\setupapi.dll
C:\Windows\System32\shell32.dll
C:\Windows\System32\oleaut32.dll
C:\Windows\System32\msctf.dll
C:\Windows\System32\advapi32.dll
C:\Windows\System32\usp10.dll
C:\Windows\System32\ole32.dll
C:\Windows\System32\rpcrt4.dll
C:\Windows\System32\imm32.dll
C:\Windows\System32\sechost.dll
C:\Windows\System32\gdi32.dll
C:\Windows\System32\msvcrt.dll
C:\Windows\System32\ws2_32.dll
C:\Windows\System32\shlwapi.dll
C:\Windows\System32\apisetschema.dll
Traceback (most recent call last):
  File "D:/repos/pytorch/pytorch_dll.py", line 6, in <module>
    import torch
  File "C:\anaconda3\envs\build_src\lib\site-packages\torch\__init__.py", line 82, in <module>
    ctypes.CDLL(dll)
  File "C:\anaconda3\envs\build_src\lib\ctypes\__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError -1073741795] Windows Error 0xc000001d

Process finished with exit code 1

It may be that your CPU is without AVX or AVX2 support.

1 Like

You can compile the example code in https://docs.microsoft.com/en-us/cpp/intrinsics/cpuid-cpuidex?view=vs-2019#example to get all the supported instruction sets on your PC.

1 Like

@peterjc123 - - Thank you very mcuh. it supports it.
I used the scripts provided here: https://github.com/peterjc123/pytorch-scripts

I recompiled my pytorch, now I am getting different error as follows:

C:\anaconda3\envs\build_src\python.exe D:/repos/pytorch/pytroch_test.py
Traceback (most recent call last):
  File "D:/repos/pytorch/pytroch_test.py", line 4, in <module>
    import torch
  File "C:\anaconda3\envs\build_src\lib\site-packages\torch\__init__.py", line 82, in <module>
    ctypes.CDLL(dll)
  File "C:\anaconda3\envs\build_src\lib\ctypes\__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\anaconda3\envs\build_src\lib\site-packages\torch\lib\caffe2_detectron_ops_gpu.dll' (or one of its dependencies). Try using the full path with constructor syntax.

Process finished with exit code 1

Here is my cuda102.bat

@echo off

IF /I "%~1" == "/y" (
    set NO_PROMPT=1
)

IF NOT EXIST "setup.py" IF NOT EXIST "pytorch" (
    call internal\clone.bat
    cd ..
    IF ERRORLEVEL 1 goto eof
)

call internal\check_deps.bat
IF ERRORLEVEL 1 goto eof

REM Check for optional components

set NO_CUDA=
set CMAKE_GENERATOR=Visual Studio 15 2017
#set CMAKE_GENERATOR=Visual Studio 15 2017 Win64


IF "%NVTOOLSEXT_PATH%"=="" (
    echo NVTX ^(Visual Studio Extension ^for CUDA^) ^not installed, disabling CUDA
    set NO_CUDA=1
    goto optcheck
)

IF "%CUDA_PATH_V10_2%"=="" (
    echo CUDA 10.2 not found, disabling it
    set NO_CUDA=1
) ELSE (
    set "CUDA_PATH=%CUDA_PATH_V10_2%"
    set "PATH=%CUDA_PATH_V10_2%\bin;%PATH%"
	echo "CUDA PATH FOUND, %PATH%"
	SLEEP 10
	
)

:optcheck

call internal\check_opts.bat
IF ERRORLEVEL 1 goto eof

call internal\setup.bat
IF ERRORLEVEL 1 goto eof

:eof

Could you please try out pip install intel-openmp?

@peterjc123 - thank you again for the prompt response.

Truly, appreciate it. I already installed it (I read it somewhere that someone recommended it), but I am still having the same problem.

(build_src) C:\Users\johnmcgray>pip install intel-openmp
Requirement already satisfied: intel-openmp in c:\anaconda3\envs\build_src\lib\s
ite-packages (2019.0)

(build_src) C:\Users\johnmcgray>

If you are building against v1.5.0, then you can try to replace __init__.py with https://gist.github.com/peterjc123/bcbf4418ff63d88e11313d308cf1b427.

Thank you again @peterjc123

If I replace my init file, then I get similar error in different place.

This is what I get now. Any suggestions or any help will be highly appreciated. Thank you so much for the support .

C:\anaconda3\envs\build_src\python.exe D:/repos/pytorch/pytroch_test.py
Traceback (most recent call last):
  File "D:/repos/pytorch/pytroch_test.py", line 4, in <module>
    import torch
  File "C:\anaconda3\envs\build_src\lib\site-packages\torch\__init__.py", line 102, in <module>
    raise err
OSError: [WinError -1073741795] <no description> Error loading "C:\anaconda3\envs\build_src\lib\site-packages\torch\lib\caffe2_detectron_ops_gpu.dll" or one of its dependencies.

Process finished with exit code 1

That’s interesting. It claims that a DLL is missing when using safe DLL search but it will load a conflicting DLL when using the legacy way. Could you please post a detailed log according to the steps here?

Thank you @peterjc123 again.

I think I might know the problem. But, as you see here, I have selected Windows 10 SDK (s) when installing VS 2017. I do have Windows 7 machine.

That is sure a problem. However, I am not sure what SDK should I choose for Windows 7? Since I do not see any Windows 7 related SDK in the list.

No, it is not a problem. Windows 10 SDK can be used to compile binaries that is used on Windows 7.