Update tflite-runtime build scripts
PiperOrigin-RevId: 276629962 Change-Id: I42c5e05361660297c78f1717d9021134abe6f0c2
This commit is contained in:
parent
087b39e079
commit
bd422caa62
@ -6,6 +6,8 @@ PYTHON ?= python3
|
||||
TENSORFLOW_TARGET ?= native
|
||||
# Values: n, y
|
||||
BUILD_DEB ?= n
|
||||
# Values: according to https://www.python.org/dev/peps/pep-0440/
|
||||
VERSION_SUFFIX ?=
|
||||
|
||||
MAKEFILE_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
|
||||
TENSORFLOW_DIR := $(MAKEFILE_DIR)/../../../..
|
||||
@ -20,23 +22,28 @@ TAG_IMAGE := "tflite-runtime-builder-$(subst :,-,$(BASE_IMAGE))"
|
||||
help:
|
||||
@echo "make docker-image -- build docker image"
|
||||
@echo "make docker-shell -- run shell inside the docker image"
|
||||
@echo "make docker-build -- build wheel inside the docker image"
|
||||
@echo "make clean -- remove built wheel files"
|
||||
@echo "make docker-build -- build wheel and deb inside the docker image"
|
||||
@echo "make clean -- remove wheel and deb files"
|
||||
|
||||
docker-image:
|
||||
docker build -t $(TAG_IMAGE) --build-arg IMAGE=$(BASE_IMAGE) .
|
||||
|
||||
docker-shell: docker-image
|
||||
docker run --rm -it -v $(TENSORFLOW_DIR):/tensorflow --workdir /tensorflow $(TAG_IMAGE)
|
||||
docker run --rm --interactive --tty \
|
||||
--volume $(TENSORFLOW_DIR):/tensorflow \
|
||||
--workdir /tensorflow \
|
||||
$(TAG_IMAGE)
|
||||
|
||||
docker-build: docker-image
|
||||
docker run \
|
||||
-e "PYTHON=$(PYTHON)" \
|
||||
-e "TENSORFLOW_TARGET=$(TENSORFLOW_TARGET)" \
|
||||
-e "BUILD_DEB=$(BUILD_DEB)" \
|
||||
-v $(TENSORFLOW_DIR):/tensorflow \
|
||||
-v $(CURDIR):/out \
|
||||
--rm -it $(TAG_IMAGE) \
|
||||
docker run --user $(shell id -u):$(shell id -g) \
|
||||
--rm --interactive $(shell tty -s && echo --tty) \
|
||||
--env "PYTHON=$(PYTHON)" \
|
||||
--env "TENSORFLOW_TARGET=$(TENSORFLOW_TARGET)" \
|
||||
--env "BUILD_DEB=$(BUILD_DEB)" \
|
||||
--env "VERSION_SUFFIX=$(VERSION_SUFFIX)" \
|
||||
--volume $(TENSORFLOW_DIR):/tensorflow \
|
||||
--volume $(CURDIR):/out \
|
||||
$(TAG_IMAGE) \
|
||||
/bin/bash -c "tensorflow/tensorflow/lite/tools/pip_package/build_pip_package.sh && \
|
||||
(cp /tmp/tflite_pip/*.deb /tmp/tflite_pip/$(PYTHON)/dist/*.whl /out 2>/dev/null || true)"
|
||||
|
||||
|
@ -13,38 +13,43 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
|
||||
# TODO(dkovalev): b/140445440 -- Implement test coverage for this script.
|
||||
set -e
|
||||
set -x
|
||||
|
||||
PYTHON="${PYTHON:-python3}"
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
export TENSORFLOW_SRC_ROOT="${SCRIPT_DIR}/../../../.."
|
||||
export TENSORFLOW_VERSION=$(grep "_VERSION = " "${TENSORFLOW_SRC_ROOT}/tensorflow/tools/pip_package/setup.py" | cut -d'=' -f 2 | sed "s/[ '-]//g");
|
||||
TFLITE_ROOT="${TENSORFLOW_SRC_ROOT}/tensorflow/lite"
|
||||
BUILD_ROOT="/tmp/tflite_pip/${PYTHON}"
|
||||
PYTHON="${PYTHON:-python3}"
|
||||
VERSION_SUFFIX=${VERSION_SUFFIX:-}
|
||||
export TENSORFLOW_DIR="${SCRIPT_DIR}/../../../.."
|
||||
TENSORFLOW_LITE_DIR="${TENSORFLOW_DIR}/tensorflow/lite"
|
||||
TENSORFLOW_VERSION=$(grep "_VERSION = " "${TENSORFLOW_DIR}/tensorflow/tools/pip_package/setup.py" | cut -d= -f2 | sed "s/[ '-]//g")
|
||||
export PACKAGE_VERSION="${TENSORFLOW_VERSION}${VERSION_SUFFIX}"
|
||||
BUILD_DIR="/tmp/tflite_pip/${PYTHON}"
|
||||
|
||||
# Build source tree.
|
||||
rm -rf "${BUILD_ROOT}"
|
||||
mkdir -p "${BUILD_ROOT}/tflite_runtime"
|
||||
cp -r "${TFLITE_ROOT}/tools/pip_package/debian" \
|
||||
"${TFLITE_ROOT}/python/interpreter_wrapper" \
|
||||
"${TFLITE_ROOT}/tools/pip_package/setup.py" \
|
||||
"${TFLITE_ROOT}/tools/pip_package/MANIFEST.in" \
|
||||
"${BUILD_ROOT}"
|
||||
cp "${TFLITE_ROOT}/python/interpreter.py" \
|
||||
"${BUILD_ROOT}/tflite_runtime"
|
||||
echo "__version__ = '${TENSORFLOW_VERSION}'" > "${BUILD_ROOT}/tflite_runtime/__init__.py"
|
||||
rm -rf "${BUILD_DIR}" && mkdir -p "${BUILD_DIR}/tflite_runtime"
|
||||
cp -r "${TENSORFLOW_LITE_DIR}/tools/pip_package/debian" \
|
||||
"${TENSORFLOW_LITE_DIR}/tools/pip_package/setup.py" \
|
||||
"${TENSORFLOW_LITE_DIR}/tools/pip_package/MANIFEST.in" \
|
||||
"${TENSORFLOW_LITE_DIR}/python/interpreter_wrapper" \
|
||||
"${BUILD_DIR}"
|
||||
cp "${TENSORFLOW_LITE_DIR}/python/interpreter.py" \
|
||||
"${BUILD_DIR}/tflite_runtime"
|
||||
echo "__version__ = '${PACKAGE_VERSION}'" >> "${BUILD_DIR}/tflite_runtime/__init__.py"
|
||||
echo "__git_version__ = '$(git -C "${TENSORFLOW_DIR}" describe)'" >> "${BUILD_DIR}/tflite_runtime/__init__.py"
|
||||
|
||||
# Build python wheel.
|
||||
cd "${BUILD_ROOT}"
|
||||
if [[ "${TENSORFLOW_TARGET}" == "rpi" ]]; then
|
||||
${PYTHON} setup.py bdist_wheel --plat-name=linux-armv7l
|
||||
elif [[ "${TENSORFLOW_TARGET}" == "aarch64" ]]; then
|
||||
${PYTHON} setup.py bdist_wheel --plat-name=linux-aarch64
|
||||
else
|
||||
${PYTHON} setup.py bdist_wheel
|
||||
fi
|
||||
cd "${BUILD_DIR}"
|
||||
case "${TENSORFLOW_TARGET}" in
|
||||
rpi)
|
||||
${PYTHON} setup.py bdist_wheel --plat-name=linux-armv7l
|
||||
;;
|
||||
aarch64)
|
||||
${PYTHON} setup.py bdist_wheel --plat-name=linux-aarch64
|
||||
;;
|
||||
*)
|
||||
${PYTHON} setup.py bdist_wheel
|
||||
;;
|
||||
esac
|
||||
|
||||
# Build debian package.
|
||||
if [[ "${BUILD_DEB}" != "y" ]]; then
|
||||
@ -58,15 +63,28 @@ if [[ ${PYTHON_VERSION} != 3 ]]; then
|
||||
fi
|
||||
|
||||
DEB_VERSION=$(dpkg-parsechangelog --show-field Version | cut -d- -f1)
|
||||
if [[ "${DEB_VERSION}" != "${TENSORFLOW_VERSION}" ]]; then
|
||||
echo "Debian package version (${DEB_VERSION}) doesn't match TensorFlow version (${TENSORFLOW_VERSION})" >&2
|
||||
exit 1
|
||||
if [[ "${DEB_VERSION}" != "${PACKAGE_VERSION}" ]]; then
|
||||
cat << EOF > "${BUILD_DIR}/debian/changelog"
|
||||
tflite-runtime (${PACKAGE_VERSION}-1) unstable; urgency=low
|
||||
|
||||
* Bump version to ${PACKAGE_VERSION}.
|
||||
|
||||
-- TensorFlow team <packages@tensorflow.org> $(date -R)
|
||||
|
||||
$(<"${BUILD_DIR}/debian/changelog")
|
||||
EOF
|
||||
fi
|
||||
|
||||
if [[ "${TENSORFLOW_TARGET}" == "rpi" ]]; then
|
||||
dpkg-buildpackage -b -rfakeroot -us -uc -tc -d -a armhf
|
||||
elif [[ "${TENSORFLOW_TARGET}" == "aarch64" ]]; then
|
||||
dpkg-buildpackage -b -rfakeroot -us -uc -tc -d -a arm64
|
||||
else
|
||||
dpkg-buildpackage -b -rfakeroot -us -uc -tc -d
|
||||
fi
|
||||
case "${TENSORFLOW_TARGET}" in
|
||||
rpi)
|
||||
dpkg-buildpackage -b -rfakeroot -us -uc -tc -d -a armhf
|
||||
;;
|
||||
aarch64)
|
||||
dpkg-buildpackage -b -rfakeroot -us -uc -tc -d -a arm64
|
||||
;;
|
||||
*)
|
||||
dpkg-buildpackage -b -rfakeroot -us -uc -tc -d
|
||||
;;
|
||||
esac
|
||||
|
||||
cat "${BUILD_DIR}/debian/changelog"
|
||||
|
@ -36,9 +36,9 @@ from setuptools import find_packages
|
||||
from setuptools import setup
|
||||
from setuptools.command.build_py import build_py
|
||||
PACKAGE_NAME = 'tflite_runtime'
|
||||
PACKAGE_VERSION = os.environ['TENSORFLOW_VERSION']
|
||||
PACKAGE_VERSION = os.environ['PACKAGE_VERSION']
|
||||
DOCLINES = __doc__.split('\n')
|
||||
TENSORFLOW_DIR = os.environ['TENSORFLOW_SRC_ROOT']
|
||||
TENSORFLOW_DIR = os.environ['TENSORFLOW_DIR']
|
||||
|
||||
# Setup cross compiling
|
||||
TARGET = os.environ.get('TENSORFLOW_TARGET', None)
|
||||
|
Loading…
Reference in New Issue
Block a user