為什么從源碼編譯Tensorflow?
-
安裝過的人們都知道如果
pip install tensorflow
的話會(huì)報(bào)錯(cuò)Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
-
考慮到操作系統(tǒng)的的兼容性,現(xiàn)有的編譯好的二進(jìn)制安裝包不適用openeuler,所以考慮這些因素,我們要自己搭建。
-
我們需要bazel交叉編譯軟件,有點(diǎn)類似cmake(上游下載的開源.sh文件已上傳到倉庫)bazel下載地址
-
chmod +x bazel-0.28.0-installer-linux-x86_64.sh
-
./bazel-0.28.0-installer-linux-x86_64.sh --user
-
bazel version 查看版本,configure.py查看tf所支持的版本(2.3版本所支持的bazel)
_TF_MIN_BAZEL_VERSION = '0.27.1'
_TF_MAX_BAZEL_VERSION = '0.29.1'
下載TF
git clone https://github.com/tensorflow/tensorflow
git barach -a 查看所有發(fā)行版本
git checkout <version> 將分支同步到本地
開始編譯
-
bazel build --config=opt --config=cuda //tensorflow:libtensorflow_cc.so (C文件庫)
-
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package (wheel文件)
-
bazel build --config=opt --config=cuda //tensorflow:libtensorflow.so (生成C庫)
-
bazel build --config=opt //tensorflow/lite:libtensorflowlite.so (Lite庫)
bazel編譯有的時(shí)候會(huì)出issue現(xiàn)bug,詳見issue
openeuler搭建Bulid Not Successfully 的Bug情況匯總
官網(wǎng)上說安裝需要pip19以上
關(guān)于openeulerpip源默認(rèn)指向python2該如何修改:
#!/usr/bin/python2=====>!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
2、修改默認(rèn)指向由于版本不同所發(fā)生的bug
from pip import main
ImportError: cannot import name 'main' from 'pip' (/usr/lib/python3.7/site-packages/pip/__init__.py)
source code change to this
from pip import __main__ //這行也要修改
if __name__ == '__main__':
sys.exit(__main__._main())//增加__main__._
PRODUCT
[root@openeuler lzb]# pip -V
pip 20.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
安裝 TensorFlow pip 軟件包依賴項(xiàng)(如果使用虛擬環(huán)境,請(qǐng)省略 --user 參數(shù)):
pip install -U --user pip six numpy wheel setuptools mock 'future>=0.17.1'
pip install -U --user keras_applications --no-deps
pip install -U --user keras_preprocessing --no-deps
|