Skip to content

Commit 71c0b23

Browse files
Added a warning when importing addons and using the wrong version of TF. (#1492)
* Added a warning when importing addons and using the wrong version. * Small rewording.
1 parent 874c988 commit 71c0b23

File tree

2 files changed

+41
-28
lines changed

2 files changed

+41
-28
lines changed

tensorflow_addons/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# limitations under the License.
1414
# ==============================================================================
1515
"""Useful extra functionality for TensorFlow maintained by SIG-addons."""
16-
from tensorflow_addons.utils.ensure_tf_install import _ensure_tf_install
16+
from tensorflow_addons.utils.ensure_tf_install import _check_tf_version
1717

18-
_ensure_tf_install()
18+
_check_tf_version()
1919

2020
# Local project imports
2121
from tensorflow_addons import activations

tensorflow_addons/utils/ensure_tf_install.py

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,56 @@
1414
# ==============================================================================
1515

1616

17-
# Ensure TensorFlow is importable and its version is sufficiently recent. This
17+
# Ensure the TensorFlow version is in the right range. This
1818
# needs to happen before anything else, since the imports below will try to
19-
# import tensorflow, too.
19+
# import TensorFlow, too.
2020

2121
from distutils.version import LooseVersion
2222
import warnings
2323

2424
import tensorflow as tf
2525

26+
MIN_TF_VERSION = "2.1.0"
27+
MAX_TF_VERSION = "2.3.0"
2628

27-
warning_template = """
28-
This version of TensorFlow Addons requires TensorFlow {required}.
29-
Detected an installation of version {present}.
3029

31-
While some functions might work, TensorFlow Addons was not tested
32-
with this TensorFlow version. Also custom ops were not compiled
33-
against this version of TensorFlow. If you use custom ops,
34-
you might get errors (segmentation faults for example).
30+
def _check_tf_version():
31+
"""Warn the user if the version of TensorFlow used is not supported.
3532
36-
It might help you to fallback to pure Python ops with
37-
TF_ADDONS_PY_OPS . To do that, see
38-
https://github.com/tensorflow/addons#gpucpu-custom-ops
33+
This is not a check for custom ops compatibility. This check only ensure that
34+
we support this TensorFlow version if the user uses only Addons' Python code.
35+
"""
3936

40-
If you encounter errors, do *not* file bugs in GitHub because
41-
the version of TensorFlow you are using is not supported.
42-
"""
37+
if "dev" in tf.__version__:
38+
warnings.warn(
39+
"You are currently using a nightly version of TensorFlow ({}). \n"
40+
"TensorFlow Addons offers no support for the nightly versions of "
41+
"TensorFlow. Some things might work, some other might not. \n"
42+
"If you encounter a bug, do not file an issue on GitHub."
43+
"".format(tf.__version__),
44+
UserWarning,
45+
)
46+
return
4347

48+
min_version = LooseVersion(MIN_TF_VERSION)
49+
max_version = LooseVersion(MAX_TF_VERSION)
4450

45-
def _ensure_tf_install():
46-
"""Warn the user if the version of TensorFlow used is not supported.
47-
"""
48-
49-
# Update this whenever we need to depend on a newer TensorFlow release.
50-
required_tf_version = "2.1.0"
51+
if min_version <= LooseVersion(tf.__version__) < max_version:
52+
return
5153

52-
if LooseVersion(tf.__version__) != LooseVersion(required_tf_version):
53-
message = warning_template.format(
54-
required=required_tf_version, present=tf.__version__
55-
)
56-
warnings.warn(message, UserWarning)
54+
warnings.warn(
55+
"Tensorflow Addons supports using Python ops for all Tensorflow versions "
56+
"above or equal to {} and strictly below {} (nightly versions are not "
57+
"supported). \n "
58+
"The versions of TensorFlow you are currently using is {} and is not "
59+
"supported. \n"
60+
"Some things might work, some things might not.\n"
61+
"If you were to encounter a bug, do not file an issue.\n"
62+
"If you want to make sure you're using a tested and supported configuration, "
63+
"either change the TensorFlow version or the TensorFlow Addons's version. \n"
64+
"You can find the compatibility matrix in TensorFlow Addon's readme:\n"
65+
"https://github.com/tensorflow/addons".format(
66+
MIN_TF_VERSION, MAX_TF_VERSION, tf.__version__
67+
),
68+
UserWarning,
69+
)

0 commit comments

Comments
 (0)