Skip to content

Commit 41ef1e0

Browse files
Better user experience when the version of TF is not right. (tensorflow#1281)
* Better user experience when the version of TF is not right.
1 parent ff90c76 commit 41ef1e0

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

tensorflow_addons/utils/ensure_tf_install.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,40 @@
1717
# Ensure TensorFlow is importable and its version is sufficiently recent. This
1818
# needs to happen before anything else, since the imports below will try to
1919
# import tensorflow, too.
20+
21+
from distutils.version import LooseVersion
22+
import warnings
23+
24+
import tensorflow as tf
25+
26+
27+
warning_template = """
28+
This version of TensorFlow Addons requires TensorFlow {required}.
29+
Detected an installation of version {present}.
30+
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).
35+
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
39+
40+
If you encounter errors, do *not* file bugs in GitHub because
41+
the version of TensorFlow you are using is not supported.
42+
"""
43+
44+
2045
def _ensure_tf_install():
21-
"""Attempt to import tensorflow, and ensure its version is sufficient.
22-
Raises:
23-
ImportError: if either tensorflow is not importable or its version is
24-
inadequate.
46+
"""Warn the user if the version of TensorFlow used is not supported.
2547
"""
26-
import tensorflow as tf
27-
import distutils.version
2848

29-
#
3049
# Update this whenever we need to depend on a newer TensorFlow release.
31-
#
32-
required_tensorflow_version = "2.1.0"
33-
34-
if distutils.version.LooseVersion(tf.__version__) < distutils.version.LooseVersion(
35-
required_tensorflow_version
36-
):
37-
raise ImportError(
38-
"This version of TensorFlow Addons requires TensorFlow "
39-
"version >= {required}; Detected an installation of version "
40-
"{present}. Please upgrade TensorFlow to proceed.".format(
41-
required=required_tensorflow_version, present=tf.__version__
42-
)
50+
required_tf_version = "2.1.0"
51+
52+
if LooseVersion(tf.__version__) != LooseVersion(required_tf_version):
53+
message = warning_template.format(
54+
required=required_tf_version, present=tf.__version__
4355
)
56+
warnings.warn(message, UserWarning)

0 commit comments

Comments
 (0)