转载

Spring sidecar模式纳入TF-Serving(二):mac上编译TF-Serving

前言

因为卤煮的云主机只有1G的内存,blade编译的时候一直OOM,所以只能在自己的mac上编译。

blade和TF-Serving版本、gcc版本之间都需要匹配,特别是bazel和TF-Serving之间匹配,不然经常因为各种原因装不上,这里列一下清单:

名称 版本 下载地址
TF-Serving r1.15 https://github.com/tensorflow/serving
bazel 0.24.1 https://github.com/bazelbuild/bazel/releases/tag/0.24.1
python 2.7.10
gcc 6 brew

TF-Serving源码安装

安装依赖项:

java和python的依赖项:

yum -y install java-1.8.0-openjdk-devel automake autoconf libtool libicu patch

pip install --upgrade pip
pip install numpy grpcio Keras-Applications Keras-Preprocessing h5py requests enum --trusted-host pypi.doubanio.com

源码

拉源码下来:

git clone --recurse-submodules https://github.com/tensorflow/models.git
git checkout r1.15
cd serving
bazel build  -c opt //tensorflow_serving/model_servers:tensorflow_model_server --verbose_failures

然后进入漫长的编译,中间会把依赖项拉下来,所以需要有外网的访问权限。

编译中遇到的各种问题

No module named xxx

python中没安装, 找到模块的包名,pip install 即可

升级gcc

mac升级

brew search gcc
brew install gcc@6

编辑 ~/.zshrc

alias gcc="gcc-6"
alias g++="g++-6"
alias cc="gcc-6"
alias c++="c++-6"

然后关闭控制台重新开一个:

➜  ~ gcc -v
Using built-in specs.
COLLECT_GCC=gcc-6
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc@6/6.5.0_2/libexec/gcc/x86_64-apple-darwin18.5.0/6.5.0/lto-wrapper
Target: x86_64-apple-darwin18.5.0
Configured with: ../configure --build=x86_64-apple-darwin18.5.0 --prefix=/usr/local/Cellar/gcc@6/6.5.0_2 --libdir=/usr/local/Cellar/gcc@6/6.5.0_2/lib/gcc/6 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-6 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --enable-stage1-checking --enable-checking=release --enable-lto --with-build-config=bootstrap-debug --disable-werror --with-pkgversion='Homebrew GCC 6.5.0_2' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-nls --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
Thread model: posix
gcc version 6.5.0 (Homebrew GCC 6.5.0_2)

Centos升级

devtoolset升级

yum install -y centos-release-scl-rh centos-release-scl && yum install -y devtoolset-4-gcc devtoolset-4-gcc-c++ devtoolset-4-gdb
echo "source /opt/rh/devtoolset-4/enable" >> /etc/bashrc
source /etc/bashrc

源码编译升级

非常久,不建议。

protoc版本不匹配

如果已经装了protoc又跟TF-Serving版本不匹配,需要卸载protoc。

编译成功

可以检查版本,成功查询就是编译成功了:

➜  serving git:(r1.15) ✗ ./bazel-bin/tensorflow_serving/model_servers/tensorflow_model_server --version
TensorFlow ModelServer: 1.15.0-rc2+dev.sha.748217e4
TensorFlow Library: 1.15.0
原文  http://yizhanggou.top/spring-sidecarmo-shi-na-ru-tf-serving-er/
正文到此结束
Loading...