[PYTHON] Build procedure of TensorFlow 2.2.0-rc0 (CUDA10.2 + cuDNN7.6.5) --Windows10

This is the procedure to build TensorFlow 2.2.0-rc0 (GPU version) on Windows 10. Since detailed explanation is omitted and only the main points are described, a little more detailed content such as Blog of dev.infohub.cc etc. I hope you can refer to it.

Build environment preparation

Use the following environment for building. CUDA, cuDNN, Python, etc. should be put in the PATH in advance.

MSYS2 package added

Launch C: \ msys64 \ msys2_shell.cmd and add the packages needed for your build.

#Installation of required packages
pacman -S git patch unzip

#After that, the MSYS2 console will not be used, so it will end.
exit

Build TensorFlow

We will build TensorFlow using the Python virtual environment g: \ venvs \ build_tf2 for build. Please read the path etc. according to each environment.

For the following operations, use the console screen launched by x64 Native Tools Command Prompt for VS 2019 in Visual Studio 2019.

#Create and activate a virtual environment
python -m venv g:\venvs\build_tf2
cd /d g:\venvs\build_tf2
g:\venvs\build_tf2\Scripts\activate.bat

#pip upgrade (optional)
python -m pip install --upgrade pip

#Introduce the packages required for build
pip install six numpy wheel
pip install keras_applications==1.0.8 --no-deps
pip install keras_preprocessing==1.1.0 --no-deps

# TensorFlow v2.2.0-Get the source code of rc0
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout v2.2.0-rc0

#Delete unnecessary environment variables (optional)
#All environment variables are passed as parameters, so if the parameter string exceeds 32768 characters
# FATAL: Command line too long (34052 > 32768)An error like this occurs.
#To prevent that, temporarily delete unnecessary environment variables here.
# _OLD_VIRTUAL_PATH tends to have a large number of characters, so it is the first choice to delete.
set _OLD_VIRTUAL_PATH=

#Build configuration settings
#----------------------------------------------------------------
# <Setting Example>
# Location of Python        : (Default)
# ROCm support              : (Default = N)
# CUDA support              : Y
# CUDA compute capabilities : 7.5 (For details https://developer.nvidia.com/cuda-See gpus) 
# Optimization flag         : /arch:AVX2
# Override eigen...         : (Default = Y)
#----------------------------------------------------------------
python ./configure.py

#Build (for CUDA)
#It takes tens of minutes to hours to complete the build
bazel build --config=opt --config=cuda --define=no_tensorflow_py_deps=true --copt=-nvcc_options=disable-warnings //tensorflow/tools/pip_package:build_pip_package

#Creating a Wheel package
# g:\tensorflow_Create a package in the pkg folder (takes a few minutes)
bazel-bin\tensorflow\tools\pip_package\build_pip_package g:\tensorflow_pkg

#This completes the TensorFlow build. Exit with exit.
#----------------------------------------------------------------
# <reference>
#Bazel's work file%UserProfile%_bazel_%UserName%Because it is created in
#If you don't need it, you can delete this folder (capacity of about 20GB)
#----------------------------------------------------------------
exit

Introducing TensorFlow built in a new environment

How to deploy the built TensorFlow into a new Python virtual environment. Here is an example of creating a new virtual environment in g: \ venvs \ tf2.

#Create and activate a virtual environment
python -m venv g:\venvs\tf2
g:\venvs\tf2\Scripts\activate.bat

#pip update (optional)
python -m pip install --upgrade pip

#Install the built TensorFlow (just specify the created wheel file)
pip install g:\tensorflow_pkg\tensorflow-2.2.0rc0-cp38-cp38-win_amd64.whl

#Operation check
python -c "import tensorflow as tf; print(tf.__version__); print(tf.keras.__version__)"
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

Remarks

I get the impression that building TensorFlow 2.2.0-rc0 is much easier than it was in TensorFlow v1. Even in this build, when I tried python ./configure.py, I just encountered the errorFATAL: Command line too long (34052> 32768), and nothing else happened. did.

In many cases, the DLL cannot be found at runtime and an error occurs. In this case, check that the path to the required library such as CUDA is in place.

Recommended Posts

Build procedure of TensorFlow 2.2.0-rc0 (CUDA10.2 + cuDNN7.6.5) --Windows10
Build procedure for TensorFlow 2.4.0 (Windows10, CUDA11.1.1, cuDNN 8.0.5, Python 3.8.6)
Build TensorFlow on Windows
How to force build TensorFlow 2.3.0 for CUDA11 + cuDNN8
Install CUDA10.1 + cuDNN7.6.5 + tensorflow-2.3.0 on Ubuntu 18.04
How to update to Chainer 2.0 (Windows + CUDA 8.0 + CUDNN)
Steps to build PyTorch 1.5 for CUDA 10.2 on Windows
Execution procedure of TensorFlow in batch processing of supercomputer ITO
Let's Deep Learning on Windows! (VS2013 + caffe + CUDA7.5 + cudnn5.1)
Procedure memo when doing unofficial release build of CardIO