Skip to content

Instantly share code, notes, and snippets.

@peterjc123
Last active November 12, 2018 16:29
Show Gist options
  • Save peterjc123/a4ac6ce4b0ed4b1b497334baaeb595e3 to your computer and use it in GitHub Desktop.
Save peterjc123/a4ac6ce4b0ed4b1b497334baaeb595e3 to your computer and use it in GitHub Desktop.
Setup script for Windows PyTorch
# Prerequisites
# 1. MSVC 2017 C++ Build Tools
# 2. CMAKE 3.0 or up
# 3. 64 bits of Windows
# 4. Anaconda / MiniConda 64 bits
# Prerequisites for CUDA
# 1. CUDA 8.0 or up
# 2. NVTX( in CUDA as Visual Studio Integration. if fail to install, you can extract
# the CUDA installer exe and found the NVTX installer under the CUDAVisualStudioIntegration)
# 3. MSVC 2015 with Update 2 or up for CUDA 8
# Optional
# 1. cuDNN 6.0 or up
# 2. Blas (MKL, OpenBlas)
git clone --recursive https://github.com/pytorch/pytorch
cd pytorch
xcopy /Y aten\src\ATen\common_with_cwrap.py tools\shared\cwrap_common.py
# Open X86_64 Developer Command Prompt for MSVC 2017 and type in the following commands:
# If you don't want to enable CUDA
set NO_CUDA=1
# If multiple versions of CUDA are installed,it will build for the last one installed. To override
set CUDA_PATH=%CUDA_PATH_V8_0%
set PATH=%CUDA_PATH_V8_0%\bin;%PATH%
# or
set CUDA_PATH=%CUDA_PATH_V9_0%
set PATH=%CUDA_PATH_V9_0%\bin;%PATH%
# For CUDA 8 builds
set CMAKE_GENERATOR=Visual Studio 14 2015 Win64
# For CUDA 9 / CPU builds
set CMAKE_GENERATOR=Visual Studio 15 2017 Win64
# If you want to speed up CUDA builds, use Ninja
pip install ninja
set CMAKE_GENERATOR=Ninja
# If you use Ninja with CUDA 8
set PREBUILD_COMMAND=%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat
set PREBUILD_COMMAND_ARGS=x86_amd64
# If you want to save time for rebuilding it next time, use clcache
pip install git+https://github.com/frerich/clcache.git
set USE_CLCACHE=1
set CC=clcache
set CXX=clcache
# If you want to add BLAS(OpenBLAS, MKL)
set LIB=[PATH_TO_BLAS_LIBS];%LIB%
# If your main python version is < 3.5
set PYTHON_VERSION=3.5 # 3.6 or up is also fine
conda create -q -n test python=PYTHON_VERSION numpy mkl cffi pyyaml
activate test
# If you have both VS2015 and VS2017
set DISTUTILS_USE_SDK=1
# Now you can start install PyTorch here
python setup.py install
@yuchenlin
Copy link

yuchenlin commented Nov 21, 2017

Hi peter, I successfully installed. While, it seems that the cuDNN is not supported?

UserWarning: PyTorch was compiled without cuDNN support. To use cuDNN, rebuild PyTorch making sure the library is visible to the build system.
"PyTorch was compiled without cuDNN support. To use cuDNN, rebuild "

But when I check my cuDNN version, it says
torch.backends.cudnn.version()
5110

@peterjc123
Copy link
Author

peterjc123 commented Nov 29, 2017

@yuchenlin The problem is that you didn't compile with cudnn. Although it can found cudnn during runtime, it can't be used since it's not included in build. My suggestion is that you should rebuild PyTorch and check if cudnn exists before you build. And I don't think cudnn 5.1.10 is supported by PyTorch anyway. You can try using cudnn 6 or up to resolve this problem.

@prithviraj23
Copy link

error: [Errno 2] No such file or directory: 'torch/lib/tmp_install/share/ATen/Declarations.yaml'

@peterjc123
Copy link
Author

@prithviraj23 This error will occur if there's anything wrong with the ATen build. Please send me the first error you met.

@Bisztyga
Copy link

I have same error like prithviraj23, but after installing cmake binary and adding it to path + running script in MSBuild Command Promt for VS2015 it seemed to be ok (it was a lot of warnings about casting int, but no errors). After 45 minutes I've got this:

F:\pytorch\torch\lib\build\ATen\INSTALL.vcxproj" (default target) (1) ->
"F:\pytorch\torch\lib\build\ATen\ALL_BUILD.vcxproj" (default target) (3) ->
"F:\pytorch\torch\lib\build\ATen\src\ATen\ATen.vcxproj" (default target) (4) ->
(ClCompile target) ->
  F:\pytorch\aten\src\TH\vector\AVX2.c(60): error C2440: 'function': cannot convert from 'int' to '__m256' [F:\pytorch\
torch\lib\build\ATen\src\ATen\ATen.vcxproj]

    6764 Warning(s)
    1 Error(s)

Time Elapsed 00:45:04.37
A subdirectory or file build\nanopb already exists.
-- Selecting Windows SDK version  to target Windows 10.0.16299.
-- Configuring done
-- Generating done

@gbmarc1
Copy link

gbmarc1 commented Jan 27, 2018

@peterjc123
Hi Peter,

I have the following error while building:

"C:\Users\Utilisateur\OneDrive\Documents\git\pytorch\torch\lib\build\ATen\INSTALL.vcxproj" (default target) (1) ->
"C:\Users\Utilisateur\OneDrive\Documents\git\pytorch\torch\lib\build\ATen\ALL_BUILD.vcxproj" (default target) (3) ->
"C:\Users\Utilisateur\OneDrive\Documents\git\pytorch\torch\lib\build\ATen\src\ATen\ATen.vcxproj" (default target) (4) -

(Link target) ->
THAtomic.obj : error LNK2019: unresolved external symbol __InterlockedExchange64 referenced in function _THAtomicSetL
ong [C:\Users\Utilisateur\OneDrive\Documents\git\pytorch\torch\lib\build\ATen\src\ATen\ATen.vcxproj]
THAtomic.obj : error LNK2019: unresolved external symbol __InterlockedExchangeAdd64 referenced in function _THAtomicA
ddLong [C:\Users\Utilisateur\OneDrive\Documents\git\pytorch\torch\lib\build\ATen\src\ATen\ATen.vcxproj]
C:\Users\Utilisateur\OneDrive\Documents\git\pytorch\torch\lib\build\ATen\src\ATen\Release\ATen.dll : fatal error LNK1
120: 2 unresolved externals [C:\Users\Utilisateur\OneDrive\Documents\git\pytorch\torch\lib\build\ATen\src\ATen\ATen.vcx
proj]

5397 Warning(s)
3 Error(s)

@peterjc123
Copy link
Author

@gbmarc1 @Bisztyga Please don't write issues here, for there's no notifications on this.
@Bisztyga There's already an issue on this.
@gbmarc1 You are not opening it in the x86_64 developer console. That's why these errors occur.

@robin32205
Copy link

robin32205 commented Feb 22, 2018

@peterjc123
Hi Peter,
I get error code here...

CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.5/Modules/CMakeDetermineCCompiler.cmake:57 (message):
Could not find compiler set in environment variable CC:
clcache.
Call Stack (most recent call first):
CMakeLists.txt:9 (project)
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
ninja: error: loading 'build.ninja':

could you help me fix that?

thanks

@peterjc123
Copy link
Author

peterjc123 commented Mar 18, 2018

Guys, don't ask here. Since there's no notification on this. Please ask here instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment