I cannot use the pytorch that was built successfully from source: (DLL) initialization routine failed. Error loading caffe2_detectron_ops_gpu.dll

After so many tries, the following has worked for me.

I had to set ninja off. Ninja is in order to speed up the process, too bad that I cannot use it. Without ninja, it ran through the whole night for about 9.5 hours. I also needed to download the source code of MKL, and then, together with the mkl installation and other tricks (which are all documented above), it works:

(myenv) C:\WINDOWS\system32>cd C:\Users\Admin\Downloads\Pytorch\pytorch

(myenv) C:\Users\Admin\Downloads\Pytorch\pytorch>set “CMAKE_INCLUDE_PATH=C:\Users\Admin\Downloads\Pytorch\mkl\include”

(myenv) C:\Users\Admin\Downloads\Pytorch\pytorch>set “LIB=C:\Users\Admin\Downloads\Pytorch\mkl\lib;%LIB%”

(myenv) C:\Users\Admin\Downloads\Pytorch\pytorch>set USE_NINJA=OFF

(myenv) C:\Users\Admin\Downloads\Pytorch\pytorch>set CMAKE_GENERATOR=Visual Studio 16 2019

(myenv) C:\Users\Admin\Downloads\Pytorch\pytorch>set USE_MKLDNN=ON

(myenv) C:\Users\Admin\Downloads\Pytorch\pytorch>set “CUDAHOSTCXX=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\Hostx64\x64\cl.exe”

(myenv) C:\Users\Admin\Downloads\Pytorch\pytorch>python setup.py install --cmake

This has run through, yet the spyder was corrupted by the cuda install:

(myenv) C:\WINDOWS\system32>spyder
_cffi_ext.c
C:\Users\Admin\anaconda3\lib\site-packages\zmq\backend\cffi\__pycache__\_cffi_ext.c(268): fatal error C1083: Datei (Include) kann nicht geöffnet werden: "zmq.h": No such file or directory
Traceback (most recent call last):
  File "C:\Users\Admin\anaconda3\Scripts\spyder-script.py", line 6, in <module>
    from spyder.app.start import main
  File "C:\Users\Admin\anaconda3\lib\site-packages\spyder\app\start.py", line 22, in <module>
    import zmq
  File "C:\Users\Admin\anaconda3\lib\site-packages\zmq\__init__.py", line 50, in <module>
    from zmq import backend
  File "C:\Users\Admin\anaconda3\lib\site-packages\zmq\backend\__init__.py", line 40, in <module>
    reraise(*exc_info)
  File "C:\Users\Admin\anaconda3\lib\site-packages\zmq\utils\sixcerpt.py", line 34, in reraise
    raise value
  File "C:\Users\Admin\anaconda3\lib\site-packages\zmq\backend\__init__.py", line 27, in <module>
    _ns = select_backend(first)
  File "C:\Users\Admin\anaconda3\lib\site-packages\zmq\backend\select.py", line 28, in select_backend
    mod = __import__(name, fromlist=public_api)
  File "C:\Users\Admin\anaconda3\lib\site-packages\zmq\backend\cython\__init__.py", line 6, in <module>
    from . import (constants, error, message, context,
ImportError: DLL load failed while importing error: Das angegebene Modul wurde nicht gefunden.

Installing it over the existing installation again:

(myenv) C:\WINDOWS\system32>conda install spyder

Opening spyder:

(myenv) C:\WINDOWS\system32>spyder

Test according to this:

import torch

torch.__version__
Out[3]: '1.8.0a0+2ab74a4'

torch.cuda.current_device()
Out[4]: 0

torch.cuda.device(0)
Out[5]: <torch.cuda.device at 0x24e6b98a400>

torch.cuda.device_count()
Out[6]: 1

torch.cuda.get_device_name(0)
Out[7]: 'GeForce GT 710'

torch.cuda.is_available()
Out[8]: True

Finally :slight_smile:

++ A compressed summary of all steps can be found on Stack Exchange at python - How to install pytorch FROM SOURCE (with cuda enabled for a deprecated CUDA cc 3.5 of an old gpu) using anaconda prompt on Windows 10? - Super User ++