gpt4 book ai didi

android - Android 上的基准量化

转载 作者:行者123 更新时间:2023-11-30 03:38:26 26 4
gpt4 key购买 nike

我一直在使用 benchmark_model 在 Exynos 7420 上对 tensorflow 模型进行基准测试。我想根据 Pete Warden's blog 加速测试量化但是还不能用量化 deps 编译 benchmark_model,因为它们破坏了很多东西。

我已遵循此 stack overflow thread 中列出的指南:

//tensorflow/tools/benchmark/BUILD cc_binary

    deps = [":benchmark_model_lib",
"//tensorflow/contrib/quantization/kernels:quantized_ops",
],

//tensorflow/contrib/quantization/kernels/BUILD:

deps = [
"//tensorflow/contrib/quantization:cc_array_ops",
"//tensorflow/contrib/quantization:cc_math_ops",
"//tensorflow/contrib/quantization:cc_nn_ops",
#"//tensorflow/core",
#"//tensorflow/core:framework",
#"//tensorflow/core:lib",
#"//tensorflow/core/kernels:concat_lib_hdrs",
#"//tensorflow/core/kernels:conv_ops",
#"//tensorflow/core/kernels:eigen_helpers",
#"//tensorflow/core/kernels:ops_util",
#"//tensorflow/core/kernels:pooling_ops",
"//third_party/eigen3",
"@gemmlowp//:eight_bit_int_gemm",
],

然后运行:

bazel build -c opt --cxxopt='-std=gnu++11'--crosstool_top=//external:android/crosstool --cpu=armeabi-v7a --host_crosstool_top=@bazel_tools//tools/cpp :toolchain tensorflow/tools/benchmark:benchmark_model --verbose_failures

其中(遵循链接帖子中的所有其他说明)成功,但它无法链接到 pthread。

我试过在 tensorflow/tensorflow.bzl tfcopts() 中删除 -lpthread,同样在 tensorflow/tools/proto_text/BUILD 和 tensorflow/cc/BUILD 中删除。

def tf_copts():
return (["-fno-exceptions", "-DEIGEN_AVOID_STL_ARRAY"] +
if_cuda(["-DGOOGLE_CUDA=1"]) +
if_android_arm(["-mfpu=neon"]) +
select({"//tensorflow:android": [
"-std=c++11",
"-DMIN_LOG_LEVEL=0",
"-DTF_LEAN_BINARY",
"-O2",
],
"//tensorflow:darwin": [],
"//tensorflow:ios": ["-std=c++11",],
#"//conditions:default": ["-lpthread"]}))
"//conditions:default": []}))

仍然收到链接错误。

external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lpthread
collect2: error: ld returned 1 exit status

非常感谢任何帮助,我很困惑。

环境:

  • Ubuntu 14.04
  • tensorflow 提交 #4462
  • android_ndk_r11c
  • android-sdk-linux r24.4.1
  • Python 2.7.12::Continuum Analytics, Inc.
  • ./configure 不支持 GCP、HDFS 或 GPU

最佳答案

转录 GitHub answer from Andrew Harp在TF队。谢谢!!!

以上改动都是不必要的。您可以通过以下方式为 benchmark_model(或依赖于 android_tensorflow_lib 的任何目标)进行量化:

  1. git pull --recurse-submodules(获取@gemmlowp 库,也可以 git clone --recursive)
  2. 对//tensorflow/core/BUILD 进行以下编辑

`

diff --git a/tensorflow/core/BUILD b/tensorflow/core/BUILD
--- a/tensorflow/core/BUILD
+++ b/tensorflow/core/BUILD
@@ -713,8 +713,11 @@ cc_library(
# binary size (by packaging a reduced operator set) is a concern.
cc_library(
name = "android_tensorflow_lib",
- srcs = if_android([":android_op_registrations_and_gradients"]),
- copts = tf_copts(),
+ srcs = if_android([":android_op_registrations_and_gradients",
+ "//tensorflow/contrib/quantization:android_ops",
+ "//tensorflow/contrib/quantization/kernels:android_ops",
+ "@gemmlowp//:eight_bit_int_gemm_sources"]),
+ copts = tf_copts() + ["-Iexternal/gemmlowp"],
linkopts = ["-lz"],
tags = [
"manual",

刚刚测试,效果很好。有趣的是,量化生成的图形大小是未量化图形的 1/4,但推理执行速度是未量化图形的 4-5 倍——似乎量化操作仍在优化中。

关于android - Android 上的基准量化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39610235/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com