From dceb1cc3f82a092b44215a6859437476f38ff173 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Tue, 10 Mar 2020 15:36:59 +0100 Subject: [PATCH 1/4] Better user experience when the version of TF is not right. --- tensorflow_addons/utils/ensure_tf_install.py | 51 ++++++++++++-------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/tensorflow_addons/utils/ensure_tf_install.py b/tensorflow_addons/utils/ensure_tf_install.py index 4351afbc7a..b116b816cf 100644 --- a/tensorflow_addons/utils/ensure_tf_install.py +++ b/tensorflow_addons/utils/ensure_tf_install.py @@ -17,27 +17,38 @@ # Ensure TensorFlow is importable and its version is sufficiently recent. This # needs to happen before anything else, since the imports below will try to # import tensorflow, too. + +from distutils.version import LooseVersion +import warnings + +import tensorflow as tf + + +warning_template = """ +This version of TensorFlow Addons requires TensorFlow {required}. +Detected an installation of version {present}. + +While some functions might work, custom ops were not compiled +against this version of TensorFlow. If you use custom ops, +you might get errors (segmentation faults for example). + +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 + +If you encounter errors, do not file bugs in GitHub because +the version of TensorFlow you are using is not supported. +""" + + def _ensure_tf_install(): - """Attempt to import tensorflow, and ensure its version is sufficient. - Raises: - ImportError: if either tensorflow is not importable or its version is - inadequate. + """Warn the user if the version of TensorFlow used is not supported. """ - import tensorflow as tf - import distutils.version - # # Update this whenever we need to depend on a newer TensorFlow release. - # - required_tensorflow_version = "2.1.0" - - if distutils.version.LooseVersion(tf.__version__) < distutils.version.LooseVersion( - required_tensorflow_version - ): - raise ImportError( - "This version of TensorFlow Addons requires TensorFlow " - "version >= {required}; Detected an installation of version " - "{present}. Please upgrade TensorFlow to proceed.".format( - required=required_tensorflow_version, present=tf.__version__ - ) - ) + required_tf_version = "2.1.0" + + if LooseVersion(tf.__version__) != LooseVersion(required_tf_version): + message = warning_template.format(required=required_tf_version, + present=tf.__version__) + warnings.warn(message, UserWarning) From 9e54387f50fb97de2aec882ed2c87fbf883f1883 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Tue, 10 Mar 2020 15:41:53 +0100 Subject: [PATCH 2/4] Some more info. --- tensorflow_addons/utils/ensure_tf_install.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tensorflow_addons/utils/ensure_tf_install.py b/tensorflow_addons/utils/ensure_tf_install.py index b116b816cf..97274b1e29 100644 --- a/tensorflow_addons/utils/ensure_tf_install.py +++ b/tensorflow_addons/utils/ensure_tf_install.py @@ -28,7 +28,8 @@ This version of TensorFlow Addons requires TensorFlow {required}. Detected an installation of version {present}. -While some functions might work, custom ops were not compiled +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). @@ -36,7 +37,7 @@ TF_ADDONS_PY_OPS . To do that, see https://github.com/tensorflow/addons#gpucpu-custom-ops -If you encounter errors, do not file bugs in GitHub because +If you encounter errors, do *not* file bugs in GitHub because the version of TensorFlow you are using is not supported. """ From 2c4908a3ebe7e1e57c6bee5f23e94ebe8eeb7cd0 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Tue, 10 Mar 2020 15:42:26 +0100 Subject: [PATCH 3/4] black. --- tensorflow_addons/utils/ensure_tf_install.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tensorflow_addons/utils/ensure_tf_install.py b/tensorflow_addons/utils/ensure_tf_install.py index 97274b1e29..d0af7d639a 100644 --- a/tensorflow_addons/utils/ensure_tf_install.py +++ b/tensorflow_addons/utils/ensure_tf_install.py @@ -50,6 +50,7 @@ def _ensure_tf_install(): required_tf_version = "2.1.0" if LooseVersion(tf.__version__) != LooseVersion(required_tf_version): - message = warning_template.format(required=required_tf_version, - present=tf.__version__) + message = warning_template.format( + required=required_tf_version, present=tf.__version__ + ) warnings.warn(message, UserWarning) From 405c39fab01da100cf5b982a392205bd12dbc8e9 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Tue, 10 Mar 2020 15:44:35 +0100 Subject: [PATCH 4/4] Trailing whitespaces. --- 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 d0af7d639a..e5dcae52fe 100644 --- a/tensorflow_addons/utils/ensure_tf_install.py +++ b/tensorflow_addons/utils/ensure_tf_install.py @@ -28,7 +28,7 @@ This version of TensorFlow Addons requires TensorFlow {required}. Detected an installation of version {present}. -While some functions might work, TensorFlow Addons was not tested +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).