Skip to content

Commit eee824d

Browse files
committed
Fix TF-text for TF 2.20.
This is a combination of a collection of changes to fix the TF-text build. All are required for a successful build. 1. Upgrade ICU to v77.1 - Requires changes to ICU build file, updating ICU data, updating test goldens - Added `custom_http_archive` rule to allow excluding files. 2. Replace `tensorflow.bzl:pybind_extension` with `pywrap.bzl:pybind_extension`, `pywrap_libraries`, `pywrap_binaries` - Forces creation of pybind bundled .so file to include in the wheel. 3. Patch TF build file to exclude `libtensorflow_framework` source files. - Avoids ODR issues causing double-registrations. 4. Update requirements files - TF 3.9, 3.10 are somewhat fundamentally broken because of tensorflow-metadata, which restricts the protobuf version below what TF requires. Though this turns out not to be a hard requirement, by skipping the requirements.update in `configure` and manually setting package versions, we can create a successful build. 5. Replace the `build_pip_package.sh` with a python version - Allows using the hermetic python toolchain to build the wheel. Avoids the need for docker. 6. Fix random missing deps. PiperOrigin-RevId: 854285564
1 parent a7870df commit eee824d

32 files changed

+1994441
-11656
lines changed

WORKSPACE

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,42 @@
11
workspace(name = "org_tensorflow_text")
22

33
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
load("//third_party/bazel:http.bzl", "custom_http_archive")
45

5-
http_archive(
6+
custom_http_archive(
67
name = "icu",
7-
strip_prefix = "icu-release-64-2",
8-
sha256 = "dfc62618aa4bd3ca14a3df548cd65fe393155edd213e49c39f3a30ccd618fc27",
8+
exclude = [
9+
# Build file does not contain all required targets.
10+
"icu4c/source/common/BUILD.bazel",
11+
],
12+
files = {
13+
"BUILD.bazel": "//third_party/icu:BUILD.bzl",
14+
},
15+
sha256 = "e424ba5282d95ad38b52639a08fb82164f0b0cbd7f17b53ae16bf14f8541855f",
16+
strip_prefix = "icu-release-77-1",
917
urls = [
10-
"https://storage.googleapis.com/mirror.tensorflow.org/github.com/unicode-org/icu/archive/release-64-2.zip",
11-
"https://github.com/unicode-org/icu/archive/release-64-2.zip",
18+
"https://storage.googleapis.com/mirror.tensorflow.org/github.com/unicode-org/icu/archive/release-77-1.zip",
19+
"https://github.com/unicode-org/icu/archive/release-77-1.zip",
1220
],
13-
build_file = "//third_party/icu:BUILD.bzl",
14-
patches = ["//third_party/icu:udata.patch"],
15-
patch_args = ["-p1"],
1621
)
1722

1823
http_archive(
1924
name = "com_google_sentencepiece",
20-
strip_prefix = "sentencepiece-0.1.96",
25+
build_file = "//third_party/sentencepiece:BUILD",
26+
patch_args = ["-p1"],
27+
patches = ["//third_party/sentencepiece:sp.patch"],
2128
sha256 = "8409b0126ebd62b256c685d5757150cf7fcb2b92a2f2b98efb3f38fc36719754",
29+
strip_prefix = "sentencepiece-0.1.96",
2230
urls = [
23-
"https://github.com/google/sentencepiece/archive/refs/tags/v0.1.96.zip"
31+
"https://github.com/google/sentencepiece/archive/refs/tags/v0.1.96.zip",
2432
],
25-
build_file = "//third_party/sentencepiece:BUILD",
26-
patches = ["//third_party/sentencepiece:sp.patch"],
27-
patch_args = ["-p1"],
2833
)
2934

3035
http_archive(
3136
name = "cppitertools",
32-
urls = ["https://github.com/ryanhaining/cppitertools/archive/refs/tags/v2.0.zip"],
3337
sha256 = "e56741b108d6baced98c4ccd83fd0d5a545937f2845978799c28d0312c0dee3d",
3438
strip_prefix = "cppitertools-2.0",
39+
urls = ["https://github.com/ryanhaining/cppitertools/archive/refs/tags/v2.0.zip"],
3540
)
3641

3742
http_archive(
@@ -56,10 +61,12 @@ http_archive(
5661

5762
http_archive(
5863
name = "org_tensorflow",
59-
strip_prefix = "tensorflow-40998f44c0c500ce0f6e3b1658dfbc54f838a82a",
60-
sha256 = "5a5bc4599964c71277dcac0d687435291e5810d2ac2f6283cc96736febf73aaf",
64+
sha256 = "213edf03ac7c4e74d8eb2074216ae8c8ae4f325c6bc22efd16cfdeed2073bd66",
65+
strip_prefix = "tensorflow-2.20.0",
66+
patch_args = ["-p1"],
67+
patches = ["//third_party/tensorflow:tensorflow.core.BUILD.patch"],
6168
urls = [
62-
"https://github.com/tensorflow/tensorflow/archive/40998f44c0c500ce0f6e3b1658dfbc54f838a82a.zip"
69+
"https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.20.0.zip",
6370
],
6471
)
6572

@@ -74,13 +81,13 @@ http_archive(
7481

7582
http_archive(
7683
name = "pybind11",
84+
build_file = "//third_party/pybind11:BUILD.bzl",
85+
sha256 = "efc901aa0aab439a3fea6efeaf930b5a349fb06394bf845c64ce15a9cf8f0240",
86+
strip_prefix = "pybind11-2.13.4",
7787
urls = [
7888
"https://storage.googleapis.com/mirror.tensorflow.org/github.com/pybind/pybind11/archive/v2.13.4.tar.gz",
7989
"https://github.com/pybind/pybind11/archive/v2.13.4.tar.gz",
8090
],
81-
sha256 = "efc901aa0aab439a3fea6efeaf930b5a349fb06394bf845c64ce15a9cf8f0240",
82-
strip_prefix = "pybind11-2.13.4",
83-
build_file = "//third_party/pybind11:BUILD.bzl",
8491
)
8592

8693
http_archive(
@@ -95,31 +102,37 @@ load("@org_tensorflow//third_party/py:python_init_rules.bzl", "python_init_rules
95102

96103
python_init_rules()
97104

98-
load("//tensorflow_text:tftext.bzl", "py_deps_profile")
105+
load("//third_party/bazel:py_deps_profile.bzl", "py_deps_profile")
99106

100107
py_deps_profile(
101108
name = "release_or_nightly",
102-
requirements_in = "//oss_scripts/pip_package:requirements.in",
103-
pip_repo_name = "pypi",
104109
deps_map = {
105-
"tensorflow": ["tf-nightly", "tf_header_lib", "libtensorflow_framework"],
106-
"tf-keras": ["tf-keras-nightly"]
110+
"tensorflow": [
111+
"tf-nightly",
112+
"tf_headers",
113+
"tf_header_lib",
114+
"libtensorflow_framework",
115+
],
116+
"tf-keras": ["tf-keras-nightly"],
107117
},
118+
pip_repo_name = "pypi",
119+
requirements_in = "//oss_scripts/pip_package:requirements.in",
108120
switch = {
109-
"IS_NIGHTLY": "nightly"
110-
}
121+
"IS_NIGHTLY": "nightly",
122+
},
111123
)
112124

113125
load("@org_tensorflow//third_party/py:python_init_repositories.bzl", "python_init_repositories")
114126

115127
python_init_repositories(
128+
default_python_version = "system",
116129
requirements = {
117130
"3.9": "//oss_scripts/pip_package:requirements_lock_3_9.txt",
118131
"3.10": "//oss_scripts/pip_package:requirements_lock_3_10.txt",
119132
"3.11": "//oss_scripts/pip_package:requirements_lock_3_11.txt",
120133
"3.12": "//oss_scripts/pip_package:requirements_lock_3_12.txt",
134+
"3.13": "//oss_scripts/pip_package:requirements_lock_3_13.txt",
121135
},
122-
default_python_version = "system",
123136
)
124137

125138
load("@org_tensorflow//third_party/py:python_init_toolchains.bzl", "python_init_toolchains")
@@ -136,18 +149,28 @@ install_deps()
136149

137150
# Initialize TensorFlow dependencies.
138151
load("@org_tensorflow//tensorflow:workspace3.bzl", "tf_workspace3")
152+
139153
tf_workspace3()
154+
140155
load("@org_tensorflow//tensorflow:workspace2.bzl", "tf_workspace2")
156+
141157
tf_workspace2()
158+
142159
load("@org_tensorflow//tensorflow:workspace1.bzl", "tf_workspace1")
160+
143161
tf_workspace1()
162+
144163
load("@org_tensorflow//tensorflow:workspace0.bzl", "tf_workspace0")
164+
145165
tf_workspace0()
146166

147167
# Set up Android.
148168
load("@org_tensorflow//third_party/android:android_configure.bzl", "android_configure")
149-
android_configure(name="local_config_android")
169+
170+
android_configure(name = "local_config_android")
171+
150172
load("@local_config_android//:android.bzl", "android_workspace")
173+
151174
android_workspace()
152175

153176
load(

oss_scripts/configure.sh

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,26 @@ function is_macos() {
3232
# Remove .bazelrc if it already exist
3333
[ -e .bazelrc ] && rm .bazelrc
3434

35-
if [[ $(pip show tensorflow) == *tensorflow* ]] ||
36-
[[ $(pip show tensorflow-macos) == *tensorflow-macos* ]] ||
37-
[[ $(pip show tf-nightly) == *tf-nightly* ]]; then
38-
echo 'Using installed tensorflow.'
39-
else
40-
echo 'Installing tensorflow.'
41-
if [[ "$IS_NIGHTLY" == "nightly" ]]; then
42-
pip install tf-nightly
43-
else
44-
pip install tensorflow==2.18.0
45-
fi
35+
# Don't install tensorflow locally.
36+
if (which python3) | grep -q "python3"; then
37+
installed_python="python3"
38+
elif (which python) | grep -q "python"; then
39+
installed_python="python"
4640
fi
4741

42+
# if [[ $($installed_python -m pip show tensorflow) == *tensorflow* ]] ||
43+
# [[ $($installed_python -m pip show tensorflow-macos) == *tensorflow-macos* ]] ||
44+
# [[ $($installed_python -m pip show tf-nightly) == *tf-nightly* ]]; then
45+
# echo 'Using installed tensorflow.'
46+
# else
47+
# echo 'Installing tensorflow.'
48+
# if [[ "$IS_NIGHTLY" == "nightly" ]]; then
49+
# $installed_python -m pip install --no-deps tf-nightly
50+
# else
51+
# $installed_python -m pip install --no-deps tensorflow==2.20
52+
# fi
53+
# fi
54+
4855
# Copy the current bazelversion of TF.
4956
curl https://raw.githubusercontent.com/tensorflow/tensorflow/master/.bazelversion -o .bazelversion
5057

@@ -54,12 +61,7 @@ curl https://raw.githubusercontent.com/tensorflow/tensorflow/master/.bazelrc -o
5461
sed -i -e 's/build --noincompatible_remove_legacy_whole_archive//' .bazelrc
5562

5663
write_to_bazelrc "build:manylinux2014 --config=release_cpu_linux"
57-
58-
if (which python3) | grep -q "python3"; then
59-
installed_python="python3"
60-
elif (which python) | grep -q "python"; then
61-
installed_python="python"
62-
fi
64+
write_to_bazelrc "test --test_env=TF_USE_LEGACY_KERAS=1"
6365

6466
if [ -z "$HERMETIC_PYTHON_VERSION" ]; then
6567
if [ -n "$PY_VERSION" ]; then
@@ -70,13 +72,16 @@ if [ -z "$HERMETIC_PYTHON_VERSION" ]; then
7072
fi
7173
export HERMETIC_PYTHON_VERSION
7274

73-
echo "TF_VERSION=$TF_VERSION"
74-
REQUIREMENTS_EXTRA_FLAGS="--upgrade"
75-
if [[ "$TF_VERSION" == *"rc"* ]]; then
76-
REQUIREMENTS_EXTRA_FLAGS="$REQUIREMENTS_EXTRA_FLAGS --pre"
77-
fi
78-
79-
bazel run //oss_scripts/pip_package:requirements.update -- $REQUIREMENTS_EXTRA_FLAGS
75+
# NIGHTLY broken, don't try to upgrade deps.
76+
# Only auto-upgrade requirements for nightly and if >= 3.11.
77+
# HERMETIC_PYTHON_VERSION_MINOR="${HERMETIC_PYTHON_VERSION#*.}"
78+
# if [[ "$IS_NIGHTLY" == "nightly" ]] && [[ 11 -le $HERMETIC_PYTHON_VERSION_MINOR ]]; then
79+
# REQUIREMENTS_EXTRA_FLAGS="--upgrade"
80+
# if [[ "$TF_VERSION" == *"rc"* ]]; then
81+
# REQUIREMENTS_EXTRA_FLAGS="$REQUIREMENTS_EXTRA_FLAGS --pre"
82+
# fi
83+
# bazel run //oss_scripts/pip_package:requirements.update -- $REQUIREMENTS_EXTRA_FLAGS
84+
# fi
8085

8186
TF_ABIFLAG=$(bazel run //oss_scripts/pip_package:tensorflow_build_info -- abi)
8287
SHARED_LIBRARY_NAME="libtensorflow_framework.so.2"

oss_scripts/pip_package/BUILD

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ py_binary(
2727
],
2828
)
2929

30-
sh_binary(
30+
py_binary(
3131
name = "build_pip_package",
32-
srcs = ["build_pip_package.sh"],
32+
srcs = ["build_pip_package.py"],
3333
data = [
3434
"LICENSE",
3535
"MANIFEST.in",
3636
"setup.nightly.py",
3737
"setup.py",
3838
"//tensorflow_text",
39+
"//tensorflow_text/core/pybinds:pybinds_binaries",
40+
],
41+
deps = [
42+
"@pypi_setuptools//:pkg",
3943
],
4044
)

0 commit comments

Comments
 (0)