目录

Mac源码编译TensorFlow

概述

正如官网上说的,目前 TensorFlow 提供已经编译好的 Docker 镜像,所以其实没什么必要自行编译。当然如果你想 fork 一个 TensorFlow 版本,那么当然是需要知道怎么编译。

首先按照官网的指导,肯定是可以编译成功并验证的,但是这里有个小坑不得不提示一下。

Before building TensorFlow, you must install the following on your system:

  • bazel
  • TensorFlow Python dependencies.
  • optionally, NVIDIA packages to support TensorFlow for GPU.

需要注意以上工具和安装包的版本问题。根据这个页面提供的信息很容易会出现工具版本不一致的问题,所以编译之前,务必自行查看各工具包的版本。

1
2
3
4
5
6
/tmp  bazel version
Build label: 0.9.0-homebrew
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Sun Jul 12 03:29:57 +49936 (1513677382197)
Build timestamp: 1513677382197
Build timestamp as int: 1513677382197

另外为了编译成功,需要检查需要编译的 TensorFlow 版本对应的各种安装包的版本。

/mac%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91tensorflow/image_1cb1ijie714ed9msl5isn1hcr9.png

换句话说,如果 Bazel 对应的版本是0.9.0,那么用来编译TensorFlow 1.7.0 就有可能编译不过了。

总结

当然在 Mac 本地编译肯定是不建议的,宁愿买个便宜的国外的竞价实例来做编译都比在本地编译强。

参考资料

  1. https://www.tensorflow.org/install/install_sources
警告
本文最后更新于 2017年2月1日,文中内容可能已过时,请谨慎参考。