Skip to content

Commit

Permalink
Fixes for tflite
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunsuresh committed Nov 26, 2022
1 parent 976e2ed commit 91a2c64
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 27 deletions.
15 changes: 14 additions & 1 deletion cm-mlops/script/app-mlperf-inference/_cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ deps:

# Variations to customize dependencies
variations:
# Implementation (CPP or Python)
# Implementation (cpp, python, nvidia, tflite-cpp)
cpp:
add_deps_recursive:
imagenet-accuracy-script:
Expand All @@ -356,6 +356,19 @@ variations:
- cpp-mlperf-inference
tags: app,mlperf,cpp,inference

tflite-cpp:
add_deps_recursive:
imagenet-accuracy-script:
tags: _int64
env:
CM_MLPERF_TFLITE_CPP: 'yes'
CM_MLPERF_CPP: 'yes'
CM_MLPERF_IMPLEMENTATION: tflite-cpp
posthook_deps:
- names:
- tflite-cpp-mlperf-inference
tags: app,mlperf,tflite-cpp,inference

python:
add_deps_recursive:
imagenet-accuracy-script:
Expand Down
3 changes: 2 additions & 1 deletion cm-mlops/script/get-bazel/_cm.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"category": "Detection or installation of tools and artifacts",
"clean_files": [],
"new_env_keys": [
"CM_BAZEL_*"
"CM_BAZEL_*",
"+PATH"
],
"prehook_deps": [
{
Expand Down
1 change: 1 addition & 0 deletions cm-mlops/script/get-bazel/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def postprocess(i):

found_path = os.path.dirname(found_file_path)
env['CM_BAZEL_INSTALLED_PATH'] = found_path
env['+PATH'] = [ found_path ]

env['CM_BAZEL_CACHE_TAGS'] = 'version-'+version

Expand Down
1 change: 1 addition & 0 deletions cm-mlops/script/get-cmake/_cm.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
],
"new_env_keys": [
"CM_CMAKE_*",
"CM_MAKE_CORES",
"+PATH"
],
"prehook_deps": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
count = int(os.environ.get('CM_DATASET_SIZE', 1))
preprocessed_base_dir = os.environ.get('CM_DATASET_PREPROCESSED_PATH', os.getcwd())
threads = os.environ.get('CM_NUM_THREADS', os.cpu_count())
threads = os.environ.get('CM_NUM_PREPROCESS_THREADS', threads)
threads = int(os.environ.get('CM_NUM_PREPROCESS_THREADS', threads))

if os.environ.get('CM_MODEL', 'resnet50') == 'resnet50':
pre_process = dataset.pre_process_vgg
Expand Down
3 changes: 3 additions & 0 deletions cm-mlops/script/install-bazel/_cm.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"tags": "detect,os"
}
],
"new_env_keys": [
"CM_BAZEL_*"
],
"env": {
"CM_WGET_URL": "https://github.com/bazelbuild/bazel/releases/download/[VERSION]/bazel-[VERSION]-installer-[OS]-[PLATFORM].sh"
},
Expand Down
28 changes: 23 additions & 5 deletions cm-mlops/script/install-tensorflow-from-src/_cm.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
"tags": "detect,cpu"
}
],
"env": {
"CM_GIT_URL": "https://github.com/tensorflow/tensorflow"
"default_env": {
"CM_GIT_URL": "https://github.com/tensorflow/tensorflow",
"CM_GIT_DEPTH": "1",
"CM_TFLITE": "off"
},
"extra_cache_tags_from_env": [
{
Expand All @@ -21,12 +23,28 @@
}
],
"tags": [
"get",
"install",
"tensorflow",
"lib",
"source",
"from-source",
"from-src"
],
"new_env_keys": [
"+C_INCLUDE_PATH",
"+CPLUS_INCLUDE_PATH",
"+LD_LIBRARY_PATH",
"+DYLD_FALLBACK_LIBRARY_PATH"
],
"uid": "a974533c4c854597",
"variations": {
"tflite": {
"env": {
"CM_TFLITE": "on"
}
}
},
"versions": {
"master": {
"deps": [
Expand All @@ -37,11 +55,11 @@
},
{
"tags": "gcc,get",
"version": "9.3"
"version_min": "9.3"
},
{
"tags": "gcc,bazel",
"version": "5.0.0"
"tags": "get,bazel",
"version": "5.3.0"
}
],
"env": {
Expand Down
9 changes: 7 additions & 2 deletions cm-mlops/script/install-tensorflow-from-src/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

CUR_DIR=${PWD:-tmp}
if [ ! -d "src" ]; then
echo "Cloning Tensorflow from ${CM_GIT_URL} with branch ${CM_GIT_CHECKOUT}..."
git clone --recursive -b "${CM_GIT_CHECKOUT}" ${CM_GIT_URL} src
echo "Cloning Tensorflow from ${CM_GIT_URL} with branch ${CM_GIT_CHECKOUT} --depth ${CM_GIT_DEPTH}..."
git clone --recursive -b "${CM_GIT_CHECKOUT}" ${CM_GIT_URL} --depth ${CM_GIT_DEPTH} src
fi
CM_PYTHON_BIN=${CM_PYTHON_BIN:-python3}
${CM_PYTHON_BIN} -m pip install numpy
Expand All @@ -21,6 +21,11 @@ cd src
./configure
if [ "${?}" != "0" ]; then exit 1; fi

if [ "${CM_TFLITE}" == "on" ]; then
bazel build -c opt --define tflite_with_xnnpack=true //tensorflow/lite:libtensorflowlite.so
if [ "${?}" != "0" ]; then exit 1; fi
exit 0
fi
echo "******************************************************"
bazel build //tensorflow/tools/pip_package:build_pip_package
if [ "${?}" != "0" ]; then exit 1; fi
Expand Down
15 changes: 12 additions & 3 deletions cm-mlops/script/install-tflite-from-src/_cm.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"tags": "get,cmake"
}
],
"default_env": {
"CM_GIT_DEPTH": "1"
},
"env": {
"CM_GIT_URL": "https://github.com/tensorflow/tensorflow"
},
Expand All @@ -26,11 +29,17 @@
"prefix": "python-"
}
],
"new_env_keys": [
"+C_INCLUDE_PATH",
"+CPLUS_INCLUDE_PATH",
"+LD_LIBRARY_PATH",
"+DYLD_FALLBACK_LIBRARY_PATH"
],
"tags": [
"get",
"install",
"tflite",
"tensorflow-lite",
"lib",
"tflite-cmake",
"tensorflow-lite-cmake",
"from-src"
],
"uid": "5c72dab5eb88407c",
Expand Down
6 changes: 3 additions & 3 deletions cm-mlops/script/install-tflite-from-src/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def postprocess(i):
# if key not in env:
env[key] = []

env['+C_INCLUDE_PATH'].append(os.path.join(os.getcwd(), 'install', 'include'))
env['+CPLUS_INCLUDE_PATH'].append(os.path.join(os.getcwd(), 'install', 'include'))
env['+C_INCLUDE_PATH'].append(os.path.join(os.getcwd(), 'src'))
env['+CPLUS_INCLUDE_PATH'].append(os.path.join(os.getcwd(), 'src'))

lib_path = os.path.join(os.getcwd(), 'install', 'lib')
lib_path = os.path.join(os.getcwd(), 'build')
env['+LD_LIBRARY_PATH'].append(lib_path)
env['+DYLD_FALLBACK_LIBRARY_PATH'].append(lib_path)

Expand Down
16 changes: 5 additions & 11 deletions cm-mlops/script/install-tflite-from-src/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

CUR_DIR=${PWD:-tmp}
if [ ! -d "src" ]; then
echo "Cloning Tensorflow from ${CM_GIT_URL} with branch ${CM_GIT_CHECKOUT}..."
git clone --recursive -b "${CM_GIT_CHECKOUT}" ${CM_GIT_URL} src
echo "Cloning Tensorflow from ${CM_GIT_URL} with branch ${CM_GIT_CHECKOUT} --depth ${CM_GIT_DEPTH}..."
git clone --recursive -b "${CM_GIT_CHECKOUT}" ${CM_GIT_URL} --depth ${CM_GIT_DEPTH} src
fi

INSTALL_DIR="${CUR_DIR}"
rm -rf ${INSTALL_DIR}/install
rm -rf ${INSTALL_DIR}/build

cd ${INSTALL_DIR}
Expand All @@ -16,18 +15,13 @@ mkdir -p install

echo "******************************************************"
cd build
cmake ../src/tensorflow/lite
cmake ../src/tensorflow/lite/c
if [ "${?}" != "0" ]; then exit 1; fi

echo "******************************************************"
cmake --build . -j
cmake --build . -j${CM_MAKE_CORES}
if [ "${?}" != "0" ]; then exit 1; fi

# Clean build directory
cd ${INSTALL_DIR}
if [ "${CM_TFLITE_CLEAN_BUILD}" != "no" ]; then
rm -rf build
fi

echo "******************************************************"
echo "Tflite is built and installed to ${INSTALL_DIR}/install ..."
echo "Tflite is built to ${INSTALL_DIR}/build ..."

0 comments on commit 91a2c64

Please sign in to comment.