Compile Tensorflow 2.01 for Windows
Required :
1. Download sources from GitHub - tensorflow/tensorflow at r2.0
2. Be sure you have installed Cuda 10.0, and CuDNN7.4.1 for Cuda 10.0 (you have to login for CuDNN download)
- Note : see Build from source | TensorFlow for compatibility table
- add path below to system path
- C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin
- C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\libnvvp
- be sure you have system variables
CUDA_PATH
C:\Program
Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0
CUDA_PATH_V10_0 C:\Program
Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0
3. Download bazel compiler system ver. 0.28.0 (it works for me, but you refer to compatibility table as well)
- unpack it to separate folder and add this path to the system path
- Note : probably it could
fail to download some packages and compile time (server is updated
continuously, same packages became obsolete), then try to use different
version, another versions may do compilation job as well, just try it
4. Additionally you will need to install Cuda_10.1 (temporarily)
- replace cudaf++.exe from 10.1 (nvcc 10.0 has crash problem)
- Note : see https://github.com/tensorflow/tensorflow/issues/27576
- you may remove Cuda_10.1 after it is done
5. Bazel is using a lot of space on disc C: (Upto ~20G). If you have not enough space on disc C:, consider :
- move windows temp buffer to another disc (System variables TEMP and TMP)
- disable pagefile.sys on disc C: and enable it on another disc (for example D:)
- disable hibernation mode (hiberfil.sys will be removed)
- clean recycle bin
- you may also use 'cleanmgr' to empty additional space
- you may revert back all changes above after compilation is done
Compiling :
1. Configure
- open CMD window and change to tensorflow main source directory
- run >> python configure.py
- answer on configuration questions:
- Usually I'm setting everything by default, but
change computing compatibility to GPUs I have (for ex. 3.0, 6.1)
- you will get ".tf_configure.bazelrc"
- in .tf_configure.bazelrc
- change true->false for
compile without XLA (dont remember why I did it, may be to
avoid compilation error)
build:xla
--define with_xla_support=false
- add definitions
build
--action_env TF_CUDA_VERSION="10.0"
build
--action_env TF_CUDNN_VERSION="7"
2. Run compilation
- run >> bazel build
--config=opt --config=cuda
//tensorflow/tools/pip_package:build_pip_package
- during compilation you will
experience several errors. Follow acctions below and run compilation
again
- comment in
c:\Users\{username}\_bazel_vadku\lumwegso\external\jpeg\BUILD.bazel
line 123
# nocopts = libjpegturbo_nocopts,
- comment in
c:\Users\{username}\_bazel_vadku\lumwegso\external\mkl_dnn\BUILD.bazel
line 137
# nocopts = "-fno-exceptions",
- Note : refer to https://github.com/mark0725/tensorflow/commit/e5f8043742f927ed0e1711bb48f3e1a153b7a997
- it will take ~1day on 4core desktop PC
3. Build wheel package
- run >> ./bazel-bin/tensorflow/tools/pip_package/build_pip_package ./tensorflow_pkg
- you may experience error like below :
---
Unzipping simple_console_for_windows.zip to create runfiles tree...
[./bazel-bin/tensorflow/tools/pip_package/simple_console_for_windows.zip]
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of ./bazel-bin/tensorflow/tools/pip_package/simple_console_for_windows.zip or
./bazel-bin/tensorflow/tools/pip_package/simple_console_for_windows.zip.zip,
and cannot find
./bazel-bin/tensorflow/tools/pip_package/simple_console_for_windows.zip.ZIP,
period.
---
- solution :
- Edit the following file to remove all the lines with ".zip" :
>> bazel-out/x64_windows-opt/bin/tensorflow/tools/pip_package/simple_console_for_windows.zip-0.params
- Run the
following command line to generate the required zip file. The verbose
option will list all the files.
>> cd bazel-tensorflow-r2.0
>>
external\bazel_tools\tools\zip\zipper\zipper.exe vcC
bazel-out/x64_windows-opt/bin/tensorflow/tools/pip_package/simple_console_for_windows.zip
@bazel-out/x64_windows-opt/bin/tensorflow/tools/pip_package/simple_console_for_windows.zip-0.params
>> cd ..
- run building wheel package again
- Note : refer to https://stackoverflow.com/questions/52394305/creating-pip-package-for-tensorflow-with-gpu-support-results-in-0-byte-simple-co
------------------------
Note (just comment) : at configuration stage I made configuration as below (but default values ar also Ok):
c:\Program Files\NVIDIA GPU Computing
Toolkit\CUDA\v10.0\lib\x64\,c:\Program Files\NVIDIA GPU Computing
Toolkit\CUDA\v10.0\include\,c:\Program Files\NVIDIA GPU Computing
Toolkit\CUDA\v10.0\bin\,c:\Program Files\NVIDIA GPU Computing
Toolkit\CUDA\v10.0\
c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\,c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include\