From b69bc8ddb85e71e1273ca930676d6190472bc7b1 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Sun, 29 Mar 2020 15:17:35 +0000 Subject: [PATCH 1/6] Fixing the gpu build. --- tensorflow_addons/losses/contrastive_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/losses/contrastive_test.py b/tensorflow_addons/losses/contrastive_test.py index 16d3928298..64665739ce 100644 --- a/tensorflow_addons/losses/contrastive_test.py +++ b/tensorflow_addons/losses/contrastive_test.py @@ -113,7 +113,7 @@ def test_scalar_weighted(): # Reduced loss = (0.81 + 0.49 + 1.69 + 0.49 + 0 + 0.25) * 6 / 6 # = 3.73 - np.testing.assert_allclose(loss, 3.73) + np.testing.assert_allclose(loss, 3.73, atol=1e-6, rtol=1e-6) def test_zero_weighted(): From b2f77c4a2d73565b270db6df900eb43a8e49ef48 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Sun, 29 Mar 2020 16:57:32 +0000 Subject: [PATCH 2/6] Add a warning when trying to load a custom op. --- tensorflow_addons/utils/resource_loader.py | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tensorflow_addons/utils/resource_loader.py b/tensorflow_addons/utils/resource_loader.py index cfbf9482a5..06c9048ff7 100644 --- a/tensorflow_addons/utils/resource_loader.py +++ b/tensorflow_addons/utils/resource_loader.py @@ -14,10 +14,16 @@ # ============================================================================== """Utilities similar to tf.python.platform.resource_loader.""" +from distutils.version import LooseVersion import os +import warnings import tensorflow as tf +MIN_TF_VERSION_FOR_ABI_COMPATIBILITY = "2.1.0" +MAX_TF_VERSION_FOR_ABI_COMPATIBILITY = "2.2.0" +abi_warning_already_raised = False + def get_project_root(): """Returns project root folder.""" @@ -46,5 +52,48 @@ def __init__(self, relative_path): @property def ops(self): if self._ops is None: + self.display_warning_if_incompatible() self._ops = tf.load_op_library(get_path_to_datafile(self.relative_path)) return self._ops + + def display_warning_if_incompatible(self): + global abi_warning_already_raised + if abi_is_compatible() or abi_warning_already_raised: + return + + warnings.warn( + "You are currently using TensorFlow {} and trying to load a custom op ( " + "{}). TensorFlow Addons has compiled its custom ops against TensorFlow {}, " + "and there are no ABI compatibility guarantees between the two versions." + "\n\n" + "This means that you might get segfaults when loading the custom op, " + "or other kind of low-level errors. If you do, do not file an issue " + "on Github. This is a known limitation." + "\n\n" + "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 " + "\n\n" + "You can also change the TensorFlow version installed on your system. " + "You would need a TensorFlow version equal to or above {} and strictly " + "below {}." + "\n\n" + "The last solution is to find the TensorFlow Addons version that is " + "compatible on the ABI level with the TensorFlow installed on your " + "system. To do that, refer to the readme: " + "https://github.com/tensorflow/addons".format( + tf.__version__, + self.relative_path, + MIN_TF_VERSION_FOR_ABI_COMPATIBILITY, + MIN_TF_VERSION_FOR_ABI_COMPATIBILITY, + MAX_TF_VERSION_FOR_ABI_COMPATIBILITY, + ), + UserWarning, + ) + abi_warning_already_raised = True + + +def abi_is_compatible(): + min_version = LooseVersion(MIN_TF_VERSION_FOR_ABI_COMPATIBILITY) + max_version = LooseVersion(MAX_TF_VERSION_FOR_ABI_COMPATIBILITY) + return min_version <= LooseVersion(tf.__version__) < max_version From 1073f6960200af3f25fd9bb57c6ccb4ccd2f144a Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Sun, 29 Mar 2020 17:12:27 +0000 Subject: [PATCH 3/6] Add also the nightly version. --- tensorflow_addons/utils/resource_loader.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tensorflow_addons/utils/resource_loader.py b/tensorflow_addons/utils/resource_loader.py index 06c9048ff7..472ca086ed 100644 --- a/tensorflow_addons/utils/resource_loader.py +++ b/tensorflow_addons/utils/resource_loader.py @@ -64,7 +64,7 @@ def display_warning_if_incompatible(self): warnings.warn( "You are currently using TensorFlow {} and trying to load a custom op ( " "{}). TensorFlow Addons has compiled its custom ops against TensorFlow {}, " - "and there are no ABI compatibility guarantees between the two versions." + "and there are no ABI compatibility guarantees between the two versions. " "\n\n" "This means that you might get segfaults when loading the custom op, " "or other kind of low-level errors. If you do, do not file an issue " @@ -76,7 +76,7 @@ def display_warning_if_incompatible(self): "\n\n" "You can also change the TensorFlow version installed on your system. " "You would need a TensorFlow version equal to or above {} and strictly " - "below {}." + "below {}. Note that nightly versions of TensorFlow are not supported." "\n\n" "The last solution is to find the TensorFlow Addons version that is " "compatible on the ABI level with the TensorFlow installed on your " @@ -94,6 +94,10 @@ def display_warning_if_incompatible(self): def abi_is_compatible(): + if "dev" in tf.__version__: + # tf-nightly + return False + min_version = LooseVersion(MIN_TF_VERSION_FOR_ABI_COMPATIBILITY) max_version = LooseVersion(MAX_TF_VERSION_FOR_ABI_COMPATIBILITY) return min_version <= LooseVersion(tf.__version__) < max_version From c6016f50f036d02ccc3979ab7482648e56c82b06 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Sun, 29 Mar 2020 17:21:09 +0000 Subject: [PATCH 4/6] Better formatting. --- tensorflow_addons/utils/resource_loader.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tensorflow_addons/utils/resource_loader.py b/tensorflow_addons/utils/resource_loader.py index 472ca086ed..eef92f03c9 100644 --- a/tensorflow_addons/utils/resource_loader.py +++ b/tensorflow_addons/utils/resource_loader.py @@ -62,12 +62,13 @@ def display_warning_if_incompatible(self): return warnings.warn( - "You are currently using TensorFlow {} and trying to load a custom op ( " - "{}). TensorFlow Addons has compiled its custom ops against TensorFlow {}, " + "You are currently using TensorFlow {} and trying to load a custom op ({})." + "\n" + "TensorFlow Addons has compiled its custom ops against TensorFlow {}, " "and there are no ABI compatibility guarantees between the two versions. " - "\n\n" + "\n" "This means that you might get segfaults when loading the custom op, " - "or other kind of low-level errors. If you do, do not file an issue " + "or other kind of low-level errors.\n If you do, do not file an issue " "on Github. This is a known limitation." "\n\n" "It might help you to fallback to pure Python " @@ -76,7 +77,7 @@ def display_warning_if_incompatible(self): "\n\n" "You can also change the TensorFlow version installed on your system. " "You would need a TensorFlow version equal to or above {} and strictly " - "below {}. Note that nightly versions of TensorFlow are not supported." + "below {}.\n Note that nightly versions of TensorFlow are not supported." "\n\n" "The last solution is to find the TensorFlow Addons version that is " "compatible on the ABI level with the TensorFlow installed on your " From 7668b0fc44b993c4c9816f80744a9954a504f018 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Tue, 31 Mar 2020 14:58:23 +0000 Subject: [PATCH 5/6] Update message. --- tensorflow_addons/utils/resource_loader.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tensorflow_addons/utils/resource_loader.py b/tensorflow_addons/utils/resource_loader.py index eef92f03c9..2cc93c51c7 100644 --- a/tensorflow_addons/utils/resource_loader.py +++ b/tensorflow_addons/utils/resource_loader.py @@ -65,7 +65,7 @@ def display_warning_if_incompatible(self): "You are currently using TensorFlow {} and trying to load a custom op ({})." "\n" "TensorFlow Addons has compiled its custom ops against TensorFlow {}, " - "and there are no ABI compatibility guarantees between the two versions. " + "and there are no compatibility guarantees between the two versions. " "\n" "This means that you might get segfaults when loading the custom op, " "or other kind of low-level errors.\n If you do, do not file an issue " @@ -79,10 +79,11 @@ def display_warning_if_incompatible(self): "You would need a TensorFlow version equal to or above {} and strictly " "below {}.\n Note that nightly versions of TensorFlow are not supported." "\n\n" - "The last solution is to find the TensorFlow Addons version that is " - "compatible on the ABI level with the TensorFlow installed on your " + "The last solution is to find the TensorFlow Addons version that has " + "custom ops compatible with the TensorFlow installed on your " "system. To do that, refer to the readme: " - "https://github.com/tensorflow/addons".format( + "https://github.com/tensorflow/addons" + "".format( tf.__version__, self.relative_path, MIN_TF_VERSION_FOR_ABI_COMPATIBILITY, From 983607c0fe8550448d347d28d5d69c02b7dd240e Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Thu, 2 Apr 2020 09:10:10 +0000 Subject: [PATCH 6/6] Added message about non-pip TF. --- tensorflow_addons/utils/resource_loader.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tensorflow_addons/utils/resource_loader.py b/tensorflow_addons/utils/resource_loader.py index 2cc93c51c7..132bf36722 100644 --- a/tensorflow_addons/utils/resource_loader.py +++ b/tensorflow_addons/utils/resource_loader.py @@ -77,7 +77,9 @@ def display_warning_if_incompatible(self): "\n\n" "You can also change the TensorFlow version installed on your system. " "You would need a TensorFlow version equal to or above {} and strictly " - "below {}.\n Note that nightly versions of TensorFlow are not supported." + "below {}.\n Note that nightly versions of TensorFlow, " + "as well as non-pip TensorFlow like `conda install tensorflow` or compiled " + "from source are not supported." "\n\n" "The last solution is to find the TensorFlow Addons version that has " "custom ops compatible with the TensorFlow installed on your "