Skip to content

Compiling Tensorflow

It is strongly discouraged to attempt building TensorFlow from source.

Documentation

Official installation instructions are at Installing TensorFlow from Sources

Prerequisites

  • Bazel
  • Python 2.7 -- current versions of TensorFlow should work with Python 3 as well
  • May need protobuf -- module load protobuf/gcc/3.3.0

Configure

$ ./configure

Modify workspace.bzl

Due to the way git computes checksums[1] tarballs downloaded from GitHub may not have a "constant" checksum. The fix is to edit the file tensorflow/workspace.bzl to remove or comment out the GitHub URL from the specification for the "protobuf" package:

  patched_http_archive(
      name = "protobuf",
      urls = [
          #"https://github.com/google/protobuf/archive/0b059a3d8a8f8aa40dde7bea55edca4ec5dfea66.tar.gz",
          "http://mirror.bazel.build/github.com/google/protobuf/archive/0b059a3d8a8f8aa40dde7bea55edca4ec5dfea66.tar.gz",
      ],
      sha256 = "6d43b9d223ce09e5d4ce8b0060cb8a7513577a35a64c7e3dad10f0703bf3ad93",
      strip_prefix = "protobuf-0b059a3d8a8f8aa40dde7bea55edca4ec5dfea66",
      # TODO: remove patching when tensorflow stops linking same protos into
      #       multiple shared libraries loaded in runtime by python.
      #       This patch fixes a runtime crash when tensorflow is compiled
      #       with clang -O2 on Linux (see https://github.com/tensorflow/tensorflow/issues/8394)
      patch_file = str(Label("//third_party/protobuf:add_noinlines.patch")),
  )

Or use the one-liner sed:

sed -i '\@https://github.com/google/protobuf/archive/0b059a3d8a8f8aa40dde7bea55edca4ec5dfea66.tar.gz@d' tensorflow/workspace.bzl

Fix CROSSTOOL

Because Proteus's default gcc is not the Red Hat-provided gcc, and it lives in a different location, the TensorFlow build will fail. It will try to link against libraries in /usr/lib64 (specifically, libstdc++), and there will be a library version mismatch error.

To fix, follow the instructions in Bazel wiki: Building with a custom toolchain.

Build

bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

See Also

References

[1] libgit2 issue #4343 - SHA256 checksum changed for v0.26.0