From 83dafb0c2d9248739aa1bddd93655656b1658451 Mon Sep 17 00:00:00 2001 From: Khurram Ghani <113982802+khurram-ghani@users.noreply.github.com> Date: Mon, 8 Jan 2024 14:35:40 +0000 Subject: [PATCH] Support TF 2.15 (#101) * Add TF=2.15 and TFP=0.23 * Exclude TF 2.15 with python 3.8 * Use older mypy version with python 3.7 * Use older mypy for py 37, 38, 39 * Exclude TF 2.15 with python 3.9 * Revert "Exclude TF 2.15 with python 3.9" This reverts commit f9d95b5c5ee57445018c789abe42416c9cbcdaab. * Revert "Use older mypy for py 37, 38, 39" This reverts commit 3e4f98c150938109ebb5cc337b870ff690e392f1. * Separate requirements for python 3.8 * Include python 3.9 in new requirements file * Fix test by using sets directly with id Behavior of tensorflow ObjectIdentitySet has change in 2.15, resulting in the set equality comparing wrappers instead of wrapped values. See https://github.com/tensorflow/tensorflow/commit/bc28335cbd05c29a8a0868bfb107d4b940a79680. * Also include intermediate TF versions * Add exclude * Add exclude * Fix tfp versions --- .github/workflows/quality-check.yaml | 24 +++++++++++++++-- CONTRIBUTORS.md | 1 + Makefile | 4 ++- gpflux/version.py | 2 +- setup.py | 6 ++--- .../layers/test_dedup_trackable_layer.py | 10 +++---- tests_requirements_37.txt | 2 +- tests_requirements_38_39.txt | 27 +++++++++++++++++++ 8 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 tests_requirements_38_39.txt diff --git a/.github/workflows/quality-check.yaml b/.github/workflows/quality-check.yaml index 5eb7f985..5eb76654 100644 --- a/.github/workflows/quality-check.yaml +++ b/.github/workflows/quality-check.yaml @@ -22,7 +22,7 @@ jobs: strategy: matrix: python-version: ["3.7", "3.8", "3.9", "3.10"] - tensorflow: ["~=2.5.0", "~=2.6.0", "~=2.7.0", "~=2.8.0", "~=2.9.0", "~=2.10.0", "~=2.11.0", "~=2.12.0"] + tensorflow: ["~=2.5.0", "~=2.6.0", "~=2.7.0", "~=2.8.0", "~=2.9.0", "~=2.10.0", "~=2.11.0", "~=2.12.0", "~=2.13.0", "~=2.14.0", "~=2.15.0"] include: - tensorflow: "~=2.5.0" keras: "~=2.6.0" @@ -47,7 +47,16 @@ jobs: tensorflow-probability: "~=0.19.0" - tensorflow: "~=2.12.0" keras: "~=2.12.0" - tensorflow-probability: "~=0.19.0" # sic! no new tfp release + tensorflow-probability: "~=0.20.0" + - tensorflow: "~=2.13.0" + keras: "~=2.13.0" + tensorflow-probability: "~=0.21.0" + - tensorflow: "~=2.14.0" + keras: "~=2.14.0" + tensorflow-probability: "~=0.22.0" + - tensorflow: "~=2.15.0" + keras: "~=2.15.0" + tensorflow-probability: "~=0.23.0" exclude: # These older versions of TensorFlow don't work with Python 3.10: - python-version: "3.10" @@ -59,6 +68,17 @@ jobs: # These newer versions of TensorFlow don't work with Python 3.7: - python-version: "3.7" tensorflow: "~=2.12.0" + - python-version: "3.7" + tensorflow: "~=2.13.0" + - python-version: "3.7" + tensorflow: "~=2.14.0" + - python-version: "3.7" + tensorflow: "~=2.15.0" + # These newer versions of TensorFlow don't work with Python 3.8: + - python-version: "3.8" + tensorflow: "~=2.14.0" + - python-version: "3.8" + tensorflow: "~=2.15.0" name: Python-${{ matrix.python-version }} tensorflow${{ matrix.tensorflow }} env: diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 56a4d0a1..3fe05341 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -18,4 +18,5 @@ Because GitHub's [graph of contributors](http://github.com/secondmind-labs/GPflu [Jesper Nielsen](https://github.com/jesnie) [Sebastian Ober](https://github.com/sebastianober) [Simon Chiu](https://github.com/sc336) +[Khurram Ghani](https://github.com/khurram-ghani) diff --git a/Makefile b/Makefile index e97edbcf..0bdbcac0 100644 --- a/Makefile +++ b/Makefile @@ -25,9 +25,11 @@ LINT_FILE_IGNORES = "$(LIB_NAME)/__init__.py:F401,F403 \ $(LIB_NAME)/sampling/__init__.py:F401 \ $(LIB_NAME)/utils/__init__.py:F401" -# Python 3.7 uses a separate test requirements file +# Older Python versions use separate test requirements files ifeq ("$(VERSION_PYTHON)", "3.7") TEST_REQUIREMENTS = "tests_requirements_37.txt" +else ifeq ($(filter $(VERSION_PYTHON),3.8 3.9),$(VERSION_PYTHON)) + TEST_REQUIREMENTS = "tests_requirements_38_39.txt" else TEST_REQUIREMENTS = "tests_requirements.txt" endif diff --git a/gpflux/version.py b/gpflux/version.py index 58994b15..5c5710ac 100644 --- a/gpflux/version.py +++ b/gpflux/version.py @@ -15,4 +15,4 @@ # """Adds __version__""" -__version__ = "0.4.2" +__version__ = "0.4.3" diff --git a/setup.py b/setup.py index ce5dcf8b..d2cff5c4 100644 --- a/setup.py +++ b/setup.py @@ -9,11 +9,11 @@ "gpflow>=2.6.3", "numpy", "scipy", - "tensorflow>=2.5.0,<2.13.0; platform_system!='Darwin' or platform_machine!='arm64'", + "tensorflow>=2.5.0,<=2.15.0; platform_system!='Darwin' or platform_machine!='arm64'", # NOTE: Support of Apple Silicon MacOS platforms is in an experimental mode - "tensorflow-macos>=2.5.0,<2.13.0; platform_system=='Darwin' and platform_machine=='arm64'", + "tensorflow-macos>=2.5.0,<=2.15.0; platform_system=='Darwin' and platform_machine=='arm64'", # NOTE: once we require tensorflow-probability>=0.12, we can remove our custom deepcopy handling - "tensorflow-probability>=0.13.0,<0.20.0", + "tensorflow-probability>=0.13.0,<=0.23.0", ] with open("README.md", "r") as file: diff --git a/tests/gpflux/layers/test_dedup_trackable_layer.py b/tests/gpflux/layers/test_dedup_trackable_layer.py index 93d4efc4..6f110e07 100644 --- a/tests/gpflux/layers/test_dedup_trackable_layer.py +++ b/tests/gpflux/layers/test_dedup_trackable_layer.py @@ -19,7 +19,6 @@ import pytest import tensorflow as tf from tensorflow.python.ops.resource_variable_ops import ResourceVariable -from tensorflow.python.util import object_identity import gpflow from gpflow.utilities import parameter_dict @@ -141,11 +140,10 @@ def test_weights_equals_deduplicated_parameter_dict(model): # We filter out the parameters of type ResourceVariable. # They have been added to the model by the `add_metric` call in the layer. parameters = [p for p in parameter_dict(model).values() if not isinstance(p, ResourceVariable)] - variables = map(lambda p: p.unconstrained_variable, parameters) - deduplicate_variables = object_identity.ObjectIdentitySet(variables) + variables = {id(p.unconstrained_variable) for p in parameters} weights = model.trainable_weights - assert len(weights) == len(deduplicate_variables) + assert len(weights) == len(variables) - weights_set = object_identity.ObjectIdentitySet(weights) - assert weights_set == deduplicate_variables + weights_set = {id(w) for w in weights} + assert weights_set == variables diff --git a/tests_requirements_37.txt b/tests_requirements_37.txt index 25679f42..4984bce9 100644 --- a/tests_requirements_37.txt +++ b/tests_requirements_37.txt @@ -6,7 +6,7 @@ codecov click==8.0.4 flake8==4.0.1 isort==5.10.1 -mypy +mypy<1.4.0 # Newer mypy versions cause issues with Python 3.7 ('Self' from 'typing_extensions'). pytest pytest-cov pytest-random-order diff --git a/tests_requirements_38_39.txt b/tests_requirements_38_39.txt new file mode 100644 index 00000000..dc553097 --- /dev/null +++ b/tests_requirements_38_39.txt @@ -0,0 +1,27 @@ +# Test requirements specific to Python 3.8 and 3.9 + +# Code quality tools: +black==21.7b0 +codecov +click==8.0.4 +flake8==4.0.1 +isort==5.10.1 +mypy<1.4.0 # Newer mypy versions cause issues with older Python ('Self' from 'typing_extensions'). +pytest +pytest-cov +pytest-random-order +pytest-mock + +# For mypy stubs: +types-Deprecated +numpy + +tqdm + +# Notebook tests: +jupytext +nbformat +nbconvert +jupyter_client +ipykernel +tornado