Skip to content

Commit

Permalink
Build Against TF 2.10 (#2744)
Browse files Browse the repository at this point in the history
* Build TF 2.10rc0
* Build with C++17

Co-authored-by: bhack <bhack@users.noreply.github.com>
Co-authored-by: Lukas Geiger <lukas.geiger94@gmail.com>
  • Loading branch information
3 people authored Sep 20, 2022
1 parent 7a98c5f commit 2e772fd
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 60 deletions.
1 change: 1 addition & 0 deletions .github/workflows/make_wheel_Linux_x86.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ DOCKER_BUILDKIT=1 docker build \
--build-arg TF_VERSION \
--build-arg NIGHTLY_FLAG \
--build-arg NIGHTLY_TIME \
--build-arg SKIP_CUSTOM_OP_TESTS \
./
2 changes: 1 addition & 1 deletion .github/workflows/make_wheel_Windows_x86.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ python --version
python -m pip install --default-timeout=1000 wheel setuptools tensorflow==$TF_VERSION

# Test
bash ./tools/testing/build_and_run_tests.sh
bash ./tools/testing/build_and_run_tests.sh $SKIP_CUSTOM_OP_TESTS

# Clean
bazel clean
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/make_wheel_macOS_arm64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$(python -c 'import configure; print
# For dynamic linking, we want the ARM version of TensorFlow.
# Since we cannot run it on x86 so we need to force pip to install it regardless
python -m pip install \
--platform=macosx_11_0_arm64 \
--platform=macosx_12_0_arm64 \
--no-deps \
--target=$(python -c 'import site; print(site.getsitepackages()[0])') \
--upgrade \
tensorflow-macos==$TF_VERSION

bazel build \
--cpu=darwin_arm64 \
--copt -mmacosx-version-min=11.0 \
--linkopt -mmacosx-version-min=11.0 \
--copt -mmacosx-version-min=12.0 \
--linkopt -mmacosx-version-min=12.0 \
--noshow_progress \
--noshow_loading_progress \
--verbose_failures \
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/make_wheel_macOS_x86.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ python --version
python -m pip install --default-timeout=1000 delocate==0.10.2 wheel setuptools tensorflow==$TF_VERSION

# Test
bash ./tools/testing/build_and_run_tests.sh
bash ./tools/testing/build_and_run_tests.sh $SKIP_CUSTOM_OP_TESTS

# Clean
bazel clean
Expand All @@ -16,8 +16,8 @@ bazel clean
python configure.py

bazel build \
--copt -mmacosx-version-min=10.13 \
--linkopt -mmacosx-version-min=10.13 \
--copt=-mmacosx-version-min=10.14 \
--linkopt=-mmacosx-version-min=10.14 \
--noshow_progress \
--noshow_loading_progress \
--verbose_failures \
Expand Down
30 changes: 15 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,22 @@ jobs:
matrix:
# To switch on windows-2022/latest, please verify the bazel version:
# https://github.com/bazelbuild/bazel/issues/14232#issuecomment-1011247429
os: ['macos-10.15', 'windows-2019', 'ubuntu-18.04']
os: ['macos-12', 'windows-2019', 'ubuntu-18.04']
py-version: ['3.7', '3.8', '3.9', '3.10']
tf-version: ['2.7.3', '2.8.2', '2.9.1']
tf-version: ['2.8.2', '2.9.1', '2.10.0']
cpu: ['x86']
exclude:
- py-version: '3.10'
tf-version: '2.7.3'
include:
- os: 'macos-11'
- os: 'macos-12'
cpu: 'arm64'
tf-version: '2.9.1'
tf-version: '2.10.0'
py-version: '3.8'
- os: 'macos-11'
- os: 'macos-12'
cpu: 'arm64'
tf-version: '2.9.1'
tf-version: '2.10.0'
py-version: '3.9'
- os: 'macos-11'
- os: 'macos-12'
cpu: 'arm64'
tf-version: '2.9.1'
tf-version: '2.10.0'
py-version: '3.10'
fail-fast: false
steps:
Expand All @@ -69,6 +66,9 @@ jobs:
script: |
const commit_details = await github.git.getCommit({owner: context.repo.owner, repo: context.repo.repo, commit_sha: context.sha});
return commit_details.data.author.date
- if: matrix.tf-version != '2.10.0'
shell: bash
run: echo "SKIP_CUSTOM_OP_TESTS=--skip-custom-ops" >> $GITHUB_ENV
- if: github.event_name == 'push'
shell: bash
run: echo "NIGHTLY_FLAG=--nightly" >> $GITHUB_ENV
Expand Down Expand Up @@ -101,20 +101,20 @@ jobs:
matrix:
os: ['macOS', 'Windows', 'Linux']
py-version: ['3.7', '3.8', '3.9', '3.10']
tf-version: ['2.9.1']
tf-version: ['2.10.0']
cpu: ['x86']
include:
- os: 'macOS'
cpu: 'arm64'
tf-version: '2.9.1'
tf-version: '2.10.0'
py-version: '3.8'
- os: 'macOS'
cpu: 'arm64'
tf-version: '2.9.1'
tf-version: '2.10.0'
py-version: '3.9'
- os: 'macOS'
cpu: 'arm64'
tf-version: '2.9.1'
tf-version: '2.10.0'
py-version: '3.10'
fail-fast: false
if: (github.event_name == 'push' && github.ref == 'refs/heads/master') || github.event_name == 'release'
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Just run from the root:

```bash
pip install tensorflow==2.8
# you can use "pip install tensorflow-cpu==2.9.1" too if you're not testing on gpu.
# you can use "pip install tensorflow-cpu==2.10.0" too if you're not testing on gpu.
pip install -e ./
```

Expand Down Expand Up @@ -262,7 +262,7 @@ If you need a custom C++/Cuda op for your test, compile your ops with

```bash
python configure.py
pip install tensorflow==2.9 -e ./ -r tools/install_deps/pytest.txt
pip install tensorflow==2.10.0 -e ./ -r tools/install_deps/pytest.txt
bash tools/install_so_files.sh # Linux/macos/WSL2
sh tools/install_so_files.sh # PowerShell
```
Expand Down Expand Up @@ -290,7 +290,7 @@ docker run --gpus all --rm -it -v ${PWD}:/addons -w /addons gcr.io/tensorflow-te

Configure:
```bash
python3 -m pip install tensorflow==2.9
python3 -m pip install tensorflow==2.10.0
python3 ./configure.py # Links project with TensorFlow dependency
```

Expand Down Expand Up @@ -329,7 +329,7 @@ quickly, as Bazel has great support for caching and distributed testing.
To test with Bazel:

```bash
python3 -m pip install tensorflow==2.9
python3 -m pip install tensorflow==2.10.0
python3 configure.py
python3 -m pip install -r tools/install_deps/pytest.txt
bazel test -c opt -k \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,4 @@ improve the guide!).

## License
[Apache License 2.0](LICENSE)

6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ cuda_configure(name = "local_config_cuda")

http_archive(
name = "org_tensorflow",
sha256 = "8087cb0c529f04a4bfe480e49925cd64a904ad16d8ec66b98e2aacdfd53c80ff",
strip_prefix = "tensorflow-2.9.0",
sha256 = "b5a1bb04c84b6fe1538377e5a1f649bb5d5f0b2e3625a3c526ff3a8af88633e8",
strip_prefix = "tensorflow-2.10.0",
urls = [
"https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.9.0.tar.gz",
"https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.10.0.tar.gz",
],
)

Expand Down
4 changes: 2 additions & 2 deletions build_deps/build_pip_pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ function main() {
BUILD_CMD="setup.py bdist_wheel --platlib-patch"
if is_macos; then
if [[ x"$(arch)" == x"arm64" ]]; then
BUILD_CMD="${BUILD_CMD} --plat-name macosx_11_0_arm64"
BUILD_CMD="${BUILD_CMD} --plat-name macosx_12_0_arm64"
else
BUILD_CMD="${BUILD_CMD} --plat-name macosx_10_15_x86_64"
BUILD_CMD="${BUILD_CMD} --plat-name macosx_10_14_x86_64"
fi
PYTHON=python3
else
Expand Down
1 change: 1 addition & 0 deletions build_deps/tf_dependency/build_defs.bzl.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Addons Build Definitions inherited from TensorFlow Core

D_GLIBCXX_USE_CXX11_ABI = "%{tf_cx11_abi}"
CPLUSPLUS_VERSION = "%{tf_cplusplus_ver}"
5 changes: 5 additions & 0 deletions build_deps/tf_dependency/tf_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ _TF_SHARED_LIBRARY_NAME = "TF_SHARED_LIBRARY_NAME"

_TF_CXX11_ABI_FLAG = "TF_CXX11_ABI_FLAG"

_TF_CPLUSPLUS_VER = "TF_CPLUSPLUS_VER"

def _tpl(repository_ctx, tpl, substitutions = {}, out = None):
if not out:
out = tpl
Expand Down Expand Up @@ -204,6 +206,7 @@ def _tf_pip_impl(repository_ctx):
tf_shared_library_name = repository_ctx.os.environ[_TF_SHARED_LIBRARY_NAME]
tf_shared_library_path = "%s/%s" % (tf_shared_library_dir, tf_shared_library_name)
tf_cx11_abi = "-D_GLIBCXX_USE_CXX11_ABI=%s" % (repository_ctx.os.environ[_TF_CXX11_ABI_FLAG])
tf_cplusplus_ver = "-std=%s" % repository_ctx.os.environ[_TF_CPLUSPLUS_VER]

tf_shared_library_rule = _symlink_genrule_for_dir(
repository_ctx,
Expand All @@ -225,6 +228,7 @@ def _tf_pip_impl(repository_ctx):
"build_defs.bzl",
{
"%{tf_cx11_abi}": tf_cx11_abi,
"%{tf_cplusplus_ver}": tf_cplusplus_ver,
},
)

Expand All @@ -234,6 +238,7 @@ tf_configure = repository_rule(
_TF_SHARED_LIBRARY_DIR,
_TF_SHARED_LIBRARY_NAME,
_TF_CXX11_ABI_FLAG,
_TF_CPLUSPLUS_VER,
],
implementation = _tf_pip_impl,
)
20 changes: 16 additions & 4 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import tensorflow as tf

from packaging.version import Version

_TFA_BAZELRC = ".bazelrc"


Expand Down Expand Up @@ -81,6 +83,13 @@ def get_tf_header_dir():
return tf_header_dir


def get_cpp_version():
cpp_version = "c++14"
if Version(tf.__version__) >= Version("2.10"):
cpp_version = "c++17"
return cpp_version


def get_tf_shared_lib_dir():
import tensorflow as tf

Expand Down Expand Up @@ -127,6 +136,9 @@ def create_build_configuration():
write_action_env("TF_SHARED_LIBRARY_NAME", get_shared_lib_name())
write_action_env("TF_CXX11_ABI_FLAG", tf.sysconfig.CXX11_ABI_FLAG)

# This should be replaced with a call to tf.sysconfig if it's added
write_action_env("TF_CPLUSPLUS_VER", get_cpp_version())

write("build --spawn_strategy=standalone")
write("build --strategy=Genrule=standalone")
write("build --experimental_repo_remote_exec")
Expand All @@ -143,14 +155,14 @@ def create_build_configuration():
write("build:windows --copt=/experimental:preprocessor")
write("build:windows --host_copt=/experimental:preprocessor")
write("build:windows --copt=/arch=AVX")
write("build:windows --cxxopt=/std:c++14")
write("build:windows --host_cxxopt=/std:c++14")
write("build:windows --cxxopt=/std:" + get_cpp_version())
write("build:windows --host_cxxopt=/std:" + get_cpp_version())

if is_macos() or is_linux():
if not is_linux_ppc64le() and not is_linux_arm() and not is_linux_aarch64():
write("build --copt=-mavx")
write("build --cxxopt=-std=c++14")
write("build --host_cxxopt=-std=c++14")
write("build --cxxopt=-std=" + get_cpp_version())
write("build --host_cxxopt=-std=" + get_cpp_version())

if os.getenv("TF_NEED_CUDA", "0") == "1":
print("> Building GPU & CPU ops")
Expand Down
4 changes: 2 additions & 2 deletions tensorflow_addons/tensorflow_addons.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@local_config_tf//:build_defs.bzl", "D_GLIBCXX_USE_CXX11_ABI")
load("@local_config_tf//:build_defs.bzl", "CPLUSPLUS_VERSION", "D_GLIBCXX_USE_CXX11_ABI")
load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda", "if_cuda_is_configured")

def custom_op_library(
Expand Down Expand Up @@ -51,7 +51,7 @@ def custom_op_library(
"/DNOGDI",
"/UTF_COMPILE_LIBRARY",
],
"//conditions:default": ["-pthread", "-std=c++14", D_GLIBCXX_USE_CXX11_ABI],
"//conditions:default": ["-pthread", CPLUSPLUS_VERSION, D_GLIBCXX_USE_CXX11_ABI],
})

native.cc_binary(
Expand Down
4 changes: 2 additions & 2 deletions tensorflow_addons/utils/resource_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import tensorflow as tf

INCLUSIVE_MIN_TF_VERSION_FOR_ABI_COMPATIBILITY = "2.9.0"
EXCLUSIVE_MAX_TF_VERSION_FOR_ABI_COMPATIBILITY = "2.10.0"
INCLUSIVE_MIN_TF_VERSION_FOR_ABI_COMPATIBILITY = "2.10.0"
EXCLUSIVE_MAX_TF_VERSION_FOR_ABI_COMPATIBILITY = "2.11.0"
abi_warning_already_raised = False
SKIP_CUSTOM_OPS = False

Expand Down
23 changes: 14 additions & 9 deletions tensorflow_addons/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
import pytest
import tensorflow as tf

from packaging.version import Version
from tensorflow_addons import options
from tensorflow_addons.utils import resource_loader

if tf.__version__[:3] > "2.8":
if Version(tf.__version__) >= Version("2.9"):
from keras.testing_infra.test_utils import layer_test # noqa: F401
else:
from keras.testing_utils import layer_test # noqa: F401
Expand All @@ -48,7 +49,8 @@ def is_gpu_available():
tf.config.threading.set_inter_op_parallelism_threads(1)

if is_gpu_available():
# We use only the first gpu at the moment. That's enough for most use cases.
# We split each of the physical GPUs to 2 logical GPUs, and use only the
# first gpu at the moment. That's enough for most use cases.
# split the first gpu into chunks of 100MB per virtual device.
# It's the user's job to limit the amount of pytest workers depending
# on the available memory.
Expand All @@ -57,12 +59,13 @@ def is_gpu_available():
# Each worker has two virtual devices.
# When running on gpu, only the first device is used. The other one is used
# in distributed strategies.
first_gpu = tf.config.list_physical_devices("GPU")[0]
virtual_gpus = [
tf.config.LogicalDeviceConfiguration(memory_limit=100) for _ in range(2)
]

tf.config.set_logical_device_configuration(first_gpu, virtual_gpus)
physical_gpus = tf.config.list_physical_devices("GPU")
tf.config.set_visible_devices(physical_gpus[0], "GPU")
for physical_gpu in physical_gpus:
virtual_gpus = [
tf.config.LogicalDeviceConfiguration(memory_limit=100) for _ in range(2)
]
tf.config.set_logical_device_configuration(physical_gpu, virtual_gpus)


def finalizer():
Expand Down Expand Up @@ -180,10 +183,12 @@ def device(request):
with strategy.scope():
yield strategy
elif isinstance(requested_device, str):
if requested_device in ["cpu", "gpu"]:
if requested_device == "gpu":
# we use GPU:0 because the virtual device we created is the
# only one in the first GPU (so first in the list of virtual devices).
requested_device += ":0"
elif requested_device == "cpu":
requested_device = "cpu"
else:
raise KeyError("Invalid device: " + requested_device)
with tf.device(requested_device):
Expand Down
6 changes: 3 additions & 3 deletions tensorflow_addons/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
"""Define TensorFlow Addons version information."""

# Required TensorFlow version [min, max)
INCLUSIVE_MIN_TF_VERSION = "2.7.0"
EXCLUSIVE_MAX_TF_VERSION = "2.10.0"
INCLUSIVE_MIN_TF_VERSION = "2.8.0"
EXCLUSIVE_MAX_TF_VERSION = "2.11.0"

# We follow Semantic Versioning (https://semver.org/)
_MAJOR_VERSION = "0"
_MINOR_VERSION = "17"
_MINOR_VERSION = "18"
_PATCH_VERSION = "0"

# When building releases, we can update this value on the release branch to
Expand Down
2 changes: 1 addition & 1 deletion tools/build_dev_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -x -e

docker build \
-f tools/docker/dev_container.Dockerfile \
--build-arg TF_VERSION=2.9.1 \
--build-arg TF_VERSION=2.10.0 \
--build-arg TF_PACKAGE=tensorflow \
--build-arg PY_VERSION=$PY_VERSION \
--no-cache \
Expand Down
Loading

0 comments on commit 2e772fd

Please sign in to comment.