Skip to content

Commit 5180fd9

Browse files
cantoniostf-text-github-robot
authored andcommitted
Add docker build scripts and enable aarch64 pip wheels.
Also enable python 3.12 builds. Usage: ``` bash oss_scripts/docker_builds.sh ``` or to build for a single python version, ``` PYTHON_VERSION=3.12 bash oss_scripts/docker_builds.sh ``` PiperOrigin-RevId: 692953635
1 parent 9474dd9 commit 5180fd9

16 files changed

+2911
-1552
lines changed

WORKSPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ python_init_repositories(
110110
"3.9": "//oss_scripts/pip_package:requirements_lock_3_9.txt",
111111
"3.10": "//oss_scripts/pip_package:requirements_lock_3_10.txt",
112112
"3.11": "//oss_scripts/pip_package:requirements_lock_3_11.txt",
113+
"3.12": "//oss_scripts/pip_package:requirements_lock_3_12.txt",
113114
},
114115
default_python_version = "system",
115116
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Constructs the environment within which we will build the tensorflow-text
2+
# pip wheels.
3+
4+
FROM linaro/tensorflow-arm64-build:2.16-multipython
5+
LABEL maintainer="TensorFlow-Text team <tf-text-team@google.com>"
6+
7+
ARG PYTHON_VERSION
8+
9+
ENV DEBIAN_FRONTEND=noninteractive
10+
ENV PYTHON_BIN_PATH=/usr/bin/python${PYTHON_VERSION}
11+
12+
# Install supplementary Python interpreters
13+
RUN ln -s ${PYTHON_BIN_PATH} /usr/local/bin/python && \
14+
ln -s ${PYTHON_BIN_PATH} /usr/local/bin/python3 && \
15+
ln -s ${PYTHON_BIN_PATH} /usr/bin/python
16+
17+
RUN --mount=type=cache,target=/var/cache/apt \
18+
apt update && \
19+
apt install -yqq \
20+
apt-utils \
21+
build-essential \
22+
checkinstall \
23+
libffi-dev
24+
25+
# Install pip dependencies needed for tensorflow-text
26+
RUN --mount=type=cache,target=/root/.cache \
27+
${PYTHON_BIN_PATH} -m pip install -U pip && \
28+
${PYTHON_BIN_PATH} -m pip install -U \
29+
absl-py \
30+
auditwheel \
31+
etils[epath] \
32+
patchelf \
33+
setuptools \
34+
twine \
35+
wheel;
36+
37+
WORKDIR "/tmp/tensorflow_text"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Constructs the environment within which we will build the tensorflow-text
2+
# pip wheels.
3+
4+
ARG PYTHON_VERSION
5+
FROM tensorflow/build:2.18-python${PYTHON_VERSION}
6+
LABEL maintainer="TensorFlow-Text team <tf-text-team@google.com>"
7+
8+
ENV DEBIAN_FRONTEND=noninteractive
9+
10+
# Install supplementary Python interpreters
11+
RUN mkdir /tmp/python
12+
RUN --mount=type=cache,target=/var/cache/apt \
13+
apt update && \
14+
apt install -yqq \
15+
apt-utils \
16+
build-essential \
17+
checkinstall \
18+
libffi-dev
19+
20+
# Install pip dependencies needed for tensorflow text.
21+
RUN --mount=type=cache,target=/root/.cache \
22+
python${PYTHON_VERSION} -m pip install -U pip && \
23+
python${PYTHON_VERSION} -m pip install -U \
24+
absl-py \
25+
auditwheel \
26+
etils[epath] \
27+
patchelf \
28+
setuptools \
29+
twine \
30+
wheel;
31+
32+
WORKDIR "/tmp/tensorflow_text"

oss_scripts/build_docs.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# Copyright 2024 TF.Text Authors.
17+
#
18+
# Licensed under the Apache License, Version 2.0 (the "License");
19+
# you may not use this file except in compliance with the License.
20+
# You may obtain a copy of the License at
21+
#
22+
# http://www.apache.org/licenses/LICENSE-2.0
23+
#
24+
# Unless required by applicable law or agreed to in writing, software
25+
# distributed under the License is distributed on an "AS IS" BASIS,
26+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27+
# See the License for the specific language governing permissions and
28+
# limitations under the License.
29+
1630
r"""Tool to generate external api_docs.
1731
1832
python build_docs.py --output_dir=/tmp/text_api

oss_scripts/configure.sh

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,10 @@ if [[ $(pip show tensorflow) == *tensorflow* ]] ||
3838
echo 'Using installed tensorflow.'
3939
else
4040
echo 'Installing tensorflow.'
41-
if is_macos; then
42-
# Only Apple Silicon will be installed with tensorflow-macos.
43-
if [[ x"$(arch)" == x"arm64" ]]; then
44-
pip install tensorflow-macos==2.16.1
45-
else
46-
pip install tensorflow==2.16.1
47-
fi
41+
if [[ "$IS_NIGHTLY" == "nightly" ]]; then
42+
pip install tf-nightly
4843
else
49-
pip install tensorflow==2.16.1
44+
pip install tensorflow==2.18.0
5045
fi
5146
fi
5247

@@ -58,8 +53,6 @@ curl https://raw.githubusercontent.com/tensorflow/tensorflow/master/.bazelrc -o
5853
# This line breaks Windows builds, so we remove it.
5954
sed -i -e 's/build --noincompatible_remove_legacy_whole_archive//' .bazelrc
6055

61-
# the next line is temporary to aid in transition
62-
write_to_bazelrc "build:manylinux2010 --config=release_cpu_linux"
6356
write_to_bazelrc "build:manylinux2014 --config=release_cpu_linux"
6457

6558
if (which python3) | grep -q "python3"; then

oss_scripts/docker_builds.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
# This script builds a docker container, and pip wheels for all supported
3+
# Python versions. Run from the root tensorflow-text directory:
4+
#
5+
# ./oss_scripts/docker_builds.sh
6+
7+
set -e -x
8+
9+
# If a specific PYTHON_VERSION is specified, only build that one.
10+
# Otherwisebuild all supported versions.
11+
python_versions=("3.9" "3.10" "3.11" "3.12")
12+
if [[ ! -z ${PYTHON_VERSION+x} ]]; then
13+
python_versions=("$PYTHON_VERSION")
14+
fi
15+
16+
# Clean previous images.
17+
for python_version in ${python_versions[@]}
18+
do
19+
docker rmi -f tensorflow_text:${python_version} || true
20+
done
21+
22+
arch=$(uname -m)
23+
build_args=()
24+
if [ "$arch" == "x86_64" ]; then
25+
build_args+=("--config=release_cpu_linux")
26+
build_args+=("--platforms=@sigbuild-r2.17-clang_config_platform//:platform")
27+
auditwheel_platform="manylinux2014_x86_64"
28+
elif [ "$arch" == "aarch64" ]; then
29+
build_args+=("--crosstool_top=@ml2014_aarch64_config_aarch64//crosstool:toolchain")
30+
auditwheel_platform="manylinux2014_aarch64"
31+
fi
32+
33+
# Build wheel for each Python version.
34+
for python_version in ${python_versions[@]}
35+
do
36+
DOCKER_BUILDKIT=1 docker build --progress=plain --no-cache \
37+
--build-arg HERMETIC_PYTHON_VERSION=${python_version} --build-arg PYTHON_VERSION=${python_version} \
38+
-t tensorflow_text:${python_version} - < "oss_scripts/build.Dockerfile.${arch}"
39+
40+
docker run --rm -a stdin -a stdout -a stderr \
41+
--env PYTHON_VERSION=${python_version} \
42+
--env HERMETIC_PYTHON_VERSION=${python_version} \
43+
--env BUILD_ARGS=${build_args} \
44+
--env AUDITWHEEL_PLATFORM=${auditwheel_platform} \
45+
--env IS_NIGHTLY=${IS_NIGHTLY} \
46+
-v $PWD:/tmp/tensorflow_text \
47+
--name tensorflow_text tensorflow_text:${python_version} \
48+
bash oss_scripts/run_build.sh
49+
done

oss_scripts/pip_package/requirements.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# ai-edge-litert
2+
setuptools==70.0.0
13
tensorflow
24
tf-keras
35
tensorflow-datasets

0 commit comments

Comments
 (0)