Skip to content

Instantly share code, notes, and snippets.

@lijiansong
Last active March 25, 2021 02:48
Show Gist options
  • Save lijiansong/c0cb5c4afb677b4e2e695a71ef952451 to your computer and use it in GitHub Desktop.
Save lijiansong/c0cb5c4afb677b4e2e695a71ef952451 to your computer and use it in GitHub Desktop.

Build TF 2.0 from source

Step 1:

从anaconda的base环境中创建新的环境:

$ conda create -n tf2-source python=3.6
$ conda activate tf2-source

最好选择python3,否则编译脚本会出现兼容性错误!!!

基于该虚拟环境进行从源码build。 build过程中如果缺少相关的依赖模块,手工安装。

Bazel安装可以从源github中release页面下载installer-xxx.sh

$ ./bazel-0.29.1-installer-linux-x86_64.sh --user

安装在个人目录下,不需要sudo权限。

Step 2:

$ ./configure

选择需要的选项,tensorrt可以关掉。 然后,bazel build进行编译:

$ bazel build --config=cuda [--config=option] //tensorflow/tools/pip_package:build_pip_package

安装的过程中,由于网络原因部分依赖库可能下载不下来,此时可以手工下载,放在提示的目录下,如:

ERROR: An error occurred during the fetch of repository 'io_bazel_rules_go':
   Traceback (most recent call last):
	File "/home/dataflow/.cache/bazel/_bazel_dataflow/a070875b19125f303ef2f02922aed5a5/external/bazel_tools/tools/build_defs/repo/http.bzl", line 111, column 45, in _http_archive_impl
		download_info = ctx.download_and_extract(
Error in download_and_extract: java.io.IOException: Error downloading [https://github.com/bazelbuild/rules_go/releases/download/0.18.5/rules_go-0.18.5.tar.gz] to /home/dataflow/.cache/bazel/_bazel_dataflow/a070875b19125f303ef2f02922aed5a5/external/io_bazel_rules_go/temp15150386869874428079/rules_go-0.18.5.tar.gz: connect timed out

上面信息提示缺少rules_go-0.18.5.tar.gz,此时可以从上述链接中下载下来并放在bazel cache目录下,并修改成对应提示的文件名! 以上方式可以解决国内网络不稳定的问题!

CUDA 10.2 fatbinary选项错误,参考该issue删除third_party/nccl/build_defs.bzl.tpl 中的"--bin2c-path=%s" % bin2c.dirname

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