使用tensorflow serving 启动模型时,报如下错误:The TensorFlow library wasn't compiled to use SSE4.1 instructions

[root@host227 ~]# tensorflow_model_server --port=9002 --model_name=inception --model_base_path=/tf/inception-model/
2017-09-08 05:46:35.324265: I tensorflow_serving/model_servers/main.cc:151] Building single TensorFlow model file config:  model_name: inception model_base_path: /tf/inception-model/ model_version_policy: 0
2017-09-08 05:46:35.324764: I tensorflow_serving/model_servers/server_core.cc:375] Adding/updating models.
2017-09-08 05:46:35.324805: I tensorflow_serving/model_servers/server_core.cc:421]  (Re-)adding model: inception
2017-09-08 05:46:35.425626: I tensorflow_serving/core/basic_manager.cc:698] Successfully reserved resources to load servable {name: inception version: 1}
2017-09-08 05:46:35.425694: I tensorflow_serving/core/loader_harness.cc:66] Approving load for servable version {name: inception version: 1}
2017-09-08 05:46:35.425721: I tensorflow_serving/core/loader_harness.cc:74] Loading servable version {name: inception version: 1}
2017-09-08 05:46:35.425817: I external/org_tensorflow/tensorflow/contrib/session_bundle/bundle_shim.cc:360] Attempting to load native SavedModelBundle in bundle-shim from: /tf/inception-model/1
2017-09-08 05:46:35.425854: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:236] Loading SavedModel from: /tf/inception-model/1
2017-09-08 05:46:35.584750: W external/org_tensorflow/tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-09-08 05:46:35.584811: W external/org_tensorflow/tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-09-08 05:46:35.584822: W external/org_tensorflow/tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-09-08 05:46:35.584831: W external/org_tensorflow/tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-09-08 05:46:35.584840: W external/org_tensorflow/tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
2017-09-08 05:46:35.871503: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:155] Restoring SavedModel bundle.
2017-09-08 05:46:36.471096: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:190] Running LegacyInitOp on SavedModel bundle.
2017-09-08 05:46:36.531887: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:284] Loading SavedModel: success. Took 1105812 microseconds.
2017-09-08 05:46:36.532013: I tensorflow_serving/core/loader_harness.cc:86] Successfully loaded servable version {name: inception version: 1}
2017-09-08 05:46:36.668659: I tensorflow_serving/model_servers/main.cc:294] Running ModelServer at 0.0.0.0:9002 ...

从tensorflow serving的启动过程可以发现有如下warning信息:
2017-09-08 05:46:35.584750: W external/org_tensorflow/tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-09-08 05:46:35.584811: W external/org_tensorflow/tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-09-08 05:46:35.584822: W external/org_tensorflow/tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-09-08 05:46:35.584831: W external/org_tensorflow/tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-09-08 05:46:35.584840: W external/org_tensorflow/tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.

意思是tensorflow 库编译没有使用 SSE4.1/SSE4.2/AVX/AVX2/FMA,可是这些指令集在机器上存在,而且能加速CPU的计算。
既然都这么说了,那就让咱安装的tensorflow serving 使用上面的指令集,如何做呢?
就是使用源码安装tensorflow serving,且在bazel build 是添加如下参数即可:
--copt=-msse4.1 --copt=-msse4.2 --copt=-mavx --copt=-mavx2 --copt=-mfma

注,下面的操作步骤直接从下载tensorflow serving的源码开始,为安装tensorflow serving准备各种依赖库的步骤就省略了,具体的请参考:
https://github.com/tensorflow/serving/blob/master/tensorflow_serving/g3doc/setup.md

解决办法:
1,git下载最新的tensorflow serving代码:
git clone --recurse-submodules https://github.com/tensorflow/serving

注:会在当前目录下产生serving文件夹。
2,执行如下操作:
cd serving/tensorflow && ./configure

注:运行命令后出现一些选项供选择,按需选择即可。
若安装支持cpu的tensorflow时,建议选择全部默认配置即可,即每步都直接回车。
若安装支持GPU的tensorflow时,选好cuda或者cudnn的版本即可

3,  编译tensorflow serving
cd ../ &&
bazel build -c opt --copt=-msse4.1 --copt=-msse4.2 --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-O3 tensorflow_serving/...

注:bazel build 这步操作挺耗时的,需要下载挺多的依赖包,若当前你的机器无法估计还会失败。建议在能的情况下操作。
其中bazel build 的编译参数就是解决那些warning的关键所在。

4, 再次验证一下:
# tensorflow_model_server --port=9003 --model_name=inception --model_base_path=/tf/inception-model/
2017-09-08 07:02:07.467884: I tensorflow_serving/model_servers/main.cc:147] Building single TensorFlow model file config:  model_name: inception model_base_path: /tf/inception-model/
2017-09-08 07:02:07.468265: I tensorflow_serving/model_servers/server_core.cc:434] Adding/updating models.
2017-09-08 07:02:07.468327: I tensorflow_serving/model_servers/server_core.cc:485]  (Re-)adding model: inception
2017-09-08 07:02:07.568917: I tensorflow_serving/core/basic_manager.cc:705] Successfully reserved resources to load servable {name: inception version: 1}
2017-09-08 07:02:07.568989: I tensorflow_serving/core/loader_harness.cc:66] Approving load for servable version {name: inception version: 1}
2017-09-08 07:02:07.569023: I tensorflow_serving/core/loader_harness.cc:74] Loading servable version {name: inception version: 1}
2017-09-08 07:02:07.569072: I external/org_tensorflow/tensorflow/contrib/session_bundle/bundle_shim.cc:360] Attempting to load native SavedModelBundle in bundle-shim from: /tf/inception-model/1
2017-09-08 07:02:07.569115: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:236] Loading SavedModel from: /tf/inception-model/1
2017-09-08 07:02:07.760806: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:155] Restoring SavedModel bundle.
2017-09-08 07:02:08.083692: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:190] Running LegacyInitOp on SavedModel bundle.
2017-09-08 07:02:08.150753: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:284] Loading SavedModel: success. Took 581322 microseconds.
2017-09-08 07:02:08.151406: I tensorflow_serving/core/loader_harness.cc:86] Successfully loaded servable version {name: inception version: 1}
E0908 07:02:08.178288291   93406 ev_epoll1_linux.c:1051]     grpc epoll fd: 3
2017-09-08 07:02:08.179964: I tensorflow_serving/model_servers/main.cc:288] Running ModelServer at 0.0.0.0:9003 ...


5,手工打完。

参考:
tensorflow serving 官方安装文档:https://github.com/tensorflow/serving/blob/master/tensorflow_serving/g3doc/setup.md

你可能感兴趣的:(tensorflow,serving)