|
14 | 14 | # ============================================================================== |
15 | 15 |
|
16 | 16 |
|
17 | | -# Ensure TensorFlow is importable and its version is sufficiently recent. This |
| 17 | +# Ensure the TensorFlow version is in the right range. This |
18 | 18 | # needs to happen before anything else, since the imports below will try to |
19 | | -# import tensorflow, too. |
| 19 | +# import TensorFlow, too. |
20 | 20 |
|
21 | 21 | from distutils.version import LooseVersion |
22 | 22 | import warnings |
23 | 23 |
|
24 | 24 | import tensorflow as tf |
25 | 25 |
|
| 26 | +MIN_TF_VERSION = "2.1.0" |
| 27 | +MAX_TF_VERSION = "2.3.0" |
26 | 28 |
|
27 | | -warning_template = """ |
28 | | -This version of TensorFlow Addons requires TensorFlow {required}. |
29 | | -Detected an installation of version {present}. |
30 | 29 |
|
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. |
35 | 32 |
|
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 | + """ |
39 | 36 |
|
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 |
43 | 47 |
|
| 48 | + min_version = LooseVersion(MIN_TF_VERSION) |
| 49 | + max_version = LooseVersion(MAX_TF_VERSION) |
44 | 50 |
|
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 |
51 | 53 |
|
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