Now I get the error:

DistutilsPlatformError: Microsoft Visual C++ 14.0 is required. Get it with “Build Tools for Visual Studio”

Although “MSVC v142 – VS 2019 C+±x64/x86-Buildtools” is already installed:
image1270×682 68 KB
(dl) C:\Users\Admin\Downloads\Pytorch\pytorch>set "CMAKE_INCLUDE_PATH=C:\Users\Admin\Downloads\Pytorch\mkl\include"

(dl) C:\Users\Admin\Downloads\Pytorch\pytorch>set "LIB=C:\Users\Admin\Downloads\Pytorch\mkl\lib;%LIB%"

(dl) C:\Users\Admin\Downloads\Pytorch\pytorch>set CMAKE_GENERATOR=Ninja

(dl) C:\Users\Admin\Downloads\Pytorch\pytorch>python setup.py install --cmake
Building wheel torch-1.7.0a0+d4c5f56
-- Building version 1.7.0a0+d4c5f56
Traceback (most recent call last):
  File "C:\Users\Admin\anaconda3\envs\dl\lib\site-packages\setuptools\msvc.py", line 273, in _msvc14_get_vc_env
    out = subprocess.check_output(
  File "C:\Users\Admin\anaconda3\envs\dl\lib\subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Users\Admin\anaconda3\envs\dl\lib\subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'cmd /u /c "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64 && set' returned non-zero exit status 255.

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

Traceback (most recent call last):
  File "setup.py", line 737, in <module>
    build_deps()
  File "setup.py", line 316, in build_deps
    build_caffe2(version=version,
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\build_pytorch_libs.py", line 52, in build_caffe2
    my_env = _create_build_env()
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\build_pytorch_libs.py", line 45, in _create_build_env
    my_env = _overlay_windows_vcvars(my_env)
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\build_pytorch_libs.py", line 14, in _overlay_windows_vcvars
    vc_env = _get_vc_env(vc_arch)
  File "C:\Users\Admin\anaconda3\envs\dl\lib\site-packages\setuptools\msvc.py", line 314, in msvc14_get_vc_env
    return _msvc14_get_vc_env(plat_spec)
  File "C:\Users\Admin\anaconda3\envs\dl\lib\site-packages\setuptools\msvc.py", line 278, in _msvc14_get_vc_env
    raise distutils.errors.DistutilsPlatformError(
distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/

Now I am running it with settings:
set "CMAKE_INCLUDE_PATH=C:\Users\Admin\Downloads\Pytorch\mkl\include"
set "LIB=C:\Users\Admin\Downloads\Pytorch\mkl\lib;%LIB%"
set USE_NINJA=OFF
set CMAKE_GENERATOR=Visual Studio 16 2019

starting again with:
(myenv) C:\Users\Admin\Downloads\Pytorch\pytorch>python setup.py install --cmake
starts with:
(dl) C:\Users\Admin\Downloads\Pytorch\pytorch>python setup.py install --cmake
Building wheel torch-1.7.0a0+d4c5f56
-- Building version 1.7.0a0+d4c5f56
cmake -GVisual Studio 16 2019 -Ax64 -Thost=x64 -DBUILD_PYTHON=True -DBUILD_TEST=True -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR=Visual Studio 16 2019 -DCMAKE_INCLUDE_PATH=C:\Users\Admin\Downloads\Pytorch\mkl\include -DCMAKE_INSTALL_PREFIX=C:\Users\Admin\Downloads\Pytorch\pytorch\torch -DCMAKE_PREFIX_PATH=C:\Users\Admin\anaconda3\envs\dl\Lib\site-packages -DJAVA_HOME=C:\Users\Admin\AppData\Local\Programs\AdoptOpenJDK\ -DNUMPY_INCLUDE_DIR=C:\Users\Admin\anaconda3\envs\dl\lib\site-packages\numpy\core\include -DPYTHON_EXECUTABLE=C:\Users\Admin\anaconda3\envs\dl\python.exe -DPYTHON_INCLUDE_DIR=C:\Users\Admin\anaconda3\envs\dl\include -DPYTHON_LIBRARY=C:\Users\Admin\anaconda3\envs\dl/libs/python38.lib -DTORCH_BUILD_VERSION=1.7.0a0+d4c5f56 -DUSE_NINJA=OFF -DUSE_NUMPY=True C:\Users\Admin\Downloads\Pytorch\pytorch
-- The CXX compiler identification is MSVC 19.27.29111.0
-- The C compiler identification is MSVC 19.27.29111.0
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Not forcing any particular BLAS to be found
-- Performing Test COMPILER_WORKS
-- Performing Test COMPILER_WORKS - Success
-- Performing Test SUPPORT_GLIBCXX_USE_C99
-- Performing Test SUPPORT_GLIBCXX_USE_C99 - Success
-- Performing Test CAFFE2_EXCEPTION_PTR_SUPPORTED
-- Performing Test CAFFE2_EXCEPTION_PTR_SUPPORTED - Success
-- std::exception_ptr is supported.
-- Performing Test CAFFE2_NEED_TO_TURN_OFF_DEPRECATION_WARNING
-- Performing Test CAFFE2_NEED_TO_TURN_OFF_DEPRECATION_WARNING - Failed
-- Performing Test CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS
-- Performing Test CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS - Success
-- Current compiler supports avx2 extension. Will build perfkernels.
-- Performing Test CAFFE2_COMPILER_SUPPORTS_AVX512_EXTENSIONS
-- Performing Test CAFFE2_COMPILER_SUPPORTS_AVX512_EXTENSIONS - Success
-- Current compiler supports avx512f extension. Will build fbgemm.
-- Performing Test COMPILER_SUPPORTS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_SUPPORTS_HIDDEN_VISIBILITY - Failed
-- Performing Test COMPILER_SUPPORTS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_SUPPORTS_HIDDEN_INLINE_VISIBILITY - Failed
-- Performing Test COMPILER_SUPPORTS_RDYNAMIC
-- Performing Test COMPILER_SUPPORTS_RDYNAMIC - Failed
-- Building using own protobuf under third_party per request.
-- Use custom protobuf build.
--
-- 3.11.4.0
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Caffe2 protobuf include directory: $<BUILD_INTERFACE:C:/Users/Admin/Downloads/Pytorch/pytorch/third_party/protobuf/src>$<INSTALL_INTERFACE:include>
-- Trying to find preferred BLAS backend of choice: MKL
-- MKL_THREADING = OMP
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of void*
-- Check size of void* - done
-- Looking for cblas_sgemm
-- Looking for cblas_sgemm - found
-- MKL libraries: C:/Users/Admin/Downloads/Pytorch/mkl/lib/mkl_intel_lp64.lib;C:/Users/Admin/Downloads/Pytorch/mkl/lib/mkl_intel_thread.lib;C:/Users/Admin/Downloads/Pytorch/mkl/lib/mkl_core.lib;C:/Users/Admin/Downloads/Pytorch/mkl/lib/libiomp5md.lib
-- MKL include directory: C:/Users/Admin/Downloads/Pytorch/mkl/include
-- MKL OpenMP type: Intel
-- MKL OpenMP library: C:/Users/Admin/Downloads/Pytorch/mkl/lib/libiomp5md.lib
CMake Warning at cmake/Dependencies.cmake:226 (message):
  Target platform "Windows" is not supported in {Q/X}NNPACK.  Supported
  platforms are Android, iOS, Linux, and macOS.  Turn this warning off by
  USE_{Q/X}NNPACK=OFF.
Call Stack (most recent call first):
  CMakeLists.txt:472 (include)

Almost at the bottom of the previous output we see that MKL is used. That shows me that can compile with the compiler MSVC and use MKL it seems. I hope that this is the way you asked me to use MKL.
This run has now led to the same error as reported in an earlier post. It seems that I have to remove the pytorch/caffe2/CMakeLists.txt before start, here the error message:
  Generating quantization/server/sigmoid_dnnlowp_op_test.py
  Generating quantization/server/spatial_batch_norm_dnnlowp_op_test.py
  Generating quantization/server/tanh_dnnlowp_op_test.py
  Generating quantization/server/utils.py
  Building Custom Rule C:/Users/Admin/Downloads/Pytorch/pytorch/caffe2/CMakeLists.txt
Traceback (most recent call last):
  File "setup.py", line 737, in <module>
    build_deps()
  File "setup.py", line 316, in build_deps
    build_caffe2(version=version,
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\build_pytorch_libs.py", line 62, in build_caffe2
    cmake.build(my_env)
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\setup_helpers\cmake.py", line 345, in build
    self.run(build_args, my_env)
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\setup_helpers\cmake.py", line 141, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "C:\Users\Admin\anaconda3\envs\dl\lib\subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '/p:CL_MPCount=4']' returned non-zero exit status 1.

I let it run again after removing the pytorch/caffe2/CMakeLists.txt, which caused error:
-- Configuring incomplete, errors occurred!
See also "C:/Users/Admin/Downloads/Pytorch/pytorch/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Admin/Downloads/Pytorch/pytorch/build/CMakeFiles/CMakeError.log".
Traceback (most recent call last):
  File "setup.py", line 737, in <module>
    build_deps()
  File "setup.py", line 316, in build_deps
    build_caffe2(version=version,
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\build_pytorch_libs.py", line 54, in build_caffe2
    cmake.generate(version,
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\setup_helpers\cmake.py", line 329, in generate
    self.run(args, env=my_env)
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\setup_helpers\cmake.py", line 141, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "C:\Users\Admin\anaconda3\envs\dl\lib\subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '-GVisual Studio 16 2019', '-Ax64', '-Thost=x64', '-DBUILD_PYTHON=True', '-DBUILD_TEST=True', '-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_GENERATOR=Visual Studio 16 2019', '-DCMAKE_INCLUDE_PATH=C:\\Users\\Admin\\Downloads\\Pytorch\\mkl\\include', '-DCMAKE_INSTALL_PREFIX=C:\\Users\\Admin\\Downloads\\Pytorch\\pytorch\\torch', '-DCMAKE_PREFIX_PATH=C:\\Users\\Admin\\anaconda3\\envs\\dl\\Lib\\site-packages', '-DJAVA_HOME=C:\\Users\\Admin\\AppData\\Local\\Programs\\AdoptOpenJDK\\', '-DNUMPY_INCLUDE_DIR=C:\\Users\\Admin\\anaconda3\\envs\\dl\\lib\\site-packages\\numpy\\core\\include', '-DPYTHON_EXECUTABLE=C:\\Users\\Admin\\anaconda3\\envs\\dl\\python.exe', '-DPYTHON_INCLUDE_DIR=C:\\Users\\Admin\\anaconda3\\envs\\dl\\include', '-DPYTHON_LIBRARY=C:\\Users\\Admin\\anaconda3\\envs\\dl/libs/python38.lib', '-DTORCH_BUILD_VERSION=1.7.0a0+d4c5f56', '-DUSE_NINJA=OFF', '-DUSE_NUMPY=True', 'C:\\Users\\Admin\\Downloads\\Pytorch\\pytorch']' returned non-zero exit status 1.

Now I let it run without the directory caffe2_builders which I had added after the cloning from git only due to a probably outdated Youtube tutorial. The directory came from pytorch-scripts project, which is outdated. Let’s see.
Result:
LINK : fatal error LNK1356: Die zur vollständigen Archivierung angegebene Bibliothek "\C:/Users/Admin/Downloads/Pytorch/pytorch/build/lib/Release/caffe2_protos.lib\.lib" wurde nicht gefunden. [C:\Users\Admi
n\Downloads\Pytorch\pytorch\build\caffe2\torch_cpu.vcxproj]
Traceback (most recent call last):
  File "setup.py", line 737, in <module>
    build_deps()
  File "setup.py", line 316, in build_deps
    build_caffe2(version=version,
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\build_pytorch_libs.py", line 62, in build_caffe2
    cmake.build(my_env)
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\setup_helpers\cmake.py", line 345, in build
    self.run(build_args, my_env)
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\setup_helpers\cmake.py", line 141, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "C:\Users\Admin\anaconda3\envs\dl\lib\subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '/p:CL_MPCount=4']' returned non-zero exit status 1.

Run again with the directory caffe2_builders causes again the same error:
LINK : fatal error LNK1356: Die zur vollständigen Archivierung angegebene Bibliothek "\C:/Users/Admin/Downloads/Pytorch/pytorch/build/lib/Release/caffe2_protos.lib\.lib" wurde nicht gefunden. [C:\Users\Admi
n\Downloads\Pytorch\pytorch\build\caffe2\torch_cpu.vcxproj]
Traceback (most recent call last):
  File "setup.py", line 737, in <module>
    build_deps()
  File "setup.py", line 316, in build_deps
    build_caffe2(version=version,
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\build_pytorch_libs.py", line 62, in build_caffe2
    cmake.build(my_env)
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\setup_helpers\cmake.py", line 345, in build
    self.run(build_args, my_env)
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\setup_helpers\cmake.py", line 141, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "C:\Users\Admin\anaconda3\envs\dl\lib\subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '/p:CL_MPCount=4']' returned non-zero exit status 1.

After this, I have done everything from the scratch again. Perhaps there were conflicts with the outdated Youtube approach that included files of the pytorch-scrypts project. It seems promising up to now, so perhaps there was simply a problem with the added outdated pytorch-scrypts files.
(myenv) C:\Users\Admin\Downloads\Pytorch>git clone https://github.com/pytorch/pytorch
(myenv) C:\Users\Admin\Downloads\Pytorch\pytorch>git submodule update --init --recursive
(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 CMAKE_GENERATOR=Visual Studio 16 2019
(myenv) C:\Users\Admin\Downloads\Pytorch\pytorch>set USE_NINJA=OFF
(myenv) C:\Users\Admin\Downloads\Pytorch\pytorch>python setup.py install --cmake

But I get the same error:
  Building Custom Rule C:/Users/Admin/Downloads/Pytorch/pytorch/caffe2/CMakeLists.txt
Traceback (most recent call last):
  File "setup.py", line 737, in <module>
    build_deps()
  File "setup.py", line 316, in build_deps
    build_caffe2(version=version,
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\build_pytorch_libs.py", line 62, in build_caffe2
    cmake.build(my_env)
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\setup_helpers\cmake.py", line 345, in build
    self.run(build_args, my_env)
  File "C:\Users\Admin\Downloads\Pytorch\pytorch\tools\setup_helpers\cmake.py", line 141, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "C:\Users\Admin\anaconda3\envs\dl\lib\subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '/p:CL_MPCount=4']' returned non-zero exit status 1.

I do not run any tests any more, each run takes about 7 hours. I am waiting for an idea what I should do. Thank you.