I will leave an overview of how to build TensorFlow 2.4.0 as of December 17, 2020.
If Numpy is the latest 1.19.4, an error will occur just by importing it in the Windows environment, so use the previous 1.19.3
. (This is a problem on the Windows side, and it seems that it will be fixed around January 2021)
This is the environment used for the build. It is in a state where the path is passed in advance, such as the CUDA and cuDNN folders.
pacman -S git patch unzip
)This time, the TensorFlow source code is downloaded and built under the S: \ build \ build_tf240
folder. A Python virtual environment is also prepared for the TensorFlow build.
S:/build/build_tf240 #Working folder Root
+ tensorflow #Source code obtained by git
+ venv #Python virtual environment
+ wheelhouse #Folder to store the created whl file
Start x64 Native Tools Command Prompt for VS 2019
and follow the steps below to build.
#Create and activate a virtual environment
python -m venv s:\build\build_tf240\venv
cd /d s:\build\build_tf240
.\venv\Scripts\activate.bat
#Installation of required packages
#Note: Numpy is the latest 1.19.If you use 4, you will get an error, so 1.19.Use 3 (Numpy 1 when using).19.Use 3)
python -m pip install --upgrade pip setuptools
pip install numpy==1.19.3
pip install six wheel
pip install keras_applications==1.0.8 --no-deps
pip install keras_preprocessing==1.1.2 --no-deps
#Source code acquisition (v2.4.0 tag specification)
git clone -b v2.4.0 https://github.com/tensorflow/tensorflow.git
cd tensorflow
#In some environments, command parameters become too long and an error occurs, so delete unnecessary environment variables.
set _OLD_VIRTUAL_PATH=
#Build configuration settings
# CUDA support: Y
# CUDA compute capabilities: 7.5 (Change according to the usage environment)
# Optimization: /arch:AVX2 (changed according to usage environment)
#Other than that, the default setting (Enter)
python ./configure.py
#Build
# TensorFlow 2.3.x+In the case of CUDA11, "DTHRUST_IGNORE_CUB_VERSION_I needed the magic of "CHECK" (skipping the CUB compatibility check), but 2.4.x is unnecessary
bazel build --config=opt --config=avx2_win --config=short_logs --config=cuda --define=no_tensorflow_py_deps=true --copt=-nvcc_options=disable-warnings //tensorflow/tools/pip_package:build_pip_package
#Create package (create package in wheelhouse folder)
#I'm worried that the screen won't refresh for a few minutes, but it's being processed properly so let's wait for a while.
bazel-bin\tensorflow\tools\pip_package\build_pip_package ..\wheelhouse
That's it.
The bazel intermediate files used for the build are created in the % UserProfile% \ _bazel_% UserName%
folder, and the capacity is close to 20GB, so you can delete them if you don't need them. If Bazel is running, you cannot delete it. In that case, use bazel shutdown
at the command prompt, exit Bazel, and then delete it.
When using the created TensorFlow wheel package, it is recommended to install Numpy by version specification before TensorFlow with the feeling of pip install numpy == 1.19.3
. The latest Numpy 1.19.4 is not available as of 12/17/2020.