Skip to content

Commit

Permalink
Update TF versions and scripts to allow consistently building against…
Browse files Browse the repository at this point in the history
… tf-nightly.

Currently the master branch contains a patch and other changes
that is needed to build against a later version of TF than the
2.13 release (and even the 2.14 rc0).  Bumped up the default
commit in the WORKSPACE file to allow a build, and bumped up
the release version to 2.13 for now (was previously 2.12).

Sometimes the tf-nightly build reports a `tf.__git_version__` of
"unknown" (occasionally on intel, frequently on ARM), causing the
build scripts to fail and abort.  Modified the `prepare_tf_dep.sh`
to account for this, defaulting to the latest tf-nightly source in
such a case.

Fixes #1202, #1195.

PiperOrigin-RevId: 559233072
  • Loading branch information
cantonios authored and tf-text-github-robot committed Aug 22, 2023
1 parent 8f8b2a2 commit a46b7b1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# The .bazelrc file is autogenerated by oss_scripts/configure.sh.
.bazelrc
.bazelversion

# Do not track bazels output directories.
bazel-*
Expand Down
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ http_archive(
name = "org_tensorflow",
patch_args = ["-p1"],
patches = ["//third_party/tensorflow:tf.patch"],
strip_prefix = "tensorflow-2.12.0",
sha256 = "af0584df1a4e28763c32c218b39f8c4f3784fabb6a8859b00c02d743864dc191",
strip_prefix = "tensorflow-f21d60a1667c4a52399986809e8e9aedac0e24c2",
sha256 = "35fd0d69969f482edcc1e46d2d07c43a16ee02cfef1396b11a71b719674a1c8a",
urls = [
"https://github.com/tensorflow/tensorflow/archive/v2.12.0.zip"
"https://github.com/tensorflow/tensorflow/archive/f21d60a1667c4a52399986809e8e9aedac0e24c2.zip"
],
)

Expand Down
6 changes: 3 additions & 3 deletions oss_scripts/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ else
if is_macos; then
# Only Apple Silicon will be installed with tensorflow-macos.
if [[ x"$(arch)" == x"arm64" ]]; then
pip install tensorflow-macos==2.9.0
pip install tensorflow-macos==2.13.0
else
pip install tensorflow==2.12.0
pip install tensorflow==2.13.0
fi
else
pip install tensorflow==2.12.0
pip install tensorflow==2.13.0
fi
fi

Expand Down
8 changes: 4 additions & 4 deletions oss_scripts/pip_package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from setuptools.dist import Distribution

project_name = 'tensorflow-text'
project_version = '2.12.0'
project_version = '2.13.0'


class BinaryDistribution(Distribution):
Expand Down Expand Up @@ -74,18 +74,18 @@ def finalize_options(self):
distclass=BinaryDistribution,
install_requires=[
(
'tensorflow>=2.12.0, <2.13; platform_machine != "arm64" or'
'tensorflow>=2.13.0, <2.14; platform_machine != "arm64" or'
' platform_system != "Darwin"'
),
(
'tensorflow-macos>=2.12.0, <2.13; platform_machine == "arm64" and'
'tensorflow-macos>=2.13.0, <2.14; platform_machine == "arm64" and'
' platform_system == "Darwin"'
),
'tensorflow_hub>=0.13.0',
],
extras_require={
'tensorflow_cpu': [
'tensorflow-cpu>=2.12.0, <2.13',
'tensorflow-cpu>=2.13.0, <2.14',
],
'tests': [
'absl-py',
Expand Down
35 changes: 22 additions & 13 deletions oss_scripts/prepare_tf_dep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,34 @@ if [[ "${osname}" == "darwin" ]]; then
ext='""'
fi

# update setup.nightly.py with tf version
# Update setup.nightly.py with current tf version.
tf_version=$($installed_python -c 'import tensorflow as tf; print(tf.__version__)')
echo "$tf_version"
sed -i $ext "s/project_version = 'REPLACE_ME'/project_version = '${tf_version}'/" oss_scripts/pip_package/setup.nightly.py
# update __version__
echo "Updating setup.nightly.py to version $tf_version"
sed -i $ext "s/project_version = '.*'/project_version = '${tf_version}'/" oss_scripts/pip_package/setup.nightly.py
# Update __version__.
echo "Updating __init__.py to version $tf_version"
sed -i $ext "s/__version__ = .*\$/__version__ = \"${tf_version}\"/" tensorflow_text/__init__.py

# Get commit sha of installed tensorflow
# For some unknown reason this now needs to be split into two commands on Windows
# Get git commit sha of installed tensorflow.
echo "Querying commit SHA"
short_commit_sha=$($installed_python -c 'import tensorflow as tf; print(tf.__git_version__)' | tail -1)
if [[ "${osname}" == "darwin" ]]; then
short_commit_sha=$(echo $short_commit_sha | perl -nle 'print $& while m{(?<=-g)[0-9a-f]*$}g')
if [[ "$short_commit_sha" == "unknown" ]]; then
# Some nightly builds report "unknown" for tf.__git_version.
echo 'TF git version "unknown", assuming nightly.'
commit_slug='nightly'
else
short_commit_sha=$(echo $short_commit_sha | grep -oP '(?<=-g)[0-9a-f]*$')
if [[ "${osname}" == "darwin" ]]; then
short_commit_sha=$(echo $short_commit_sha | perl -nle 'print $& while m{(?<=-g)[0-9a-f]*$}g')
else
short_commit_sha=$(echo $short_commit_sha | grep -oP '(?<=-g)[0-9a-f]*$')
fi
echo "Found tensorflow commit sha: $short_commit_sha"
commit_slug=$(curl -s "https://api.github.com/repos/tensorflow/tensorflow/commits/$short_commit_sha" | grep "sha" | head -n 1 | cut -d '"' -f 4)
fi
commit_sha=$(curl -s "https://api.github.com/repos/tensorflow/tensorflow/commits/$short_commit_sha" | grep "sha" | head -n 1 | cut -d '"' -f 4)

# Update TF dependency to installed tensorflow
sed -E -i $ext "s/strip_prefix = \"tensorflow-2.+\",/strip_prefix = \"tensorflow-${commit_sha}\",/" WORKSPACE
sed -E -i $ext "s|\"https://github.com/tensorflow/tensorflow/archive/v.+\.zip\"|\"https://github.com/tensorflow/tensorflow/archive/${commit_sha}.zip\"|" WORKSPACE
# Update TF dependency to installed tensorflow.
echo "Updating WORKSPACE file to use TensorFlow commit $commit_slug"
sed -E -i $ext "s/strip_prefix = \"tensorflow-.+\",/strip_prefix = \"tensorflow-${commit_slug}\",/" WORKSPACE
sed -E -i $ext "s|\"https://github.com/tensorflow/tensorflow/archive/.+\.zip\"|\"https://github.com/tensorflow/tensorflow/archive/${commit_slug}.zip\"|" WORKSPACE
prev_shasum=$(grep -A 1 -e "strip_prefix.*tensorflow-" WORKSPACE | tail -1 | awk -F '"' '{print $2}')
sed -i $ext "s/sha256 = \"${prev_shasum}\",//" WORKSPACE
2 changes: 1 addition & 1 deletion tensorflow_text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@
]

remove_undocumented(__name__, _allowed_symbols)
__version__ = "2.12.0"
__version__ = "2.13.0"

0 comments on commit a46b7b1

Please sign in to comment.