|
14 | 14 | # ==============================================================================
|
15 | 15 | """Utilities similar to tf.python.platform.resource_loader."""
|
16 | 16 |
|
| 17 | +from distutils.version import LooseVersion |
17 | 18 | import os
|
| 19 | +import warnings |
18 | 20 |
|
19 | 21 | import tensorflow as tf
|
20 | 22 |
|
| 23 | +MIN_TF_VERSION_FOR_ABI_COMPATIBILITY = "2.1.0" |
| 24 | +MAX_TF_VERSION_FOR_ABI_COMPATIBILITY = "2.2.0" |
| 25 | +abi_warning_already_raised = False |
| 26 | + |
21 | 27 |
|
22 | 28 | def get_project_root():
|
23 | 29 | """Returns project root folder."""
|
@@ -46,5 +52,56 @@ def __init__(self, relative_path):
|
46 | 52 | @property
|
47 | 53 | def ops(self):
|
48 | 54 | if self._ops is None:
|
| 55 | + self.display_warning_if_incompatible() |
49 | 56 | self._ops = tf.load_op_library(get_path_to_datafile(self.relative_path))
|
50 | 57 | return self._ops
|
| 58 | + |
| 59 | + def display_warning_if_incompatible(self): |
| 60 | + global abi_warning_already_raised |
| 61 | + if abi_is_compatible() or abi_warning_already_raised: |
| 62 | + return |
| 63 | + |
| 64 | + warnings.warn( |
| 65 | + "You are currently using TensorFlow {} and trying to load a custom op ({})." |
| 66 | + "\n" |
| 67 | + "TensorFlow Addons has compiled its custom ops against TensorFlow {}, " |
| 68 | + "and there are no compatibility guarantees between the two versions. " |
| 69 | + "\n" |
| 70 | + "This means that you might get segfaults when loading the custom op, " |
| 71 | + "or other kind of low-level errors.\n If you do, do not file an issue " |
| 72 | + "on Github. This is a known limitation." |
| 73 | + "\n\n" |
| 74 | + "It might help you to fallback to pure Python " |
| 75 | + "ops with TF_ADDONS_PY_OPS . To do that, see " |
| 76 | + "https://github.com/tensorflow/addons#gpucpu-custom-ops " |
| 77 | + "\n\n" |
| 78 | + "You can also change the TensorFlow version installed on your system. " |
| 79 | + "You would need a TensorFlow version equal to or above {} and strictly " |
| 80 | + "below {}.\n Note that nightly versions of TensorFlow, " |
| 81 | + "as well as non-pip TensorFlow like `conda install tensorflow` or compiled " |
| 82 | + "from source are not supported." |
| 83 | + "\n\n" |
| 84 | + "The last solution is to find the TensorFlow Addons version that has " |
| 85 | + "custom ops compatible with the TensorFlow installed on your " |
| 86 | + "system. To do that, refer to the readme: " |
| 87 | + "https://github.com/tensorflow/addons" |
| 88 | + "".format( |
| 89 | + tf.__version__, |
| 90 | + self.relative_path, |
| 91 | + MIN_TF_VERSION_FOR_ABI_COMPATIBILITY, |
| 92 | + MIN_TF_VERSION_FOR_ABI_COMPATIBILITY, |
| 93 | + MAX_TF_VERSION_FOR_ABI_COMPATIBILITY, |
| 94 | + ), |
| 95 | + UserWarning, |
| 96 | + ) |
| 97 | + abi_warning_already_raised = True |
| 98 | + |
| 99 | + |
| 100 | +def abi_is_compatible(): |
| 101 | + if "dev" in tf.__version__: |
| 102 | + # tf-nightly |
| 103 | + return False |
| 104 | + |
| 105 | + min_version = LooseVersion(MIN_TF_VERSION_FOR_ABI_COMPATIBILITY) |
| 106 | + max_version = LooseVersion(MAX_TF_VERSION_FOR_ABI_COMPATIBILITY) |
| 107 | + return min_version <= LooseVersion(tf.__version__) < max_version |
0 commit comments