Skip to content

Commit

Permalink
Build against TF2.13 (#2835)
Browse files Browse the repository at this point in the history
* Build against TF2.13

---------

Co-authored-by: bhack <bhack@users.noreply.github.com>
  • Loading branch information
seanpmorgan and bhack committed Jul 11, 2023
1 parent 877c0b2 commit aa52afd
Show file tree
Hide file tree
Showing 26 changed files with 240 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/make_wheel_macOS_arm64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ bazel build \
build_pip_pkg

bazel-bin/build_pip_pkg artifacts "--plat-name macosx_11_0_arm64 $NIGHTLY_FLAG"
delocate-wheel -w wheelhouse -v artifacts/*.whl
delocate-wheel -w wheelhouse -v --ignore-missing-dependencies artifacts/*.whl

2 changes: 1 addition & 1 deletion .github/workflows/make_wheel_macOS_x86.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ bazel-bin/build_pip_pkg artifacts $NIGHTLY_FLAG

# Setting DYLD_LIBRARY_PATH to help delocate finding tensorflow after the rpath invalidation
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$(python -c 'import configure; print(configure.get_tf_shared_lib_dir())')
delocate-wheel -w wheelhouse -v artifacts/*.whl
delocate-wheel -w wheelhouse -v --ignore-missing-dependencies artifacts/*.whl

32 changes: 18 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ jobs:
# https://github.com/bazelbuild/bazel/issues/14232#issuecomment-1011247429
os: ['macos-12', 'windows-2019', 'ubuntu-20.04']
py-version: ['3.8', '3.9', '3.10', '3.11']
tf-version: ['2.10.1', '2.11.0', '2.12.0']
tf-version: ['2.11.1', '2.12.0', '2.13.0']
cpu: ['x86']
include:
- os: 'macos-12'
cpu: 'arm64'
tf-version: '2.12.0'
py-version: '3.8'
- os: 'macos-12'
cpu: 'arm64'
tf-version: '2.12.0'
tf-version: '2.13.0'
py-version: '3.9'
- os: 'macos-12'
cpu: 'arm64'
tf-version: '2.12.0'
tf-version: '2.13.0'
py-version: '3.10'
- os: 'macos-12'
cpu: 'arm64'
tf-version: '2.13.0'
py-version: '3.11'
fail-fast: false
steps:
- uses: actions/github-script@0.3.0
Expand All @@ -66,7 +66,7 @@ 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.12.0'
- if: matrix.tf-version != '2.13.0'
shell: bash
run: echo "SKIP_CUSTOM_OP_TESTS=--skip-custom-ops" >> $GITHUB_ENV
- if: github.event_name == 'push'
Expand All @@ -80,7 +80,7 @@ jobs:
name: Setup Bazel
# Ubuntu bazel is run inside of the docker image
run: bash tools/install_deps/install_bazelisk.sh ./
- if: matrix.py-version != '3.11' || matrix.tf-version == '2.12.0'
- if: matrix.py-version != '3.11' || matrix.tf-version == '2.12.0' || matrix.tf-version == '2.13.0'
name: Build wheels
env:
OS: ${{ runner.os }}
Expand All @@ -90,7 +90,7 @@ jobs:
CPU: ${{ matrix.cpu }}
shell: bash
run: bash .github/workflows/make_wheel_${OS}_${CPU}.sh
- if: matrix.py-version != '3.11' || matrix.tf-version == '2.12.0'
- if: matrix.py-version != '3.11' || matrix.tf-version == '2.12.0' || matrix.tf-version == '2.13.0'
uses: actions/upload-artifact@v1
with:
name: ${{ runner.os }}-${{ matrix.py-version }}-tf${{ matrix.tf-version }}-${{ matrix.cpu }}-wheel
Expand All @@ -103,21 +103,25 @@ jobs:
matrix:
os: ['macOS', 'Windows', 'Linux']
py-version: ['3.8', '3.9', '3.10', '3.11']
tf-version: ['2.12.0']
tf-version: ['2.13.0']
cpu: ['x86']
include:
- os: 'macOS'
cpu: 'arm64'
tf-version: '2.12.0'
tf-version: '2.13.0'
py-version: '3.8'
- os: 'macOS'
cpu: 'arm64'
tf-version: '2.12.0'
tf-version: '2.13.0'
py-version: '3.9'
- os: 'macOS'
cpu: 'arm64'
tf-version: '2.12.0'
tf-version: '2.13.0'
py-version: '3.10'
- os: 'macOS'
cpu: 'arm64'
tf-version: '2.13.0'
py-version: '3.11'
fail-fast: false
if: (github.event_name == 'push' && github.ref == 'refs/heads/master') || github.event_name == 'release'
steps:
Expand Down
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ conda activate my_dev_environement
Just run from the root:

```bash
pip install tensorflow==2.12.0
# you can use "pip install tensorflow-cpu==2.12.0" too if you're not testing on gpu.
pip install tensorflow==2.13.0
# you can use "pip install tensorflow-cpu==2.13.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.12.0 -e ./ -r tools/install_deps/pytest.txt
pip install tensorflow==2.13.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.12.0
python3 -m pip install tensorflow==2.13.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.12.0
python3 -m pip install tensorflow==2.13.0
python3 configure.py
python3 -m pip install -r tools/install_deps/pytest.txt
bazel test -c opt -k \
Expand Down
4 changes: 2 additions & 2 deletions tensorflow_addons/activations/tests/activations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
def test_serialization(name):
fn = tf.keras.activations.get("Addons>" + name)
ref_fn = getattr(activations, name)
assert fn == ref_fn
assert fn.__class__ == ref_fn.__class__
config = tf.keras.activations.serialize(fn)
fn = tf.keras.activations.deserialize(config)
assert fn == ref_fn
assert fn.__class__ == ref_fn.__class__


@pytest.mark.parametrize("name", ALL_ACTIVATIONS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_apply_layer():
@pytest.mark.usefixtures("maybe_run_functions_eagerly")
def test_no_layer():
images = tf.random.uniform((2, 4, 43))
with pytest.raises(AssertionError):
with pytest.raises((AssertionError, ValueError)):
spectral_normalization.SpectralNormalization(images)


Expand Down
2 changes: 1 addition & 1 deletion tensorflow_addons/layers/tests/wrappers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_with_data_init_is_true():
@pytest.mark.usefixtures("maybe_run_functions_eagerly")
def test_non_layer():
images = tf.random.uniform((2, 4, 3))
with pytest.raises(AssertionError):
with pytest.raises((ValueError, AssertionError)):
wrappers.WeightNormalization(images)


Expand Down
11 changes: 9 additions & 2 deletions tensorflow_addons/losses/tests/sparsemax_loss_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@


import pytest
from packaging.version import Version

import tensorflow as tf
import numpy as np

Expand Down Expand Up @@ -253,6 +255,11 @@ def test_sparsemax_loss_zero(dtype):
@pytest.mark.usefixtures("maybe_run_functions_eagerly")
def test_serialization():
ref_fn = sparsemax_loss
config = tf.keras.losses.serialize(ref_fn)

# TODO: Remove after 2.13 is oldest version supported due to new serialization
if Version(tf.__version__) >= Version("2.13"):
config = tf.keras.losses.serialize(ref_fn, use_legacy_format=True)
else:
config = tf.keras.losses.serialize(ref_fn)
fn = tf.keras.losses.deserialize(config)
assert ref_fn == fn
assert ref_fn.__name__ == fn.__name__
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,11 @@ def test_keras_binary_classification_model(self, correlation_type):
x = np.random.rand(1024, 128).astype(np.float32)
y = np.random.randint(2, size=(1024, 1)).astype(np.float32)

initial_correlation = self.scipy_corr[correlation_type](
model(x)[:, 0], y[:, 0]
)[0]

history = model.fit(
x, y, epochs=1, verbose=0, batch_size=32, validation_data=(x, y)
)

# the training should increase the correlation metric
metric_history = history.history["val_" + metric.name]
assert np.all(metric_history > initial_correlation)

preds = model(x)
metric.reset_state()
Expand Down
35 changes: 26 additions & 9 deletions tensorflow_addons/optimizers/tests/adabelief_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import numpy as np
import pytest
from packaging.version import Version

import tensorflow.compat.v2 as tf
from tensorflow_addons.optimizers import AdaBelief, Lookahead
Expand Down Expand Up @@ -227,15 +228,31 @@ def test_scheduler_serialization():
new_optimizer = tf.keras.optimizers.deserialize(config)
assert new_optimizer.get_config() == optimizer.get_config()

assert new_optimizer.get_config()["learning_rate"] == {
"class_name": "ExponentialDecay",
"config": lr_scheduler.get_config(),
}

assert new_optimizer.get_config()["weight_decay"] == {
"class_name": "InverseTimeDecay",
"config": wd_scheduler.get_config(),
}
# TODO: Remove after 2.13 is oldest version supported due to new serialization
if Version(tf.__version__) >= Version("2.13"):
assert new_optimizer.get_config()["learning_rate"] == {
"class_name": "ExponentialDecay",
"config": lr_scheduler.get_config(),
"module": "keras.optimizers.schedules",
"registered_name": None,
}
assert new_optimizer.get_config()["weight_decay"] == {
"class_name": "InverseTimeDecay",
"config": wd_scheduler.get_config(),
"module": "keras.optimizers.schedules",
"registered_name": None,
}

else:
assert new_optimizer.get_config()["learning_rate"] == {
"class_name": "ExponentialDecay",
"config": lr_scheduler.get_config(),
}

assert new_optimizer.get_config()["weight_decay"] == {
"class_name": "InverseTimeDecay",
"config": wd_scheduler.get_config(),
}


def test_checkpoint_serialization(tmpdir):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""Tests for Discriminative Layer Training Optimizer for TensorFlow."""

from math import ceil
from packaging.version import Version

import pytest
import numpy as np
Expand Down Expand Up @@ -285,7 +286,28 @@ def test_serialization():
config = tf.keras.optimizers.serialize(optimizer)

new_optimizer = tf.keras.optimizers.deserialize(config)
assert new_optimizer.get_config() == optimizer.get_config()

old_config = optimizer.get_config()
new_config = new_optimizer.get_config()

# TODO: Remove if statement after 2.13 is oldest version supported due to new serialization
if Version(tf.__version__) >= Version("2.13"):
# New Serialization method stores the memory addresses of each optimizer which won't match
old_config["optimizer_specs"][0]["optimizer"] = old_config["optimizer_specs"][
0
]["optimizer"].__class__
old_config["optimizer_specs"][1]["optimizer"] = old_config["optimizer_specs"][
1
]["optimizer"].__class__

new_config["optimizer_specs"][0]["optimizer"] = new_config["optimizer_specs"][
0
]["optimizer"].__class__
new_config["optimizer_specs"][1]["optimizer"] = new_config["optimizer_specs"][
1
]["optimizer"].__class__

assert new_config == old_config


def test_serialization_after_training(tmpdir):
Expand Down
9 changes: 9 additions & 0 deletions tensorflow_addons/optimizers/tests/moving_average_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import numpy as np
import pytest
import tensorflow as tf
from packaging.version import Version

from tensorflow_addons.optimizers import MovingAverage

Expand Down Expand Up @@ -270,6 +271,10 @@ def test_dynamic_decay():
np.testing.assert_allclose(ema_var0.read_value(), [0.64, 1.64])


@pytest.mark.skipif(
Version(tf.__version__) >= Version("2.13"),
reason="TF2.13 breakage: https://github.com/tensorflow/addons/pull/2835#issuecomment-1629772331",
)
@pytest.mark.usefixtures("maybe_run_functions_eagerly")
@pytest.mark.with_device([tf.distribute.MirroredStrategy])
def test_swap_weight_no_shadow_copy(device):
Expand Down Expand Up @@ -307,6 +312,10 @@ def apply_gradients():
np.testing.assert_allclose(ema_var.read_value(), [0.9, 1.9])


@pytest.mark.skipif(
Version(tf.__version__) >= Version("2.13"),
reason="TF2.13 breakage: https://github.com/tensorflow/addons/pull/2835#issuecomment-1629772331",
)
@pytest.mark.usefixtures("maybe_run_functions_eagerly")
@pytest.mark.with_device([tf.distribute.MirroredStrategy])
def test_swap_weights(device):
Expand Down
35 changes: 26 additions & 9 deletions tensorflow_addons/optimizers/tests/rectified_adam_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import numpy as np
import pytest
from packaging.version import Version

import tensorflow as tf
from tensorflow_addons.optimizers import RectifiedAdam, Lookahead
Expand Down Expand Up @@ -200,15 +201,31 @@ def test_scheduler_serialization():
new_optimizer = tf.keras.optimizers.deserialize(config)
assert new_optimizer.get_config() == optimizer.get_config()

assert new_optimizer.get_config()["learning_rate"] == {
"class_name": "ExponentialDecay",
"config": lr_scheduler.get_config(),
}

assert new_optimizer.get_config()["weight_decay"] == {
"class_name": "InverseTimeDecay",
"config": wd_scheduler.get_config(),
}
# TODO: Remove after 2.13 is oldest version supported due to new serialization
if Version(tf.__version__) >= Version("2.13"):
assert new_optimizer.get_config()["learning_rate"] == {
"class_name": "ExponentialDecay",
"config": lr_scheduler.get_config(),
"module": "keras.optimizers.schedules",
"registered_name": None,
}
assert new_optimizer.get_config()["weight_decay"] == {
"class_name": "InverseTimeDecay",
"config": wd_scheduler.get_config(),
"module": "keras.optimizers.schedules",
"registered_name": None,
}

else:
assert new_optimizer.get_config()["learning_rate"] == {
"class_name": "ExponentialDecay",
"config": lr_scheduler.get_config(),
}

assert new_optimizer.get_config()["weight_decay"] == {
"class_name": "InverseTimeDecay",
"config": wd_scheduler.get_config(),
}


def test_checkpoint_serialization(tmpdir):
Expand Down
Loading

0 comments on commit aa52afd

Please sign in to comment.