从源代码安装tensorflow

编程入门 行业动态 更新时间:2024-10-08 02:24:20

从<a href=https://www.elefans.com/category/jswz/34/1769335.html style=源代码安装tensorflow"/>

从源代码安装tensorflow

1、克隆最新tensorflow仓库:

git clone 

2、选择特定的分支:

cd tensorflow
git checkout Branch # where Branch is the desired branch

3、安装 Bazel

按照bazel官网上安装即可。(下载二进制可执行文件)

4、 ./configure

除了

Do you wish to use jemalloc as the malloc implementation? [Y/n] Y

这个选项选择Y,其余选项都选择N (CPU-only情况下)

5、Build the pip package

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

在编译时,bazel带上--config=opt会使用默认的-march=native,tensorflow会提高使用cpu的速度。

Update: 按照How to compile Tensorflow with SSE4.2 and AVX instructions?,运行tensorflow程序时可以满载使用CPU

在CPU的情况下,

bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.2  //tensorflow/tools/pip_package:build_pip_package

当我用上面命令编译tensorflow时,我的服务器CPU会报错:The TensorFlow library was compiled to use AVX2 instructions, but these aren't available on your machine.另一个错误:The TensorFlow library was compiled to use FMA instructions, but these aren't available on your machine.

所以,用下面的命令编译tensorflow(但是这条命令起不到加速的效果):

bazel build -c opt --copt=-march=native --copt=-mfpmath=both //tensorflow/tools/pip_package:build_pip_package

命令(也起不到加速的效果):

bazel build -c opt --copt=-mavx --copt=-msse4.1 --copt=-msse4.2  -k //tensorflow/tools/pip_package:build_pip_package

将所有不报错的参数都加进去(还是起不到加速的效果,也只用到了最多90%的算力):

bazel build -c opt --copt=-mavx --copt=-march=native  --copt=-mfpmath=both --copt=-msse4.1 --copt=-msse4.2  -k //tensorflow/tools/pip_package:build_pip_package

bazel build -c opt --copt=-mavx --copt=-march=native  --copt=-mfpmath=both --copt=-msse4.2  //tensorflow/tools/pip_package:build_pip_package


bazel build -c opt --copt=-mavx --copt=-msse4.1 --copt=-msse4.2  -k //tensorflow/tools/pip_package:build_pip_package //起不到加速的效果


bazel build -c opt --copt=-mavx --copt=-march=native  --copt=-mfpmath=both --copt=-msse4.1 --copt=-msse4.2  -k //tensorflow/tools/pip_package:build_pip_package  //起不到加速的效果


bazel build -c opt --copt=-mavx  --copt=-mfpmath=both --copt=-msse4.2  //tensorflow/tools/pip_package:build_pip_package  //起不到加速的效果


bazel build -c opt --copt=-mavx --copt=-msse4.1 --copt=-msse4.2  -k //tensorflow/tools/pip_package:build_pip_package


bazel build -c opt --copt=-march=native --copt=-mfpmath=both --copt=-msse4.2 //tensorflow/tools/pip_package:build_pip_package ///起不到加速的效果


bazel build -c opt --copt=-march=native --copt=-mfpmath=both --copt=-msse4.1 --copt=-msse4.2 //tensorflow/tools/pip_package:build_pip_package //起不到加速的效果


bazel build -c opt --copt=-mavx  --copt=-mfpmath=both  --copt=-msse4.2 //tensorflow/tools/pip_package:build_pip_package


bazel build -c opt --copt=-mavx --copt=-mavx2  --copt=-mfpmath=both --copt=-msse4.2  //tensorflow/tools/pip_package:build_pip_package  //报错


bazel build -c opt --copt=-mavx --copt=-mfma --copt=-mfpmath=both --copt=-msse4.2  //tensorflow/tools/pip_package:build_pip_package  //报错


bazel build -c opt --copt=-mavx --copt=-mfpmath=both --copt=-msse4.1 --copt=-msse4.2  -k //tensorflow/tools/pip_package:build_pip_package //不要march=native


在GPU的情况下

bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.2 --config=cuda  //tensorflow/tools/pip_package:build_pip_package

或者是:

bazel build -c opt --copt=-march=native --copt=-mfpmath=both --config=cuda //tensorflow/tools/pip_package:build_pip_package

bazel build命令会创建一个叫做build_pip_package的脚本,使用下面命令运行该脚本可以在/tmp/tensorflow_pkg目录下创建一个.whl文件

bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg


6、Install the pip package

pip install /tmp/tensorflow_pkg/tensorflow-1.4.0-py2-none-any.whl
(具体安装包名称视情况而定)

更多推荐

从源代码安装tensorflow

本文发布于:2024-02-14 14:36:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1763629.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:源代码   tensorflow

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!