[PYTHON] Steps to build PyTorch 1.5 for CUDA 10.2 on Windows

Here are the steps to build PyTorch 1.5 for CUDA 10.2 on Windows 10. (As of March 1, 2020) It also includes the torchvision build instructions that are commonly used with PyTorch. Detailed explanation is omitted here, so if you need a little more detailed explanation, please also refer to Blog --dev.infohub.cc. I hope you can.

Build environment

Settings such as environment variables

--MKL_DEBUG_CPU_TYPE = 5 (Settings for using MKL on AMD CPUs) --The PATH to other CUDA etc. is in place

Build PyTorch, torchvision

Open the x64 Native Tools Command Prompt for VS 2019 in Visual Studio 2019 and follow the steps below. (Explanation is posted in comment format)

#Virtual environment for build(build_pt)Create
python -m venv g:\work\build_pt
g:\work\build_pt\Scripts\activate.bat
cd /d g:\work\build_pt

#Updates such as packages
python -m pip install --upgrade pip

#Installation of packages required for build
pip install numpy ninja pyyaml mkl mkl-include cmake cffi wheel

#Get source
#Unlike the procedure on the original site, the submodule will be acquired later.
git clone https://github.com/pytorch/pytorch
cd pytorch

# 2020/03/01 13:Switch to the state at the time of 24 (latest state tried this time)
git checkout ace2b4f

#Get submodule
git submodule sync
git submodule update --init --recursive

#Build (about 18 minutes with Threadripper 3960X)
python setup.py install

#Create wheel package (put wheel in pip)
# G:\work\build_pt\pytorch\"Torch" in dist-1.5.0a0+ace2b4f-cp38-cp38-win_amd64.whl "is created
python setup.py bdist_wheel

# ----Build torchvision from here----------------------------------

#Parent folder (g:\work\build_Move to pt)
cd ..

#Introducing additional packages needed to build torchvision
pip install six pillow

#Check if CUDA is used in torchvision
#If this result is True, CUDA will be used (you can also build to force it, see the torchvision page for details).
python -c "import torch; print(torch.cuda.is_available())"

#Get the source code of torchvision
git clone https://github.com/pytorch/vision.git
cd vision

git checkout b2e9565

#Build (a few minutes)
python setup.py install

#Creating a wheel package
python setup.py bdist_wheel

This will create a PyTorch and torchvision wheel file (* .whl) in the dist folder.

Introduction to the usage environment

This is the procedure to install the built PyTorch and torchvision wheel packages in separate virtual environments. Since the build folder uses a lot of disk space, it is convenient to separate the environment that actually uses PyTorch etc. from the virtual environment for build. Here, it is assumed that a virtual environment called `ml``` is created under c: \ venvs \ ``. You can run it from a normal command prompt (not the Visual Studio console)

#Virtual environment(ml)Create
python -m venv c:\venvs\ml
c:\venvs\ml\Scripts\activate.bat
cd /d c:\venvs\ml

#Updates such as packages
python -m pip install --upgrade pip

#Introducing PyTorch and torchvision (including dependent packages)
#For the whl file of PyTorch and torchvision, specify the file created above.
pip install numpy mkl six pillow
pip install "torch-1.5.0a0+ace2b4f-cp38-cp38-win_amd64.whl"
pip install "torchvision-0.6.0a0+b2e9565-cp38-cp38-win_amd64.whl"

This completes the PyTorch 1.5.0a0 environment creation for CUDA 10.2.

Recommended Posts

Steps to build PyTorch 1.5 for CUDA 10.2 on Windows
Build procedure for TensorFlow 2.4.0 (Windows10, CUDA11.1.1, cuDNN 8.0.5, Python 3.8.6)
Build TensorFlow on Windows
Build XGBoost on Windows
Build Linux on a Windows environment. Steps to install Laradock and migrate
How to force build TensorFlow 2.3.0 for CUDA11 + cuDNN8
Build a Python extension for E-Cell 4 on Windows 7 (64bit)
F2py on Miniconda for Windows
Build Python environment on Windows
Build python environment on windows
Build Python3 for Windows 10 on ARM with Visual Studio 2019 (x86) on Windows 10 on ARM
Steps to deploy EMLauncher on CentOS 8
Steps to install MySQL 8.0 on CentOS 8.1
Python 3.6 on Windows ... and to Xamarin.
How to use Dataiku on Windows
Steps to install matplotlib on Mac
Build and install OpenCV on Windows
Steps to install VirtualBox on CentOS
Install Pytorch on Blender 2.90 python on Windows
How to install pycrypto on Windows
How to deploy django-compressor on Windows
Steps to install python3 on mac
pykintone on Windows Subsystem for Linux
How to install music 21 on windows
What to do if Python doesn't work on Git for Windows
The easiest way to get Chainer v1.5 + CUDA + cuDNN on Windows
Notes for using OpenCV on Windows10 Python 3.8.3.
[UE4] Build DedicatedServer on Windows and Linux
Python 2.7, 3.4, 3.5 extension module build environment on Windows
Programming environment for beginners made on Windows
How to update to Chainer 2.0 (Windows + CUDA 8.0 + CUDNN)
[Kivy] How to install Kivy on Windows [Python]
How to build Hello, World on #Nix
[Note] Procedures for installing Ubuntu on Windows 10
Steps to create a Python virtual environment with VS Code on Windows
Steps to install Python environment on Ubuntu
How to use Google Assistant on Windows 10
How to install Windows Subsystem For Linux
Building an environment for "Tello_Video" on Windows
How to build an environment for using multiple versions of Python on Mac
[Forefront of Object Recognition 2020] Logs from installing Pytorch on Windows 10 to running CornerNet-Lite.
Until you can use RTX 2060 on Windows 10 (Installing NVIDIA DRIVER, NVIDIA CUDA toolkit, PyTorch)
Various ways to execute .py files on Windows
For beginners to build an Anaconda environment. (Memo)
Put MicroPython on Windows to run ESP32 on Python
(Windows) Causes and workarounds for UnicodeEncodeError on Python 3
Simply build a Python 3 execution environment on Windows
[Latest] How to build Java environment on Ubuntu
How to quickly install h5py on Windows 10 [Unofficial]
Build procedure of TensorFlow 2.2.0-rc0 (CUDA10.2 + cuDNN7.6.5) --Windows10
From ROS for Windows installation to operation check
How to live a decent life on 2017 Windows
Build a Kubernetes environment for development on Ubuntu
I want to do pyenv + pipenv on Windows
[Python] How to install OpenCV on Anaconda [Windows]
How to build Java environment on Ubuntu (Linux)
[Windows] Memo to use Keras on GPU [Tensorflow-GPU]
Convert binary packages for windows to wheel format
How to install / verify graphviz on anaconda / windows10
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
How to embed mod_wsgi into Apache on Python Windows