[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tensorflow lite selective build results _ZN6google8protobuf8internal26fixed_address_empty_stringE" error, build fails with tne --config=monolithic setup, returning the Check failed: existing == nullptr (Tensor already registered) errror #60831

Open
dachshund-ncu opened this issue Jun 10, 2023 · 28 comments
Assignees
Labels
comp:lite TF Lite related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.13 For issues related to Tensorflow 2.13 type:bug Bug type:build/install Build and install issues

Comments

@dachshund-ncu
Copy link
dachshund-ncu commented Jun 10, 2023
Click to expand!

Issue Type

Bug

Have you reproduced the bug with TF nightly?

No

Source

source

Tensorflow Version

2.13

Custom Code

No

OS Platform and Distribution

Ubuntu 22.04 lts, Ubuntu 23.04

Mobile device

No response

Python version

No response

Bazel version

6.1.0

GCC/Compiler version

9.4.0

CUDA/cuDNN version

No response

GPU model and memory

No response

Current Behaviour?

I tried to create the selective build of the tensorflow lite, following this guide.
The build succeeded and I added the tensorflow-lite-select-tf-ops.aar to the android studio project, yet it resulted in an error:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN6google8protobuf8internal26fixed_address_empty_stringE" referenced by "/data/app/~~PgTBlp4bIwZ8yl02UBjqqg==/com.inseye.core.test-yoruTyRORPvs5Ap3TE6dGw==/base.apk!/lib/x86_64/libtensorflowlite_flex_jni.so".

I noticed, there are fixes for this problem, e.g. here - one needs just add following line:

--config=monolithic

to the .bazelrc file.
But build with this configuration fails with the following error:

ERROR: /tensorflow_src/tensorflow/BUILD:1652:19: Action tensorflow/_api/v2/v2.py [for tool] failed: (Aborted): bash failed: error executing command (from target //tensorflow:tf_python_api_gen_v2) 
  (cd /root/.cache/bazel/_bazel_root/43801f1e35f242fb634ebbc6079cf6c5/execroot/org_tensorflow && \
  exec env - \
    DOCKER_HOST_CACHEBUSTER=1682977560680045781 \
    LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64 \
    PATH=/root/.cache/bazelisk/downloads/bazelbuild/bazel-6.1.0-linux-x86_64/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/android/sdk/cmdline-tools/latest/bin:/android/sdk/platform-tools:/android/ndk \
  /bin/bash -c 'bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2 --root_init_template=tensorflow/api_template.__init__.py --apidir=bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/_api/v2/ --apiname=tensorflow --apiversion=2  --compat_apiversion=1 --compat_apiversion=2  --compat_init_template=tensorflow/compat_template_v1.__init__.py --compat_init_template=tensorflow/compat_template.__init__.py --packages=tensorflow.python,tensorflow.dtensor.python.accelerator_util,tensorflow.dtensor.python.api,tensorflow.dtensor.python.config,tensorflow.dtensor.python.d_checkpoint,tensorflow.dtensor.python.d_variable,tensorflow.dtensor.python.input_util,tensorflow.dtensor.python.layout,tensorflow.dtensor.python.mesh_util,tensorflow.dtensor.python.tpu_util,tensorflow.dtensor.python.save_restore,tensorflow.lite.python.analyzer,tensorflow.lite.python.lite,tensorflow.lite.python.authoring.authoring,tensorflow.python.modules_with_exports --output_package=tensorflow._api.v2 --use_relative_imports=True --loading=default bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/tf_python_api_gen_v2.params')
# Configuration: 9f320c2ab265ab521267a555257ce138659ef24e739cde7fde73c7665f4cf5e4
# Execution platform: @local_execution_config_platform//:platform
2023-06-09 21:58:46.512000: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2023-06-09 21:58:46.546669: F ./tensorflow/core/framework/variant_op_registry.h:114] Check failed: existing == nullptr (0x2df3898 vs. nullptr)UnaryVariantDeviceCopy for direction: 1 and type_index: tensorflow::Tensor already registered
Target //tmp:tensorflow-lite-select-tf-ops failed to build
ERROR: /tensorflow_src/tensorflow/python/tools/BUILD:303:17 Middleman _middlemen/tensorflow_Spython_Stools_Sprint_Uselective_Uregistration_Uheader-runfiles failed: (Aborted): bash failed: error executing command (from target //tensorflow:tf_python_api_gen_v2) 
  (cd /root/.cache/bazel/_bazel_root/43801f1e35f242fb634ebbc6079cf6c5/execroot/org_tensorflow && \
  exec env - \
    DOCKER_HOST_CACHEBUSTER=1682977560680045781 \
    LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64 \
    PATH=/root/.cache/bazelisk/downloads/bazelbuild/bazel-6.1.0-linux-x86_64/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/android/sdk/cmdline-tools/latest/bin:/android/sdk/platform-tools:/android/ndk \
  /bin/bash -c 'bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2 --root_init_template=tensorflow/api_template.__init__.py --apidir=bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/_api/v2/ --apiname=tensorflow --apiversion=2  --compat_apiversion=1 --compat_apiversion=2  --compat_init_template=tensorflow/compat_template_v1.__init__.py --compat_init_template=tensorflow/compat_template.__init__.py --packages=tensorflow.python,tensorflow.dtensor.python.accelerator_util,tensorflow.dtensor.python.api,tensorflow.dtensor.python.config,tensorflow.dtensor.python.d_checkpoint,tensorflow.dtensor.python.d_variable,tensorflow.dtensor.python.input_util,tensorflow.dtensor.python.layout,tensorflow.dtensor.python.mesh_util,tensorflow.dtensor.python.tpu_util,tensorflow.dtensor.python.save_restore,tensorflow.lite.python.analyzer,tensorflow.lite.python.lite,tensorflow.lite.python.authoring.authoring,tensorflow.python.modules_with_exports --output_package=tensorflow._api.v2 --use_relative_imports=True --loading=default bazel-out/k8-opt-exec-50AE0418/bin/tensorflow/tf_python_api_gen_v2.params')
# Configuration: 9f320c2ab265ab521267a555257ce138659ef24e739cde7fde73c7665f4cf5e4
# Execution platform: @local_execution_config_platform//:platform

Standalone code to reproduce the issue

Contents of the .tf_configure.bazelrc:

build --action_env PYTHON_BIN_PATH="/usr/bin/python3"
build --action_env PYTHON_LIB_PATH="/usr/local/lib/python3.11/dist-packages"
build --python_path="/usr/bin/python3"
build:opt --copt=n
build:opt --host_copt=n
build --action_env ANDROID_NDK_HOME="/android/ndk"
build --action_env ANDROID_NDK_API_LEVEL="21"
build --action_env ANDROID_BUILD_TOOLS_VERSION="34.0.0"
build --action_env ANDROID_SDK_API_LEVEL="29"
build --action_env ANDROID_SDK_HOME="/android/sdk"
test --test_size_filters=small,medium
test:v1 --test_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-gpu,-oss_serial
test:v1 --build_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-gpu
test:v2 --test_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-gpu,-oss_serial,-v1only
test:v2 --build_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-gpu,-v1only

Relevant log output

No response

@google-ml-butler google-ml-butler bot added the type:bug Bug label Jun 10, 2023
@pjpratik pjpratik added comp:lite TF Lite related issues TF 2.13 For issues related to Tensorflow 2.13 labels Jun 14, 2023
@pjpratik pjpratik assigned pkgoogle and unassigned pjpratik Jun 16, 2023
@pkgoogle
Copy link

Hi @dachshund-ncu, which way are you building? With Docker/ w/o Docker? Please provide exact steps so that we can reproduce your issue. This includes commands prior to docker commands, docker commands (if applicable), commands within the docker (if applicable).

@pkgoogle pkgoogle added the stat:awaiting response Status - Awaiting response from author label Jun 16, 2023
@dachshund-ncu
Copy link
Author

Hi @pkgoogle, the build steps are presented below:

Prepare docker envirnoment:

  1. Download a docker file from here.

  2. Edit the dockerfile:

    • change the lines:

      From

      FROM tensorflow/build:latest-python3.11
      ENV ANDROID_API_LEVEL 23
      ENV ANDROID_BUILD_TOOLS_VERSION 31.0.0
      

      To

      FROM tensorflow/build:2.13-python3.11
      ENV ANDROID_API_LEVEL 29
      ENV ANDROID_BUILD_TOOLS_VERSION 34.0.0
      
  3. Build docker envirnoment:

    docker build . -t tflite-builder -f tflite-android.Dockerfile
  4. Run docker:

    docker run -it -v $PWD:/host_dir tflite-builder bash

Inside docker envirnoment:

  1. Install android tools:

    sdkmanager "build-tools;${ANDROID_BUILD_TOOLS_VERSION}"
    sdkmanager "platform-tools"
    sdkmanager "platforms;android-${ANDROID_API_LEVEL}"
  2. Clone tensorflow repository

    git clone https://github.com/tensorflow/tensorflow.git
  3. Change working directory to the tensorflow repo

    cd tensorflow
  4. Checkout to the 2.13 release tag:

    git checkout r2.13
  5. Add one line to the .bazelrc file:

    echo -n "build --config=monolithic" >> .bazelrc
  6. Configure:

    ./configure
    • Inside the configure:

      Please specify the location of python. [Default is /usr/bin/python3]
      
      /usr/bin/python3
      
      Found possible Python library paths:
      /usr/lib/python3/dist-packages
      /usr/local/lib/python3.11/dist-packages
      Please input the desired Python library path to use.  Default is [/usr/lib/python3/dist-packages]
      
      /usr/lib/python3/dist-packages
      
      Do you wish to build TensorFlow with ROCm support? [y/N]:
      
      n
      
      Do you wish to build TensorFlow with CUDA support? [y/N]:
      
      n
      
      Do you wish to download a fresh release of clang? (Experimental) [y/N]
      
      n
      
      Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -Wno-sign-compare]:
      
      < no answer here, just hit ENTER  >
      
      Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: 
      
      y
      
  7. Contents of the .tf_configure.bazelrc:

    build --action_env PYTHON_BIN_PATH="/usr/bin/python3"
    build --action_env PYTHON_LIB_PATH="/usr/lib/python3/dist-packages"
    build --python_path="/usr/bin/python3"
    build:opt --copt=-Wno-sign-compare
    build:opt --host_copt=-Wno-sign-compare
    build --action_env ANDROID_NDK_HOME="/android/ndk"
    build --action_env ANDROID_NDK_API_LEVEL="21"
    build --action_env ANDROID_BUILD_TOOLS_VERSION="34.0.0"
    build --action_env ANDROID_SDK_API_LEVEL="29"
    build --action_env ANDROID_SDK_HOME="/android/sdk"
    test --flaky_test_attempts=3
    test --test_size_filters=small,medium
    test:v1 --test_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-gpu,-oss_serial
    test:v1 --build_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-gpu
    test:v2 --test_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-gpu,-oss_serial,-v1only
    test:v2 --build_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-gpu,-v1only
    
  8. Build command

    bash tensorflow/lite/tools/build_aar.sh --input_models=/host_dir/left.tflite,/host_dir/right.tflite --target_archs=arm64-v8a

    Note, that /host_dir/left.tflite and /host_dir/right.tflite are the tflite models, placed in the docker /host_dir directory.

  9. Output message

    +++ dirname tensorflow/lite/tools/build_aar.sh
    ++ cd tensorflow/lite/tools
    ++ pwd
    + SCRIPT_DIR=/tensorflow/tensorflow/lite/tools
    ++ cd /tensorflow/tensorflow/lite/tools/../../../
    ++ pwd
    + ROOT_DIR=/tensorflow
    + TARGET_ARCHS=x86,x86_64,arm64-v8a,armeabi-v7a
    + '[' '!' -z ']'
    + '[' 2 -gt 4 ']'
    + for i in "$@"
    + case $i in
    + FLAG_MODELS=/host_dir/left.tflite,/host_dir/right.tflite
    + shift
    + for i in "$@"
    + case $i in
    + TARGET_ARCHS=arm64-v8a
    + shift
    + cd /tensorflow
    + '[' '!' -f /tensorflow/.tf_configure.bazelrc ']'
    + grep -q ANDROID_SDK_HOME /tensorflow/.tf_configure.bazelrc
    + '[' -z /host_dir/left.tflite,/host_dir/right.tflite ']'
    + TMP_DIR=/tensorflow/tmp/
    + rm -rf /tensorflow/tmp/
    + mkdir -p /tensorflow/tmp/
    + MODEL_NAMES=
    ++ echo /host_dir/left.tflite,/host_dir/right.tflite
    ++ sed 's/,/ /g'
    + for model in $(echo ${FLAG_MODELS} | sed "s/,/ /g")
    + cp /host_dir/left.tflite /tensorflow/tmp/
    ++ basename /host_dir/left.tflite
    + MODEL_NAMES=,left.tflite
    + for model in $(echo ${FLAG_MODELS} | sed "s/,/ /g")
    + cp /host_dir/right.tflite /tensorflow/tmp/
    ++ basename /host_dir/right.tflite
    + MODEL_NAMES=,left.tflite,right.tflite
    + TFLITE_OPS_SRCS=
    ++ echo
    ++ sed 's/,/ /g'
    + generate_tflite_aar
    + pushd /tensorflow/tmp/
    + message=('load("//tensorflow/lite:build_def.bzl", "tflite_custom_android_library")' 'load("//tensorflow/lite/java:aar_with_jni.bzl", "aar_with_jni")' '' 'tflite_custom_android_library(' '    name = "custom_tensorflowlite",')
    + message+=('    '$(generate_list_field "models" $MODEL_NAMES))
    ++ generate_list_field models ,left.tflite,right.tflite
    ++ local name=models
    ++ local list_string=,left.tflite,right.tflite
    ++ list=(${list_string//,/ })
    ++ local list
    ++ message=("$name=[")
    ++ local message
    ++ for item in "${list[@]}"
    ++ message+=("\"$item\",")
    ++ for item in "${list[@]}"
    ++ message+=("\"$item\",")
    ++ message+=('],')
    ++ printf %s 'models=[' '"left.tflite",' '"right.tflite",' '],'
    + message+=('    '$(generate_list_field "srcs" $TFLITE_OPS_SRCS))
    ++ generate_list_field srcs
    ++ local name=srcs
    ++ local list_string=
    ++ list=(${list_string//,/ })
    ++ local list
    ++ message=("$name=[")
    ++ local message
    ++ message+=('],')
    ++ printf %s 'srcs=[' '],'
    + message+=('    '$(generate_list_field "deps" $FLAG_TFLITE_OPS_DEPS))
    ++ generate_list_field deps
    ++ local name=deps
    ++ local list_string=
    ++ list=(${list_string//,/ })
    ++ local list
    ++ message=("$name=[")
    ++ local message
    ++ message+=('],')
    ++ printf %s 'deps=[' '],'
    + message+=(')' '' 'aar_with_jni(' '    name = "tensorflow-lite",' '    android_library = ":custom_tensorflowlite",' ')' '')
    + printf '%s\n' 'load("//tensorflow/lite:build_def.bzl", "tflite_custom_android_library")' 'load("//tensorflow/lite/java:aar_with_jni.bzl", "aar_with_jni")' '' 'tflite_custom_android_library(' '    name = "custom_tensorflowlite",' '    models=["left.tflite","right.tflite",],' '    srcs=[],' '    deps=[],' ')' '' 'aar_with_jni(' '    name = "tensorflow-lite",' '    android_library = ":custom_tensorflowlite",' ')' ''
    + popd
    + bazel build -c opt --cxxopt=--std=c++17 --fat_apk_cpu=arm64-v8a --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder --define=xnn_enable_arm_fp16=false --host_crosstool_top=@bazel_tools//tools/cpp:toolchain //tmp:tensorflow-lite
    Extracting Bazel installation...
    Starting local Bazel server and connecting to it...
    INFO: Options provided by the client:
    Inherited 'common' options: --isatty=1 --terminal_columns=126
    INFO: Reading rc options for 'build' from /tensorflow/.bazelrc:
    Inherited 'common' options: --experimental_repo_remote_exec
    INFO: Reading rc options for 'build' from /etc/bazel.bazelrc:
    'build' options: --action_env=DOCKER_CACHEBUSTER=1682977560589058360 --host_action_env=DOCKER_HOST_CACHEBUSTER=1682977560680045781
    INFO: Reading rc options for 'build' from /tensorflow/.bazelrc:
    'build' options: --define framework_shared_object=true --define tsl_protobuf_header_only=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --enable_platform_specific_config --define=with_xla_support=true --config=short_logs --config=v2 --define=no_aws_support=true --define=no_hdfs_support=true --experimental_cc_shared_library --experimental_link_static_libraries_once=false --incompatible_enforce_config_setting_visibility
    INFO: Reading rc options for 'build' from /tensorflow/.tf_configure.bazelrc:
    'build' options: --action_env PYTHON_BIN_PATH=/usr/bin/python3 --action_env PYTHON_LIB_PATH=/usr/lib/python3/dist-packages --python_path=/usr/bin/python3 --action_env ANDROID_NDK_HOME=/android/ndk --action_env ANDROID_NDK_API_LEVEL=21 --action_env ANDROID_BUILD_TOOLS_VERSION=34.0.0 --action_env ANDROID_SDK_API_LEVEL=29 --action_env ANDROID_SDK_HOME=/android/sdk
    INFO: Reading rc options for 'build' from /tensorflow/.bazelrc:
    'build' options: --deleted_packages=tensorflow/compiler/mlir/tfrt,tensorflow/compiler/mlir/tfrt/benchmarks,tensorflow/compiler/mlir/tfrt/jit/python_binding,tensorflow/compiler/mlir/tfrt/jit/transforms,tensorflow/compiler/mlir/tfrt/python_tests,tensorflow/compiler/mlir/tfrt/tests,tensorflow/compiler/mlir/tfrt/tests/ir,tensorflow/compiler/mlir/tfrt/tests/analysis,tensorflow/compiler/mlir/tfrt/tests/jit,tensorflow/compiler/mlir/tfrt/tests/lhlo_to_tfrt,tensorflow/compiler/mlir/tfrt/tests/lhlo_to_jitrt,tensorflow/compiler/mlir/tfrt/tests/tf_to_corert,tensorflow/compiler/mlir/tfrt/tests/tf_to_tfrt_data,tensorflow/compiler/mlir/tfrt/tests/saved_model,tensorflow/compiler/mlir/tfrt/transforms/lhlo_gpu_to_tfrt_gpu,tensorflow/core/runtime_fallback,tensorflow/core/runtime_fallback/conversion,tensorflow/core/runtime_fallback/kernel,tensorflow/core/runtime_fallback/opdefs,tensorflow/core/runtime_fallback/runtime,tensorflow/core/runtime_fallback/util,tensorflow/core/tfrt/eager,tensorflow/core/tfrt/eager/backends/cpu,tensorflow/core/tfrt/eager/backends/gpu,tensorflow/core/tfrt/eager/core_runtime,tensorflow/core/tfrt/eager/cpp_tests/core_runtime,tensorflow/core/tfrt/gpu,tensorflow/core/tfrt/run_handler_thread_pool,tensorflow/core/tfrt/runtime,tensorflow/core/tfrt/saved_model,tensorflow/core/tfrt/graph_executor,tensorflow/core/tfrt/saved_model/tests,tensorflow/core/tfrt/tpu,tensorflow/core/tfrt/utils,tensorflow/core/tfrt/utils/debug --config=monolithic
    INFO: Found applicable config definition build:short_logs in file /tensorflow/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
    INFO: Found applicable config definition build:v2 in file /tensorflow/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
    INFO: Found applicable config definition build:monolithic in file /tensorflow/.bazelrc: --define framework_shared_object=false --define tsl_protobuf_header_only=false --experimental_link_static_libraries_once=false
    INFO: Found applicable config definition build:linux in file /tensorflow/.bazelrc: --define=build_with_onednn_v2=true --host_copt=-w --copt=-Wno-all --copt=-Wno-extra --copt=-Wno-deprecated --copt=-Wno-deprecated-declarations --copt=-Wno-ignored-attributes --copt=-Wno-array-bounds --copt=-Wunused-result --copt=-Werror=unused-result --copt=-Wswitch --copt=-Werror=switch --copt=-Wno-error=unused-but-set-variable --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --config=dynamic_kernels --experimental_guard_against_concurrent_changes
    INFO: Found applicable config definition build:dynamic_kernels in file /tensorflow/.bazelrc: --define=dynamic_loaded_kernels=true --copt=-DAUTOLOAD_DYNAMIC_KERNELS
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/tensorflow/runtime/archive/7d879c8b161085a4374ea481b93a52adb19c0529.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/llvm/llvm-project/archive/dc275fd03254d67d29cc70a5a0569acf24d2280d.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/benchmark/archive/f7547e29ccaed7b64ef4f7495ecfff1c9f6f3d03.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    WARNING: Download from https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/081771d4a0e9d7d3aa0eed2ef389fa4700dfb23e.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/abseil/abseil-cpp/archive/b971ac5250ea8de900eae9f95e06548d14cd95fe.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/XNNPACK/archive/b9d4073a6913891ce9cbd8965c8d506075d2a45a.zip failed: class java.io.FileNotFoundException GET returned 404 Not Found
    INFO: Analyzed target //tmp:tensorflow-lite (159 packages loaded, 11634 targets configured).
    INFO: Found 1 target...
    Target //tmp:tensorflow-lite up-to-date:
    bazel-bin/tmp/tensorflow-lite.aar
    INFO: Elapsed time: 174.543s, Critical Path: 39.53s
    INFO: 1354 processes: 269 internal, 1085 local.
    INFO: Build completed successfully, 1354 total actions
    + OUT_FILES=' bazel-bin/tmp/tensorflow-lite.aar'
    + bazel build -c opt --config=monolithic //tensorflow/lite/tools:list_flex_ops_no_kernel_main
    WARNING: The following configs were expanded more than once: [monolithic]. For repeatable flags, repeats are counted twice and may lead to unexpected behavior.
    INFO: Options provided by the client:
    Inherited 'common' options: --isatty=1 --terminal_columns=126
    INFO: Reading rc options for 'build' from /tensorflow/.bazelrc:
    Inherited 'common' options: --experimental_repo_remote_exec
    INFO: Reading rc options for 'build' from /etc/bazel.bazelrc:
    'build' options: --action_env=DOCKER_CACHEBUSTER=1682977560589058360 --host_action_env=DOCKER_HOST_CACHEBUSTER=1682977560680045781
    INFO: Reading rc options for 'build' from /tensorflow/.bazelrc:
    'build' options: --define framework_shared_object=true --define tsl_protobuf_header_only=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --enable_platform_specific_config --define=with_xla_support=true --config=short_logs --config=v2 --define=no_aws_support=true --define=no_hdfs_support=true --experimental_cc_shared_library --experimental_link_static_libraries_once=false --incompatible_enforce_config_setting_visibility
    INFO: Reading rc options for 'build' from /tensorflow/.tf_configure.bazelrc:
    'build' options: --action_env PYTHON_BIN_PATH=/usr/bin/python3 --action_env PYTHON_LIB_PATH=/usr/lib/python3/dist-packages --python_path=/usr/bin/python3 --action_env ANDROID_NDK_HOME=/android/ndk --action_env ANDROID_NDK_API_LEVEL=21 --action_env ANDROID_BUILD_TOOLS_VERSION=34.0.0 --action_env ANDROID_SDK_API_LEVEL=29 --action_env ANDROID_SDK_HOME=/android/sdk
    INFO: Reading rc options for 'build' from /tensorflow/.bazelrc:
    'build' options: --deleted_packages=tensorflow/compiler/mlir/tfrt,tensorflow/compiler/mlir/tfrt/benchmarks,tensorflow/compiler/mlir/tfrt/jit/python_binding,tensorflow/compiler/mlir/tfrt/jit/transforms,tensorflow/compiler/mlir/tfrt/python_tests,tensorflow/compiler/mlir/tfrt/tests,tensorflow/compiler/mlir/tfrt/tests/ir,tensorflow/compiler/mlir/tfrt/tests/analysis,tensorflow/compiler/mlir/tfrt/tests/jit,tensorflow/compiler/mlir/tfrt/tests/lhlo_to_tfrt,tensorflow/compiler/mlir/tfrt/tests/lhlo_to_jitrt,tensorflow/compiler/mlir/tfrt/tests/tf_to_corert,tensorflow/compiler/mlir/tfrt/tests/tf_to_tfrt_data,tensorflow/compiler/mlir/tfrt/tests/saved_model,tensorflow/compiler/mlir/tfrt/transforms/lhlo_gpu_to_tfrt_gpu,tensorflow/core/runtime_fallback,tensorflow/core/runtime_fallback/conversion,tensorflow/core/runtime_fallback/kernel,tensorflow/core/runtime_fallback/opdefs,tensorflow/core/runtime_fallback/runtime,tensorflow/core/runtime_fallback/util,tensorflow/core/tfrt/eager,tensorflow/core/tfrt/eager/backends/cpu,tensorflow/core/tfrt/eager/backends/gpu,tensorflow/core/tfrt/eager/core_runtime,tensorflow/core/tfrt/eager/cpp_tests/core_runtime,tensorflow/core/tfrt/gpu,tensorflow/core/tfrt/run_handler_thread_pool,tensorflow/core/tfrt/runtime,tensorflow/core/tfrt/saved_model,tensorflow/core/tfrt/graph_executor,tensorflow/core/tfrt/saved_model/tests,tensorflow/core/tfrt/tpu,tensorflow/core/tfrt/utils,tensorflow/core/tfrt/utils/debug --config=monolithic
    INFO: Found applicable config definition build:short_logs in file /tensorflow/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
    INFO: Found applicable config definition build:v2 in file /tensorflow/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
    INFO: Found applicable config definition build:monolithic in file /tensorflow/.bazelrc: --define framework_shared_object=false --define tsl_protobuf_header_only=false --experimental_link_static_libraries_once=false
    INFO: Found applicable config definition build:monolithic in file /tensorflow/.bazelrc: --define framework_shared_object=false --define tsl_protobuf_header_only=false --experimental_link_static_libraries_once=false
    INFO: Found applicable config definition build:linux in file /tensorflow/.bazelrc: --define=build_with_onednn_v2=true --host_copt=-w --copt=-Wno-all --copt=-Wno-extra --copt=-Wno-deprecated --copt=-Wno-deprecated-declarations --copt=-Wno-ignored-attributes --copt=-Wno-array-bounds --copt=-Wunused-result --copt=-Werror=unused-result --copt=-Wswitch --copt=-Werror=switch --copt=-Wno-error=unused-but-set-variable --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --config=dynamic_kernels --experimental_guard_against_concurrent_changes
    INFO: Found applicable config definition build:dynamic_kernels in file /tensorflow/.bazelrc: --define=dynamic_loaded_kernels=true --copt=-DAUTOLOAD_DYNAMIC_KERNELS
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/llvm/llvm-project/archive/dc275fd03254d67d29cc70a5a0569acf24d2280d.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/tensorflow/runtime/archive/7d879c8b161085a4374ea481b93a52adb19c0529.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/benchmark/archive/f7547e29ccaed7b64ef4f7495ecfff1c9f6f3d03.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    WARNING: Download from https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/081771d4a0e9d7d3aa0eed2ef389fa4700dfb23e.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    INFO: Build options --cxxopt, --define, and --fat_apk_cpu have changed, discarding analysis cache.
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/abseil/abseil-cpp/archive/b971ac5250ea8de900eae9f95e06548d14cd95fe.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    INFO: Analyzed target //tensorflow/lite/tools:list_flex_ops_no_kernel_main (7 packages loaded, 1085 targets configured).
    INFO: Found 1 target...
    Target //tensorflow/lite/tools:list_flex_ops_no_kernel_main up-to-date:
    bazel-bin/tensorflow/lite/tools/list_flex_ops_no_kernel_main
    INFO: Elapsed time: 13.111s, Critical Path: 10.67s
    INFO: 173 processes: 82 internal, 91 local.
    INFO: Build completed successfully, 173 total actions
    + bazel-bin/tensorflow/lite/tools/list_flex_ops_no_kernel_main --graphs=/host_dir/left.tflite,/host_dir/right.tflite
    ++ cat /tensorflow/tmp//ops_list.txt
    + [[ ["Add","BroadcastGradientArgs","ReluGrad","Restore","Save"] != \[\] ]]
    + generate_flex_aar
    + pushd /tensorflow/tmp/
    /tensorflow/tmp /tensorflow
    + message=('load("//tensorflow/lite/delegates/flex:build_def.bzl", "tflite_flex_android_library")' 'load("//tensorflow/lite/java:aar_with_jni.bzl", "aar_with_jni")' '' 'tflite_flex_android_library(' '    name = "custom_tensorflowlite_flex",')
    + message+=('    '$(generate_list_field "models" $MODEL_NAMES))
    ++ generate_list_field models ,left.tflite,right.tflite
    ++ local name=models
    ++ local list_string=,left.tflite,right.tflite
    ++ list=(${list_string//,/ })
    ++ local list
    ++ message=("$name=[")
    ++ local message
    ++ for item in "${list[@]}"
    ++ message+=("\"$item\",")
    ++ for item in "${list[@]}"
    ++ message+=("\"$item\",")
    ++ message+=('],')
    ++ printf %s 'models=[' '"left.tflite",' '"right.tflite",' '],'
    + message+=(')' '' 'aar_with_jni(' '    name = "tensorflow-lite-select-tf-ops",' '    android_library = ":custom_tensorflowlite_flex",' ')')
    + printf '%s\n' 'load("//tensorflow/lite/delegates/flex:build_def.bzl", "tflite_flex_android_library")' 'load("//tensorflow/lite/java:aar_with_jni.bzl", "aar_with_jni")' '' 'tflite_flex_android_library(' '    name = "custom_tensorflowlite_flex",' '    models=["left.tflite","right.tflite",],' ')' '' 'aar_with_jni(' '    name = "tensorflow-lite-select-tf-ops",' '    android_library = ":custom_tensorflowlite_flex",' ')'
    + cp /tensorflow/tensorflow/lite/java/AndroidManifest.xml .
    + cp /tensorflow/tensorflow/lite/java/proguard.flags .
    + popd
    /tensorflow
    + bazel build -c opt --cxxopt=--std=c++17 --fat_apk_cpu=arm64-v8a --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder --define=xnn_enable_arm_fp16=false --host_crosstool_top=@bazel_tools//tools/cpp:toolchain //tmp:tensorflow-lite-select-tf-ops
    INFO: Options provided by the client:
    Inherited 'common' options: --isatty=1 --terminal_columns=126
    INFO: Reading rc options for 'build' from /tensorflow/.bazelrc:
    Inherited 'common' options: --experimental_repo_remote_exec
    INFO: Reading rc options for 'build' from /etc/bazel.bazelrc:
    'build' options: --action_env=DOCKER_CACHEBUSTER=1682977560589058360 --host_action_env=DOCKER_HOST_CACHEBUSTER=1682977560680045781
    INFO: Reading rc options for 'build' from /tensorflow/.bazelrc:
    'build' options: --define framework_shared_object=true --define tsl_protobuf_header_only=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --enable_platform_specific_config --define=with_xla_support=true --config=short_logs --config=v2 --define=no_aws_support=true --define=no_hdfs_support=true --experimental_cc_shared_library --experimental_link_static_libraries_once=false --incompatible_enforce_config_setting_visibility
    INFO: Reading rc options for 'build' from /tensorflow/.tf_configure.bazelrc:
    'build' options: --action_env PYTHON_BIN_PATH=/usr/bin/python3 --action_env PYTHON_LIB_PATH=/usr/lib/python3/dist-packages --python_path=/usr/bin/python3 --action_env ANDROID_NDK_HOME=/android/ndk --action_env ANDROID_NDK_API_LEVEL=21 --action_env ANDROID_BUILD_TOOLS_VERSION=34.0.0 --action_env ANDROID_SDK_API_LEVEL=29 --action_env ANDROID_SDK_HOME=/android/sdk
    INFO: Reading rc options for 'build' from /tensorflow/.bazelrc:
    'build' options: --deleted_packages=tensorflow/compiler/mlir/tfrt,tensorflow/compiler/mlir/tfrt/benchmarks,tensorflow/compiler/mlir/tfrt/jit/python_binding,tensorflow/compiler/mlir/tfrt/jit/transforms,tensorflow/compiler/mlir/tfrt/python_tests,tensorflow/compiler/mlir/tfrt/tests,tensorflow/compiler/mlir/tfrt/tests/ir,tensorflow/compiler/mlir/tfrt/tests/analysis,tensorflow/compiler/mlir/tfrt/tests/jit,tensorflow/compiler/mlir/tfrt/tests/lhlo_to_tfrt,tensorflow/compiler/mlir/tfrt/tests/lhlo_to_jitrt,tensorflow/compiler/mlir/tfrt/tests/tf_to_corert,tensorflow/compiler/mlir/tfrt/tests/tf_to_tfrt_data,tensorflow/compiler/mlir/tfrt/tests/saved_model,tensorflow/compiler/mlir/tfrt/transforms/lhlo_gpu_to_tfrt_gpu,tensorflow/core/runtime_fallback,tensorflow/core/runtime_fallback/conversion,tensorflow/core/runtime_fallback/kernel,tensorflow/core/runtime_fallback/opdefs,tensorflow/core/runtime_fallback/runtime,tensorflow/core/runtime_fallback/util,tensorflow/core/tfrt/eager,tensorflow/core/tfrt/eager/backends/cpu,tensorflow/core/tfrt/eager/backends/gpu,tensorflow/core/tfrt/eager/core_runtime,tensorflow/core/tfrt/eager/cpp_tests/core_runtime,tensorflow/core/tfrt/gpu,tensorflow/core/tfrt/run_handler_thread_pool,tensorflow/core/tfrt/runtime,tensorflow/core/tfrt/saved_model,tensorflow/core/tfrt/graph_executor,tensorflow/core/tfrt/saved_model/tests,tensorflow/core/tfrt/tpu,tensorflow/core/tfrt/utils,tensorflow/core/tfrt/utils/debug --config=monolithic
    INFO: Found applicable config definition build:short_logs in file /tensorflow/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
    INFO: Found applicable config definition build:v2 in file /tensorflow/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
    INFO: Found applicable config definition build:monolithic in file /tensorflow/.bazelrc: --define framework_shared_object=false --define tsl_protobuf_header_only=false --experimental_link_static_libraries_once=false
    INFO: Found applicable config definition build:linux in file /tensorflow/.bazelrc: --define=build_with_onednn_v2=true --host_copt=-w --copt=-Wno-all --copt=-Wno-extra --copt=-Wno-deprecated --copt=-Wno-deprecated-declarations --copt=-Wno-ignored-attributes --copt=-Wno-array-bounds --copt=-Wunused-result --copt=-Werror=unused-result --copt=-Wswitch --copt=-Werror=switch --copt=-Wno-error=unused-but-set-variable --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --config=dynamic_kernels --experimental_guard_against_concurrent_changes
    INFO: Found applicable config definition build:dynamic_kernels in file /tensorflow/.bazelrc: --define=dynamic_loaded_kernels=true --copt=-DAUTOLOAD_DYNAMIC_KERNELS
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/llvm/llvm-project/archive/dc275fd03254d67d29cc70a5a0569acf24d2280d.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/tensorflow/runtime/archive/7d879c8b161085a4374ea481b93a52adb19c0529.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/benchmark/archive/f7547e29ccaed7b64ef4f7495ecfff1c9f6f3d03.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    INFO: Build options --cxxopt, --define, and --fat_apk_cpu have changed, discarding analysis cache.
    WARNING: Download from https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/081771d4a0e9d7d3aa0eed2ef389fa4700dfb23e.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/abseil/abseil-cpp/archive/b971ac5250ea8de900eae9f95e06548d14cd95fe.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/XNNPACK/archive/b9d4073a6913891ce9cbd8965c8d506075d2a45a.zip failed: class java.io.FileNotFoundException GET returned 404 Not Found
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/boringssl/archive/c00d7ca810e93780bd0c8ee4eea28f4f2ea4bcdc.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/pybind/pybind11_abseil/archive/2c4932ed6f6204f1656e245838f4f5eae69d2e29.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
    WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/openxla/stablehlo/archive/43d81c6883ade82052920bd367c61f9e52f09954.zip failed: class java.io.FileNotFoundException GET returned 404 Not Found
    INFO: Analyzed target //tmp:tensorflow-lite-select-tf-ops (462 packages loaded, 45802 targets configured).
    INFO: Found 1 target...
    ERROR: /tensorflow/tensorflow/BUILD:1646:19: Action tensorflow/_api/v2/v2.py [for host] failed: (Aborted): bash failed: error executing command /bin/bash -c ... (remaining 1 argument skipped)
    2023-06-19 07:29:06.906099: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
    2023-06-19 07:29:06.944621: F ./tensorflow/core/framework/variant_op_registry.h:114] Check failed: existing == nullptr (0x2bc5608 vs. nullptr)UnaryVariantDeviceCopy for direction: 1 and type_index: tensorflow::Tensor already registered
    Target //tmp:tensorflow-lite-select-tf-ops failed to build
    Use --verbose_failures to see the command lines of failed build steps.
    ERROR: /tensorflow/tensorflow/python/tools/BUILD:284:10 Middleman _middlemen/tensorflow_Spython_Stools_Sprint_Uselective_Uregistration_Uheader-runfiles failed: (Aborted): bash failed: error executing command /bin/bash -c ... (remaining 1 argument skipped)
    INFO: Elapsed time: 4872.123s, Critical Path: 566.63s
    INFO: 16874 processes: 1454 internal, 15420 local.
    FAILED: Build did NOT complete successfully
    

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label Jun 19, 2023
@pkgoogle
Copy link

Hi @dachshund-ncu, Thanks for providing detailed reproducing steps, this helps a lot! Following your instructions with some modifications I was able to build the tflite aar, however I see you are using a command that is dependent your tflite models. This will probably allow you to continue with a bigger aar file, I can't reproduce your issue with your specific tflite model as I don't have access to those models.

To build the "fatter" aar, install your android tools as stated in the documentation:

sdkmanager \
  "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
  "platform-tools" \
  "platforms;android-${ANDROID_API_LEVEL}"

Your version is probably fine if you do it line by line, but when I pasted it all it seemed to say No to the license.

When building the aar, just for arm64-v8a:

bazel build -c opt --fat_apk_cpu=arm64-v8a --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder

Let me know if this works for you. Please close if this is sufficient for you.

If you need help w/ the specific model cases, please upload the additional models or at least a minimally reproducible toy model that reproduces the issue.

@pkgoogle pkgoogle added the stat:awaiting response Status - Awaiting response from author label Jun 20, 2023
@dachshund-ncu
Copy link
Author
dachshund-ncu commented Jun 22, 2023

Hello, thank for your response!
Unfortunately, the provided solution produces message:

Your request is correct, but requested an empty set of targets. Nothing will be built

Unfortunately I cannot share the input models, but I asked for some dummy models that utilize the same operatos. It results in the same error as stated above.
You can find it attached to this message

Thank you for support!

model_small.tflite.zip

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label Jun 22, 2023
@pkgoogle
Copy link

Hi @dachshund-ncu, can you provide me the exact steps that led to the above error message? I am unsure what you mean by "the provided solution". i.e. I'm trying to answer did it fail on the build step? were you able to build the aar successfully or did it fail after you integrated it? I'll try to build the aar w/ your dummy models.

@pkgoogle pkgoogle added stat:awaiting response Status - Awaiting response from author and removed stat:awaiting response Status - Awaiting response from author labels Jun 22, 2023
@pkgoogle
Copy link

Hi @dachshund-ncu, with your toy model I was able to build fine if I don't include this step:

echo -n "build --config=monolithic" >> .bazelrc

do you absolutely need this configuration?

@pkgoogle pkgoogle added the stat:awaiting response Status - Awaiting response from author label Jun 22, 2023
@dachshund-ncu
Copy link
Author
dachshund-ncu commented Jun 23, 2023

Hi @dachshund-ncu, can you provide me the exact steps that led to the above error message? I am unsure what you mean by "the provided solution". i.e. I'm trying to answer did it fail on the build step? were you able to build the aar successfully or did it fail after you integrated it? I'll try to build the aar w/ your dummy models.

Steps are exactly the same, as before, but instead of using build_aar.sh script I executed
the build command, provided few messages prior:

bazel build -c opt --fat_apk_cpu=arm64-v8a --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder

It results in output:

INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=120
INFO: Reading rc options for 'build' from /tensorflow/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'build' from /etc/bazel.bazelrc:
  'build' options: --action_env=DOCKER_CACHEBUSTER=1682977560589058360 --host_action_env=DOCKER_HOST_CACHEBUSTER=1682977560680045781
INFO: Reading rc options for 'build' from /tensorflow/.bazelrc:
  'build' options: --define framework_shared_object=true --define tsl_protobuf_header_only=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --features=-force_no_whole_archive --enable_platform_specific_config --define=with_xla_support=true --config=short_logs --config=v2 --define=no_aws_support=true --define=no_hdfs_support=true --experimental_cc_shared_library --experimental_link_static_libraries_once=false --incompatible_enforce_config_setting_visibility
INFO: Reading rc options for 'build' from /tensorflow/.tf_configure.bazelrc:
  'build' options: --action_env PYTHON_BIN_PATH=/usr/bin/python3 --action_env PYTHON_LIB_PATH=/usr/lib/python3/dist-packages --python_path=/usr/bin/python3 --action_env ANDROID_NDK_HOME=/android/ndk --action_env ANDROID_NDK_API_LEVEL=21 --action_env ANDROID_BUILD_TOOLS_VERSION=34.0.0 --action_env ANDROID_SDK_API_LEVEL=29 --action_env ANDROID_SDK_HOME=/android/sdk
INFO: Reading rc options for 'build' from /tensorflow/.bazelrc:
  'build' options: --deleted_packages=tensorflow/core/tfrt/stubs,tensorflow/compiler/mlir/tfrt,tensorflow/compiler/mlir/tfrt/benchmarks,tensorflow/compiler/mlir/tfrt/ir,tensorflow/compiler/mlir/tfrt/ir/mlrt,tensorflow/compiler/mlir/tfrt/jit/python_binding,tensorflow/compiler/mlir/tfrt/jit/transforms,tensorflow/compiler/mlir/tfrt/python_tests,tensorflow/compiler/mlir/tfrt/tests,tensorflow/compiler/mlir/tfrt/tests/mlrt,tensorflow/compiler/mlir/tfrt/tests/ir,tensorflow/compiler/mlir/tfrt/tests/analysis,tensorflow/compiler/mlir/tfrt/tests/jit,tensorflow/compiler/mlir/tfrt/tests/lhlo_to_tfrt,tensorflow/compiler/mlir/tfrt/tests/lhlo_to_jitrt,tensorflow/compiler/mlir/tfrt/tests/tf_to_corert,tensorflow/compiler/mlir/tfrt/tests/tf_to_tfrt_data,tensorflow/compiler/mlir/tfrt/tests/saved_model,tensorflow/compiler/mlir/tfrt/transforms/lhlo_gpu_to_tfrt_gpu,tensorflow/compiler/mlir/tfrt/transforms/mlrt,tensorflow/core/runtime_fallback,tensorflow/core/runtime_fallback/conversion,tensorflow/core/runtime_fallback/kernel,tensorflow/core/runtime_fallback/opdefs,tensorflow/core/runtime_fallback/runtime,tensorflow/core/runtime_fallback/util,tensorflow/core/tfrt/mlrt,tensorflow/core/tfrt/mlrt/attribute,tensorflow/core/tfrt/mlrt/kernel,tensorflow/core/tfrt/mlrt/bytecode,tensorflow/core/tfrt/mlrt/interpreter,tensorflow/compiler/mlir/tfrt/translate/mlrt,tensorflow/compiler/mlir/tfrt/translate/mlrt/testdata,tensorflow/core/tfrt/gpu,tensorflow/core/tfrt/run_handler_thread_pool,tensorflow/core/tfrt/runtime,tensorflow/core/tfrt/saved_model,tensorflow/core/tfrt/graph_executor,tensorflow/core/tfrt/saved_model/tests,tensorflow/core/tfrt/tpu,tensorflow/core/tfrt/utils,tensorflow/core/tfrt/utils/debug,tensorflow/core/tfrt/saved_model/python,tensorflow/core/tfrt/graph_executor/python --config=monolithic
INFO: Found applicable config definition build:short_logs in file /tensorflow/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:v2 in file /tensorflow/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition build:monolithic in file /tensorflow/.bazelrc: --define framework_shared_object=false --define tsl_protobuf_header_only=false --experimental_link_static_libraries_once=false
INFO: Found applicable config definition build:linux in file /tensorflow/.bazelrc: --define=build_with_onednn_v2=true --host_copt=-w --copt=-Wno-all --copt=-Wno-extra --copt=-Wno-deprecated --copt=-Wno-deprecated-declarations --copt=-Wno-ignored-attributes --copt=-Wno-array-bounds --copt=-Wunused-result --copt=-Werror=unused-result --copt=-Wswitch --copt=-Werror=switch --copt=-Wno-error=unused-but-set-variable --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --config=dynamic_kernels --experimental_guard_against_concurrent_changes
INFO: Found applicable config definition build:dynamic_kernels in file /tensorflow/.bazelrc: --define=dynamic_loaded_kernels=true --copt=-DAUTOLOAD_DYNAMIC_KERNELS
WARNING: Usage: bazel build <options> <targets>.
Invoke `bazel help build` for full description of usage and options.
Your request is correct, but requested an empty set of targets. Nothing will be built.
INFO: Analyzed 0 targets (0 packages loaded, 0 targets configured).
INFO: Found 0 targets...
INFO: Elapsed time: 0.369s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action

And no .aar file is produced

Hi @dachshund-ncu, with your toy model I was able to build fine if I don't include this step:

echo -n "build --config=monolithic" >> .bazelrc

do you absolutely need this configuration?

Reason for adding --config=monolithic to the .bazelrc file is to avoid other error:

_ZN6google8protobuf8internal26fixed_address_empty_stringE" error

during running the android project.

This appeared to fix this issue for some other users (see here and here and here ), yet fails to build in my case.

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label Jun 23, 2023
@pkgoogle
Copy link

Hi @dachshund-ncu, there seems to be an issue with that command that doesn't output the aar... I was able to get the output if I made the aar really fat as in the documentation:

bazel build -c opt --fat_apk_cpu=x86,x86_64,arm64-v8a,armeabi-v7a \
  --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
  --define=android_dexmerger_tool=d8_dexmerger \
  --define=android_incremental_dexing_tool=d8_dexbuilder \
  //tensorflow/lite/java:tensorflow-lite

Can you try that and use that aar for now while I investigate the other part?

@pkgoogle pkgoogle added the stat:awaiting response Status - Awaiting response from author label Jun 23, 2023
@dachshund-ncu
Copy link
Author

Hi @pkgoogle, command provided from documentation:

bazel build -c opt --fat_apk_cpu=x86,x86_64,arm64-v8a,armeabi-v7a \
  --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
  --define=android_dexmerger_tool=d8_dexmerger \
  --define=android_incremental_dexing_tool=d8_dexbuilder \
  //tensorflow/lite/java:tensorflow-lite

produces only the tensorflow-lite.aar file, but not the tensorflow-lite-select-tf-ops.aar

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label Jun 29, 2023
@dachshund-ncu
Copy link
Author

Hi @pkgoogle I was wondering if my issue is still under consideration by you.

@pkgoogle
Copy link
pkgoogle commented Jul 7, 2023

Hi @dachshund-ncu, I'm still looking at it but was having an internal docker issue which I just resolved, I'll let you know when I have more information. Thanks.

@pkgoogle
Copy link
pkgoogle commented Jul 7, 2023

I tried not editing the dockerfile but I'm running into the same issue:

[17,843 / 18,487] [Prepa] action 'SolibSymlink _solib_k8/_U_S_Stensorflow_Spython_C_Upywrap_Utensorflow_Uinternal.so_Ucclib___UteERROR: /tensorflow/tensorflow/BUILD:1646:19: Action tensorflow/_api/v2/v2.py [for host] failed: (Aborted): bash failed: error executing command /bin/bash -c ... (remaining 1 argument skipped)
2023-07-07 21:45:31.166998: F ./tensorflow/core/framework/variant_op_registry.h:114] Check failed: existing == nullptr (0x1b5bdc8 vs. nullptr)UnaryVariantDeviceCopy for direction: 1 and type_index: tensorflow::Tensor already registered
Target //tmp:tensorflow-lite-select-tf-ops failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /tensorflow/tensorflow/python/tools/BUILD:284:10 Middleman _middlemen/tensorflow_Spython_Stools_Sprint_Uselective_Uregistration_Uheader-runfiles failed: (Aborted): bash failed: error executing command /bin/bash -c ... (remaining 1 argument skipped)
INFO: Elapsed time: 2219.284s, Critical Path: 349.98s
INFO: 16874 processes: 1454 internal, 15420 local.
FAILED: Build did NOT complete successfully

Seems like the combination of the workaround echo -n "build --config=monolithic" >> .bazelrc + your model is failing the build

Hi @terryheo, can you please take a look? Thanks.

@pkgoogle pkgoogle added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Jul 7, 2023
@lgessonimc1
Copy link

I have the same problem. Had to add the workaround for tensorflow 2.13.0 but them i have this build error.
I had previously built an .aar that worked in tensorflow 2.9.3, but I am being asked to update the dependencies.

@pkgoogle pkgoogle added the type:build/install Build and install issues label Jul 19, 2023
@pkgoogle
Copy link
pkgoogle commented Sep 8, 2023

Hi @dachshund-ncu, can you provide for me reproducible steps for the root cause of the issue?

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN6google8protobuf8internal26fixed_address_empty_stringE" referenced by "/data/app/~~PgTBlp4bIwZ8yl02UBjqqg==/com.inseye.core.test-yoruTyRORPvs5Ap3TE6dGw==/base.apk!/lib/x86_64/libtensorflowlite_flex_jni.so".

We shouldn't really rely on work-arounds long-term and it seems like we fixed the "official way" before so let's try to actually fix the root cause here.

@pkgoogle pkgoogle added stat:awaiting response Status - Awaiting response from author and removed stat:awaiting tensorflower Status - Awaiting response from tensorflower labels Sep 8, 2023
@dachshund-ncu
Copy link
Author
dachshund-ncu commented Sep 11, 2023

Dear @pkgoogle, I provide the steps to reproduce this bug below

Prepare docker envirnoment:

  1. Download a docker file from here.

  2. Edit the dockerfile:

    • change the lines:

      From

      FROM tensorflow/build:latest-python3.11
      ENV ANDROID_API_LEVEL 23
      ENV ANDROID_BUILD_TOOLS_VERSION 31.0.0
      

      To

      FROM tensorflow/build:2.13-python3.11
      ENV ANDROID_API_LEVEL 29
      ENV ANDROID_BUILD_TOOLS_VERSION 34.0.0
      
  3. Build docker envirnoment:

    docker build . -t tflite-builder -f tflite-android.Dockerfile
  4. Run docker:

    docker run -it -v $PWD:/host_dir tflite-builder bash

Inside docker envirnoment:

  1. Install android tools:

    sdkmanager "build-tools;${ANDROID_BUILD_TOOLS_VERSION}"
    sdkmanager "platform-tools"
    sdkmanager "platforms;android-${ANDROID_API_LEVEL}"
  2. Clone tensorflow repository

    git clone https://github.com/tensorflow/tensorflow.git
  3. Change working directory to the tensorflow repo

    cd tensorflow
  4. Checkout to the 2.13 release tag:

    git checkout r2.13
  5. Configure:

    ./configure
    • Inside the configure:

      Please specify the location of python. [Default is /usr/bin/python3]
      
      /usr/bin/python3
      
      Found possible Python library paths:
      /usr/lib/python3/dist-packages
      /usr/local/lib/python3.11/dist-packages
      Please input the desired Python library path to use.  Default is [/usr/lib/python3/dist-packages]
      
      /usr/lib/python3/dist-packages
      
      Do you wish to build TensorFlow with ROCm support? [y/N]:
      
      n
      
      Do you wish to build TensorFlow with CUDA support? [y/N]:
      
      n
      
      Do you wish to download a fresh release of clang? (Experimental) [y/N]
      
      n
      
      Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -Wno-sign-compare]:
      
      < no answer here, just hit ENTER  >
      
      Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: 
      
      y
      
  6. Build command

    bash tensorflow/lite/tools/build_aar.sh --input_models=/host_dir/left.tflite,/host_dir/right.tflite --target_archs=arm64-v8a

    Note, that /host_dir/left.tflite and /host_dir/right.tflite are the tflite models, placed in the docker /host_dir directory.

I also attach the dummy model that contains the operators used.

model_small.tflite.zip

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label Sep 11, 2023
@pkgoogle
Copy link

Hi @dachshund-ncu, I was able to integrate the aar's into my default empty Android project fine ("Hello Android!"). I'm not really using any functionality though so maybe that's why I'm not running into the issue... how are you integrating the aar's into your project? and how are you using that functionality that is causing the error?

@pkgoogle pkgoogle added the stat:awaiting response Status - Awaiting response from author label Sep 12, 2023
@github-actions
Copy link

This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.

@github-actions github-actions bot added the stale This label marks the issue/pr stale - to be closed automatically if no activity label Sep 20, 2023
@mszczuj
Copy link
mszczuj commented Sep 20, 2023

Hi @pkgoogle , the test is to run single inference through the network and then then the exception occurs

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN6google8protobuf8internal26fixed_address_empty_stringE" referenced by "/data/app/~~PgTBlp4bIwZ8yl02UBjqqg==/com.inseye.core.test-yoruTyRORPvs5Ap3TE6dGw==/base.apk!/lib/x86_64/libtensorflowlite_flex_jni.so".

@github-actions github-actions bot removed stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response Status - Awaiting response from author labels Sep 21, 2023
@pkgoogle
Copy link

Hi @mszczuj, there's still a lot of missing context, can you please show me the Android Studio code? a full project export from a toy version (that just loads and runs inference) would be the easiest to share.

@pkgoogle pkgoogle added the stat:awaiting response Status - Awaiting response from author label Sep 21, 2023
@dachshund-ncu
Copy link
Author

Dear @pkgoogle, you'll find a dummy android studio project attached.

You'll only need to change one line in inseye_tracker_core/build.gradle
From

implementation files("/home/michu/projects/dummy_tracker_core/tensorflow-lite-select-tf-ops.aar")

to

implementation files("your_directory/dummy_tracker_core/tensorflow-lite-select-tf-ops.aar")

and run inseyeDNNTracker from main.kt in java->com.inseye.core (androidTest)

dummy_tracker_core.zip

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label Sep 25, 2023
@pkgoogle
Copy link
pkgoogle commented Sep 26, 2023

Hi @dachshund-ncu, thanks for the info it helps.

@terryheo, I was able to replicate with with @dachshund-ncu's project, I also rebuilt the aar using the official instructions:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZNK6google8protobuf7Message11GetTypeNameEv" referenced by "/data/app/~~bIkQuSqajVmYEPNnKetv5w==/com.inseye.core.test-7O34SiL9duJWfYnOaIKVsA==/base.apk!/lib/arm64-v8a/libtensorflowlite_flex_jni.so"...

@pkgoogle pkgoogle added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Sep 26, 2023
@shsaronian
Copy link
shsaronian commented Dec 16, 2023

Any update on this issue? Ive ran into a similar error when building tensorflow select ops via docker on branch r2.13 on my model.
@dachshund-ncu did you manage to find a workaround for your problem?

@pkgoogle
Copy link

Hi @shsaronian, can you please try with r2.15 or nightly. Also can you please share your reproduce steps the same way as above so that will give us more data to potentially solve the issue if it's the same issue. Thanks for your help.

@shsaronian
Copy link

Hi @shsaronian, can you please try with r2.15 or nightly. Also can you please share your reproduce steps the same way as above so that will give us more data to potentially solve the issue if it's the same issue. Thanks for your help.

Hi, thanks for responding. I will give r2.15 a try and let you know. Meanwhile, I downgraded to r2.9 and followed the official instructions using docker and I managed to build successfully. I didn't even need the --config=monolithic as I didn't run into the _ZN6google8protobuf8internal26fixed_address_empty_stringE error.

@shsaronian
Copy link
shsaronian commented Jan 2, 2024

@pkgoogle I'm providing my reproduce steps on r2.13 to get to the above issue.

  1. Downloaded the official Docker file from here and put it into an empty directory.
  2. Followed the official documentation and built the image:
docker build . -t tflite-builder -f tflite-android.Dockerfile
  1. Ran the container:
docker run -it -v $PWD:/host_dir tflite-builder bash
  1. Inside the container, ran the following commands:
sdkmanager \
  "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
  "platform-tools" \
  "platforms;android-${ANDROID_API_LEVEL}" 
  1. Cloned tensorflow r2.13 branch with depth of 1:
git clone https://github.com/tensorflow/tensorflow.git --branch r2.13 --depth 1
  1. Changed working directory to the tensorflow repo:
cd tensorflow
  1. Executed configure file:
python configure.py
  1. Answered the questions like this:
Please specify the location of python. [Default is /usr/bin/python3]: /usr/bin/python3
Please input the desired Python library path to use.  Default is [/usr/lib/python3/dist-packages]: /usr/lib/python3/dist-packages
Do you wish to build TensorFlow with ROCm support? [y/N]: N
Do you wish to build TensorFlow with CUDA support? [y/N]: N
Do you wish to download a fresh release of clang? (Experimental) [y/N]: N
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -Wno-sign-compare]: -Wno-sign-compare
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: y
  1. Finally, executed the build command:
bash tensorflow/lite/tools/build_aar.sh \
  --input_models=path/to/models \
  --target_archs=arm64-v8a,armeabi-v7a

Just like above, if I execute the build command without the monolitic option, I get the _ZN6google8protobuf8internal26fixed_address_empty_stringE error, and when I do insert the monolitic option in .bazelrc file with echo -n "build --config=monolithic" >> .bazelrc command, my build fails with Check failed: existing == nullptr (Tensor already registered) error.

@tanpengshi
Copy link

I am encountering a similar error with 2.13

Anyone knows if 2.15 solves the error? Do you need

echo -n "build --config=monolithic" >> .bazelrc

command for 2.15?

@Jovian-Dsouza
Copy link

I am encountering a similar error with 2.13

Anyone knows if 2.15 solves the error? Do you need

echo -n "build --config=monolithic" >> .bazelrc

command for 2.15?

I tried with 2.15, same error is coming.

@Jovian-Dsouza
Copy link

@terryheo @pkgoogle
Can you please help with possible debug options as this error is a major blocker in my project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:lite TF Lite related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.13 For issues related to Tensorflow 2.13 type:bug Bug type:build/install Build and install issues
Projects
None yet
Development

No branches or pull requests

10 participants