Closed VinayHajare closed 1 month ago
It seems building the TFLite library from the modified source code has problems. You can first comment these codes in "obfuscation.py" to disable building the TFLite python package and get the error message more clear:
os.chdir('./tensorflow-2.9.1/')
os.system("bash build.sh")
os.chdir(currentPath)
then, run the commands one by one (these commands can be found in the building scripts):
generate the obfuscation model and modified source code of TFLite
python obfuscation.py --model_name=fruit --extra_layer=30 --shortcut=30
build the customized tflite from the modified source code, the problem is usually caused by this step. Note that if your machine has enough RAM (>32 GB), you can remove the option "--jobs=14", it defines the maximal nb. of compiling jobs:
bazel build --jobs=14 //tensorflow/tools/pip_package:build_pip_package
generate python package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
uninstall the original TFLite
python -m pip uninstall -y tensorflow
install the customized TFLite
python -m pip install /tmp/tensorflow_pkg/tensorflow-2.9.1-cp38-cp38-linux_x86_64.whl
test
python test_model.py --model_name=fruit
When you identify the step causing the problem, you can post the error message here. And I can try my best to help you. But you know building the Python package from the source sometimes will have different errors in different machines. So, my suggestion is to use the provided Docker Image to run the code, it will save your time in solving the environment issues.
I tried with the docker image to then the below error appear -
conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: Requirement '/tmp/tensorflow_pkg/tensorflow-2.9.1-cp38-cp38-linux_x86_64.whl' looks like a filename, but the file does not exist
Processing /tmp/tensorflow_pkg/tensorflow-2.9.1-cp38-cp38-linux_x86_64.whl
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '/tmp/tensorflow_pkg/tensorflow-2.9.1-cp38-cp38-linux_x86_64.whl'
Traceback (most recent call last):
File "test_model.py", line 5, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
(code275) root@0ffa26980d1b:/Code275# bash build_obf.sh
Traceback (most recent call last):
File "obfuscation.py", line 5, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
WARNING: Skipping tensorflow as it is not installed.
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: Requirement '/tmp/tensorflow_pkg/tensorflow-2.9.1-cp38-cp38-linux_x86_64.whl' looks like a filename, but the file does not exist
Processing /tmp/tensorflow_pkg/tensorflow-2.9.1-cp38-cp38-linux_x86_64.whl
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '/tmp/tensorflow_pkg/tensorflow-2.9.1-cp38-cp38-linux_x86_64.whl'
Traceback (most recent call last):
File "test_model.py", line 5, in <module>
import tensorflow as tf
Ok. You can try these steps and see which one causes the problem:
You can first comment these codes in "obfuscation.py" to disable building the TFLite python package and get the error message clearer:
os.chdir('./tensorflow-2.9.1/')
os.system("bash build.sh")
os.chdir(currentPath)
then, run the commands one by one (these commands can be found in the building scripts):
generate the obfuscation model and modified source code of TFLite
python obfuscation.py --model_name=fruit --extra_layer=30 --shortcut=30
build the customized tflite from the modified source code, the problem is usually caused by this step. Note that if your machine has enough RAM (>32 GB), you can remove the option "--jobs=14", it defines the maximal nb. of compiling jobs:
cd ./tensorflow-2.9.1/
bazel build --jobs=14 //tensorflow/tools/pip_package:build_pip_package
generate python package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
cd ..
uninstall the original TFLite
python -m pip uninstall -y tensorflow
install the customized TFLite
python -m pip install /tmp/tensorflow_pkg/tensorflow-2.9.1-cp38-cp38-linux_x86_64.whl
test
python test_model.py --model_name=fruit
When you identify the step causing the problem, you can post the error message here. And I can try my best to help you. But you know building the Python package from the source sometimes will have different errors in different machines. So, my suggestion is to use the provided Docker Image to run the code, it will save your time in solving the environment issues.
Ok so the model get obfuscate successfully but after that the bazel build command gives below error
(code275) root@f75033d90548:/Code275/tensorflow-2.9.1# bazel build //tensorflow/tools/pip_package:build_pip_package
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
INFO: Options provided by the client:
Inherited 'common' options: --isatty=1 --terminal_columns=114
INFO: Reading rc options for 'build' from /Code275/tensorflow-2.9.1/.bazelrc:
Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'build' from /Code275/tensorflow-2.9.1/.bazelrc:
'build' options: --define framework_shared_object=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
INFO: Reading rc options for 'build' from /Code275/tensorflow-2.9.1/.tf_configure.bazelrc:
'build' options: --action_env PYTHON_BIN_PATH=/root/anaconda3/envs/code275/bin/python3 --action_env PYTHON_LIB_PATH=/root/anaconda3/envs/code275/lib/python3.8/site-packages --python_path=/root/anaconda3/envs/code275/bin/python3 --action_env ANDROID_NDK_HOME=/home/Android/android-ndk-r19c --action_env ANDROID_NDK_API_LEVEL=21 --action_env ANDROID_BUILD_TOOLS_VERSION=30.0.3 --action_env ANDROID_SDK_API_LEVEL=30 --action_env ANDROID_SDK_HOME=/home/Android/Sdk
INFO: Reading rc options for 'build' from /Code275/tensorflow-2.9.1/.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/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/common,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
INFO: Found applicable config definition build:short_logs in file /Code275/tensorflow-2.9.1/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:v2 in file /Code275/tensorflow-2.9.1/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition build:linux in file /Code275/tensorflow-2.9.1/.bazelrc: --copt=-w --host_copt=-w --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 --config=dynamic_kernels --distinct_host_configuration=false --experimental_guard_against_concurrent_changes
INFO: Found applicable config definition build:dynamic_kernels in file /Code275/tensorflow-2.9.1/.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/093ed77f7d50f75b376f40a71ea86e08cedb8b80.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
DEBUG: Rule 'io_bazel_rules_docker' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1596824487 -0400"
DEBUG: Repository io_bazel_rules_docker instantiated at:
/Code275/tensorflow-2.9.1/WORKSPACE:23:14: in <toplevel>
/Code275/tensorflow-2.9.1/tensorflow/workspace0.bzl:107:34: in workspace
/root/.cache/bazel/_bazel_root/a5a5071651a6c349d639f25e016288e1/external/bazel_toolchains/repositories/repositories.bzl:35:23: in repositories
Repository rule git_repository defined at:
/root/.cache/bazel/_bazel_root/a5a5071651a6c349d639f25e016288e1/external/bazel_tools/tools/build_defs/repo/git.bzl:199:33: in <toplevel>
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/XNNPACK/archive/11b2812d64e49bab9b6c489f79067fc94e69db9f.zip failed: class java.io.FileNotFoundException GET returned 404 Not Found
INFO: Analyzed target //tensorflow/tools/pip_package:build_pip_package (484 packages loaded, 28840 targets configured).
INFO: Found 1 target...
[3,505 / 9,753] 12 actions running
Compiling mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp; 99s local
Compiling mlir/lib/Dialect/Vector/IR/VectorOps.cpp; 31s local
Compiling tensorflow/compiler/mlir/hlo/lib/Dialect/mhlo/IR/hlo_ops.cc; 28s local
Compiling mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp; 24s local
Compiling tensorflow/compiler/xla/service/cpu/runtime_matmul.cc; 19s local
Compiling mlir/lib/Dialect/Arithmetic/IR/ArithmeticDialect.cpp; 17s local
Compiling tensorflow/compiler/mlir/hlo/lib/Dialect/mhlo/transforms/rank_specialization.cc; 11s local
Compiling .../compiler/mlir/hlo/lib/Dialect/mhlo/transforms/legalize_einsum_to_dot_general.cc; 9s local ...
time="2024-09-05T13:55:01+05:30" level=error msg="error waiting for container: unexpected EOF"
Ok so the model get obfuscate successfully but after that the bazel build command gives below error
(code275) root@f75033d90548:/Code275/tensorflow-2.9.1# bazel build //tensorflow/tools/pip_package:build_pip_package Extracting Bazel installation... Starting local Bazel server and connecting to it... INFO: Options provided by the client: Inherited 'common' options: --isatty=1 --terminal_columns=114 INFO: Reading rc options for 'build' from /Code275/tensorflow-2.9.1/.bazelrc: Inherited 'common' options: --experimental_repo_remote_exec INFO: Reading rc options for 'build' from /Code275/tensorflow-2.9.1/.bazelrc: 'build' options: --define framework_shared_object=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 INFO: Reading rc options for 'build' from /Code275/tensorflow-2.9.1/.tf_configure.bazelrc: 'build' options: --action_env PYTHON_BIN_PATH=/root/anaconda3/envs/code275/bin/python3 --action_env PYTHON_LIB_PATH=/root/anaconda3/envs/code275/lib/python3.8/site-packages --python_path=/root/anaconda3/envs/code275/bin/python3 --action_env ANDROID_NDK_HOME=/home/Android/android-ndk-r19c --action_env ANDROID_NDK_API_LEVEL=21 --action_env ANDROID_BUILD_TOOLS_VERSION=30.0.3 --action_env ANDROID_SDK_API_LEVEL=30 --action_env ANDROID_SDK_HOME=/home/Android/Sdk INFO: Reading rc options for 'build' from /Code275/tensorflow-2.9.1/.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/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/common,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 INFO: Found applicable config definition build:short_logs in file /Code275/tensorflow-2.9.1/.bazelrc: --output_filter=DONT_MATCH_ANYTHING INFO: Found applicable config definition build:v2 in file /Code275/tensorflow-2.9.1/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1 INFO: Found applicable config definition build:linux in file /Code275/tensorflow-2.9.1/.bazelrc: --copt=-w --host_copt=-w --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 --config=dynamic_kernels --distinct_host_configuration=false --experimental_guard_against_concurrent_changes INFO: Found applicable config definition build:dynamic_kernels in file /Code275/tensorflow-2.9.1/.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/093ed77f7d50f75b376f40a71ea86e08cedb8b80.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 DEBUG: Rule 'io_bazel_rules_docker' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1596824487 -0400" DEBUG: Repository io_bazel_rules_docker instantiated at: /Code275/tensorflow-2.9.1/WORKSPACE:23:14: in <toplevel> /Code275/tensorflow-2.9.1/tensorflow/workspace0.bzl:107:34: in workspace /root/.cache/bazel/_bazel_root/a5a5071651a6c349d639f25e016288e1/external/bazel_toolchains/repositories/repositories.bzl:35:23: in repositories Repository rule git_repository defined at: /root/.cache/bazel/_bazel_root/a5a5071651a6c349d639f25e016288e1/external/bazel_tools/tools/build_defs/repo/git.bzl:199:33: in <toplevel> WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/XNNPACK/archive/11b2812d64e49bab9b6c489f79067fc94e69db9f.zip failed: class java.io.FileNotFoundException GET returned 404 Not Found INFO: Analyzed target //tensorflow/tools/pip_package:build_pip_package (484 packages loaded, 28840 targets configured). INFO: Found 1 target... [3,505 / 9,753] 12 actions running Compiling mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp; 99s local Compiling mlir/lib/Dialect/Vector/IR/VectorOps.cpp; 31s local Compiling tensorflow/compiler/mlir/hlo/lib/Dialect/mhlo/IR/hlo_ops.cc; 28s local Compiling mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp; 24s local Compiling tensorflow/compiler/xla/service/cpu/runtime_matmul.cc; 19s local Compiling mlir/lib/Dialect/Arithmetic/IR/ArithmeticDialect.cpp; 17s local Compiling tensorflow/compiler/mlir/hlo/lib/Dialect/mhlo/transforms/rank_specialization.cc; 11s local Compiling .../compiler/mlir/hlo/lib/Dialect/mhlo/transforms/legalize_einsum_to_dot_general.cc; 9s local ... time="2024-09-05T13:55:01+05:30" level=error msg="error waiting for container: unexpected EOF"
Sorry, I forget to add the command to change the directory.
Here is the updated steps:
You can first comment these codes in "obfuscation.py" to disable building the TFLite python package and get the error message clearer:
os.chdir('./tensorflow-2.9.1/')
os.system("bash build.sh")
os.chdir(currentPath)
then, run the commands one by one (these commands can be found in the building scripts):
generate the obfuscation model and modified source code of TFLite
python obfuscation.py --model_name=fruit --extra_layer=30 --shortcut=30
build the customized tflite from the modified source code, the problem is usually caused by this step. Note that if your machine has enough RAM (>32 GB), you can remove the option "--jobs=14", it defines the maximal nb. of compiling jobs:
cd ./tensorflow-2.9.1/
bazel build --jobs=14 //tensorflow/tools/pip_package:build_pip_package
generate python package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
cd ..
uninstall the original TFLite
python -m pip uninstall -y tensorflow
install the customized TFLite
python -m pip install /tmp/tensorflow_pkg/tensorflow-2.9.1-cp38-cp38-linux_x86_64.whl
test
python test_model.py --model_name=fruit
When you identify the step causing the problem, you can post the error message here. And I can try my best to help you. But you know building the Python package from the source sometimes will have different errors in different machines. So, my suggestion is to use the provided Docker Image to run the code, it will save your time in solving the environment issues.
Close it as it has been inactive for some days
I have followed all the given instructions to setup the environment and after following the environment is created and configure successfully. In the last executing the test command -
bash ./build_obf.sh
generates below error while all the dependencies where satisfied and the conda environment has all the needed libraries and dependencies.
I have tried it on several machines with different OS and every time i encounter same error