Building PyTorch from source having problems

username: davidzhoud
cooked: <p>Dear All,</p>
<p>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.</p>
<p>Windows 7,<br>
MS Visual Studio 2017<br>
CUDA 10.2<br>
Python 3.8</p>
<p>However, I am getting following error when I try to import torch.</p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "D:/repos/pytorch/pytroch_test.py", line 4, in &lt;module&gt;
    import torch
  File "C:\anaconda3\envs\build_src\lib\site-packages\torch\__init__.py", line 82, in &lt;module&gt;
    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
</code></pre>
<p>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.</p>
<p>Here is the little script that people suggested running and it results.</p>
<pre><code class="lang-auto">import psutil, os
p = psutil.Process( os.getpid() )
for dll in p.memory_maps():
  print(dll.path)

import torch
</code></pre>
<p>Here is the result</p>
<pre><code class="lang-auto">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 &lt;module&gt;
    import torch
  File "C:\anaconda3\envs\build_src\lib\site-packages\torch\__init__.py", line 82, in &lt;module&gt;
    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

</code></pre>

username: peterjc123
cooked: <aside class="quote no-group" data-username="davidzhoud" data-post="1" data-topic="81935">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/d/57b2e6/48.png" class="avatar"> davidzhoud:</div>
<blockquote>
<p><code>Windows Error 0xc000001d</code></p>
</blockquote>
</aside>
<p>It may be that your CPU is without AVX or AVX2 support.</p>

username: peterjc123
cooked: <p>You can compile the example code in <a href="https://docs.microsoft.com/en-us/cpp/intrinsics/cpuid-cpuidex?view=vs-2019#example" rel="nofollow noopener">https://docs.microsoft.com/en-us/cpp/intrinsics/cpuid-cpuidex?view=vs-2019#example</a> to get all the supported instruction sets on your PC.</p>

username: davidzhoud
cooked: <p><a class="mention" href="/u/peterjc123">@peterjc123</a> - - Thank you very mcuh. it supports it.<br>
I used the scripts provided here: <a href="https://github.com/peterjc123/pytorch-scripts" class="inline-onebox" rel="noopener nofollow ugc">GitHub - peterjc123/pytorch-scripts: A few Windows specific scripts for PyTorch</a></p>
<p>I recompiled my pytorch, now I am getting different error as follows:</p>
<pre><code class="lang-auto">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 &lt;module&gt;
    import torch
  File "C:\anaconda3\envs\build_src\lib\site-packages\torch\__init__.py", line 82, in &lt;module&gt;
    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

</code></pre>
<p>Here is my cuda102.bat</p>
<pre><code class="lang-auto">@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

</code></pre>
<aside class="quote no-group" data-username="peterjc123" data-post="3" data-topic="81935">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/peterjc123/48/2790_2.png" class="avatar"> peterjc123:</div>
<blockquote>
<p>It may be that your CPU is without AVX or AVX2 support.</p>
</blockquote>
</aside>

username: peterjc123
cooked: <p>Could you please try out <code>pip install intel-openmp</code>?</p>

username: davidzhoud
cooked: <p><a class="mention" href="/u/peterjc123">@peterjc123</a>  - thank you again for the prompt response.</p>
<p>Truly, appreciate it.   I already installed it (I read it somewhere that someone recommended it), but I am still having the same problem.</p>
<p>(build_src) C:\Users\johnmcgray&gt;pip install intel-openmp<br>
Requirement already satisfied: intel-openmp in c:\anaconda3\envs\build_src\lib\s<br>
ite-packages (2019.0)</p>
<p>(build_src) C:\Users\johnmcgray&gt;</p>

username: peterjc123
cooked: <p>If you are  building against v1.5.0, then you can try to replace <code>__init__.py</code> with <a href="https://gist.github.com/peterjc123/bcbf4418ff63d88e11313d308cf1b427" rel="nofollow noopener">https://gist.github.com/peterjc123/bcbf4418ff63d88e11313d308cf1b427</a>.</p>

username: davidzhoud
cooked: <p>Thank you again <a class="mention" href="/u/peterjc123">@peterjc123</a></p>
<p>If I replace my init file, then I get similar error in different place.</p>
<p>This is what I get now. Any suggestions or any help will be highly appreciated. Thank you so much for the support .</p>
<pre><code class="lang-auto">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 &lt;module&gt;
    import torch
  File "C:\anaconda3\envs\build_src\lib\site-packages\torch\__init__.py", line 102, in &lt;module&gt;
    raise err
OSError: [WinError -1073741795] &lt;no description&gt; 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
</code></pre>

username: peterjc123
cooked: <p>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 <a href="https://github.com/peterjc123/pytorch_dll_load_smoketests#how-to-contribute-or-report-issues" rel="nofollow noopener">here</a>?</p>

username: davidzhoud
cooked: <p>Thank you <a class="mention" href="/u/peterjc123">@peterjc123</a> again.</p>
<p>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.  <div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/a/3a5ece2f2b9ddf1a0d7091efbefa74bf1ee45db5.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/3a5ece2f2b9ddf1a0d7091efbefa74bf1ee45db5" title="windows_sdk"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/3/a/3a5ece2f2b9ddf1a0d7091efbefa74bf1ee45db5_2_659x500.jpeg" alt="windows_sdk" data-base62-sha1="8kmOoV0M5rMDVEsOYAJ8ZMFsc6x" width="659" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/3/a/3a5ece2f2b9ddf1a0d7091efbefa74bf1ee45db5_2_659x500.jpeg, https://discuss.pytorch.org/uploads/default/original/3X/3/a/3a5ece2f2b9ddf1a0d7091efbefa74bf1ee45db5.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/3/a/3a5ece2f2b9ddf1a0d7091efbefa74bf1ee45db5.jpeg 2x" data-dominant-color="EEEEEF"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">windows_sdk</span><span class="informations">906×687 75.7 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>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.</p>
<aside class="quote no-group" data-username="peterjc123" data-post="10" data-topic="81935" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/peterjc123/48/2790_2.png" class="avatar"> peterjc123:</div>
<blockquote>
<p>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 <a href="https://github.com/peterjc123/pytorch_dll_load_smoketests#how-to-contribute-or-report-issues" rel="noopener nofollow ugc">here</a>?</p>
</blockquote>
</aside>

username: peterjc123
cooked: <p>No, it is not a problem. Windows 10 SDK can be used to compile binaries that is used on Windows 7.</p>