Skip to content

Instantly share code, notes, and snippets.

@gentaiscool
Last active November 7, 2019 08:22
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save gentaiscool/a628fab5cd98953af7f46b69463394b3 to your computer and use it in GitHub Desktop.
Save gentaiscool/a628fab5cd98953af7f46b69463394b3 to your computer and use it in GitHub Desktop.
Building Tensorflow on CentOS 7.X from Source

I figured out how to build tensorflow from source in centOS. This process does not require any root access and you can do it anywhere. This will save your time and no need to worry much after this.

#What to prepare:

  1. Java 8
  2. Bazel
  3. Tensorflow
  4. CuDNN and CUDA toolkit (assume you have install them)

#Installation ##Bazel

I am using Bazel 0.3.2 since I found issues with Bazel in master branch.

check your JAVA_HOME since Bazel requires Java 8, you should download and install it first. This tutorial will not cover it.

$ git clone https://github.com/bazelbuild/bazel.git
$ git checkout tags/0.3.2
$ cd bazel
$ ./compile.sh

It takes some time and after you finished, and add the binary path into the PATH variable, in this case

$ /PATH-TO-BAZEL/output/

##TensorFlow

This is the toughest software to build that I ever know (if you don't have any access to admin). You can download Tensorflow from github as mentioned in the website https://www.tensorflow.org/versions/r0.11/get_started/os_setup.html

$ git clone https://github.com/tensorflow/tensorflow

Then, you may need to hack the code before you can start the configuration free from issues. Go to file tensorflow/third_party/gpus/crosstool/CROSSTOOL and update cxx_builtin_include_directory with

cxx_builtin_include_directory : "/usr/local/cuda/targets/x86_64-linux/include"

Run the configuration

$ ./configure

If you are wonder to use Tensorflow in a GPU with less than 3.5 compute capabilities, you may run this command and type the compute capabilities you desired

TF_UNOFFICIAL_SETTING=1 ./configure

Build with bazel

# Without GPU support
$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package

# To build with GPU support:
$ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

# Build whl file
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

Install tensorflow

pip install --upgrade /tmp/tensorflow_pkg/<your whl file>.whl

And done!

@haramoz
Copy link

haramoz commented Sep 26, 2018

I am unable to use this command yum install bazel because i do not have root access, the centOS i need to setup is in the cluster environment.

@jorgeramirez
Copy link

For those coming from Google and trying to compile tensorflow current 1.12 release. Then, first,
use bazel from here. I encountered some issues while trying to use the newest version of bazel.

When trying to do

bazel build -c opt //tensorflow/tools/pip_package:build_pip_package

I encountered an error and fixed it following this tip. After this fix tensorflow compiled successfuly.

@AmericanEnglish
Copy link

As of tensorflow 2.0

I noticed that, as someone who came from google, these instructions didn't help except the build statement itself.
If you're someone who doesn't have root access and/or working in a cluster style environment. I'd like to mention these issues which talk about fixes for problems I encountered:

  1. Header errors despite their existence
    tensorflow/tensorflow#33975
  2. SWIG and issues with libstdc++.so.1 errors despite gcc being up to date. This issue talks about using a local version of SWIG instead.
    bazelbuild/bazel#4053

I'd also like to respectfully plug my own gist that talks about it as well.

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