From b5798f6e2502ca535b1e651db8703e738ad1b027 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Mon, 30 Mar 2020 10:38:40 +0000 Subject: [PATCH 1/2] Added a warning when importing addons and using the wrong version. --- tensorflow_addons/__init__.py | 4 +- tensorflow_addons/utils/ensure_tf_install.py | 65 ++++++++++++-------- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/tensorflow_addons/__init__.py b/tensorflow_addons/__init__.py index d5527ecb6e..2afa5c13ad 100644 --- a/tensorflow_addons/__init__.py +++ b/tensorflow_addons/__init__.py @@ -13,9 +13,9 @@ # limitations under the License. # ============================================================================== """Useful extra functionality for TensorFlow maintained by SIG-addons.""" -from tensorflow_addons.utils.ensure_tf_install import _ensure_tf_install +from tensorflow_addons.utils.ensure_tf_install import _check_tf_version -_ensure_tf_install() +_check_tf_version() # Local project imports from tensorflow_addons import activations diff --git a/tensorflow_addons/utils/ensure_tf_install.py b/tensorflow_addons/utils/ensure_tf_install.py index e5dcae52fe..e53057bd09 100644 --- a/tensorflow_addons/utils/ensure_tf_install.py +++ b/tensorflow_addons/utils/ensure_tf_install.py @@ -14,43 +14,56 @@ # ============================================================================== -# Ensure TensorFlow is importable and its version is sufficiently recent. This +# Ensure the TensorFlow version is in the right range. This # needs to happen before anything else, since the imports below will try to -# import tensorflow, too. +# import TensorFlow, too. from distutils.version import LooseVersion import warnings import tensorflow as tf +MIN_TF_VERSION = "2.1.0" +MAX_TF_VERSION = "2.3.0" -warning_template = """ -This version of TensorFlow Addons requires TensorFlow {required}. -Detected an installation of version {present}. -While some functions might work, TensorFlow Addons was not tested -with this TensorFlow version. Also custom ops were not compiled -against this version of TensorFlow. If you use custom ops, -you might get errors (segmentation faults for example). +def _check_tf_version(): + """Warn the user if the version of TensorFlow used is not supported. -It might help you to fallback to pure Python ops with -TF_ADDONS_PY_OPS . To do that, see -https://github.com/tensorflow/addons#gpucpu-custom-ops + This is not a check for ABI compatibility. This check only ensure that + we support this TensorFlow version if the user uses only Addons' Python code. + """ -If you encounter errors, do *not* file bugs in GitHub because -the version of TensorFlow you are using is not supported. -""" + if "dev" in tf.__version__: + warnings.warn( + "You are currently using a nightly version of TensorFlow ({}). \n" + "TensorFlow Addons offers no support for the nightly versions of " + "TensorFlow. Some things might work, some other might not. \n" + "If you encounter a bug, do not file an issue on GitHub." + "".format(tf.__version__), + UserWarning, + ) + return + min_version = LooseVersion(MIN_TF_VERSION) + max_version = LooseVersion(MAX_TF_VERSION) -def _ensure_tf_install(): - """Warn the user if the version of TensorFlow used is not supported. - """ - - # Update this whenever we need to depend on a newer TensorFlow release. - required_tf_version = "2.1.0" + if min_version <= LooseVersion(tf.__version__) < max_version: + return - if LooseVersion(tf.__version__) != LooseVersion(required_tf_version): - message = warning_template.format( - required=required_tf_version, present=tf.__version__ - ) - warnings.warn(message, UserWarning) + warnings.warn( + "Tensorflow Addons supports using Python ops for all Tensorflow versions " + "above or equal to {} and strictly below {} (nightly versions are not " + "supported). \n " + "The versions of TensorFlow you are currently using is {} and is not " + "supported. \n" + "Some things might work, some things might not.\n" + "If you were to encounter a bug, do not file an issue.\n" + "If you want to make sure you're using a tested and supported configuration, " + "either change the TensorFlow version or the TensorFlow Addons's version. \n" + "You can find the compatibility matrix in TensorFlow Addon's readme:\n" + "https://github.com/tensorflow/addons".format( + MIN_TF_VERSION, MAX_TF_VERSION, tf.__version__ + ), + UserWarning, + ) From cce70a6240ae887069dab1c71025e4ea2c09494f Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Tue, 31 Mar 2020 15:03:58 +0000 Subject: [PATCH 2/2] Small rewording. --- tensorflow_addons/utils/ensure_tf_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/utils/ensure_tf_install.py b/tensorflow_addons/utils/ensure_tf_install.py index e53057bd09..1465dea8e6 100644 --- a/tensorflow_addons/utils/ensure_tf_install.py +++ b/tensorflow_addons/utils/ensure_tf_install.py @@ -30,7 +30,7 @@ def _check_tf_version(): """Warn the user if the version of TensorFlow used is not supported. - This is not a check for ABI compatibility. This check only ensure that + This is not a check for custom ops compatibility. This check only ensure that we support this TensorFlow version if the user uses only Addons' Python code. """