Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions tensorflow_addons/utils/resource_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -46,5 +52,56 @@ 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 ({})."
"\n"
"TensorFlow Addons has compiled its custom ops against TensorFlow {}, "
"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 "
"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 "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add "installed from pip" somewhere in there. I suspect that is just as likely of an issue as incompatible version

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add it. But this warning won't appear if someone is building from source. I don't know if there is any way we can detect that. If TF was exposing an API to get info about the build, we could use that. As far as I know, such an API doesn't exist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe so. If there was it would be in https://www.tensorflow.org/api_docs/python/tf/sysconfig most likely

"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 "
"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():
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