Skip to content

Better user experience when the version of TF is not right. #1281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 12, 2020
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
51 changes: 32 additions & 19 deletions tensorflow_addons/utils/ensure_tf_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,40 @@
# Ensure TensorFlow is importable and its version is sufficiently recent. This
# needs to happen before anything else, since the imports below will try to
# import tensorflow, too.

from distutils.version import LooseVersion
import warnings

import tensorflow as tf


warning_template = """
Copy link
Member

Choose a reason for hiding this comment

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

Just curious why this was pulled out of the function? Not likely to be an issue but if we don't need to add a variable to global space then I don't see a reason to?

Copy link
Member Author

@gabrieldemarmiesse gabrieldemarmiesse Mar 12, 2020

Choose a reason for hiding this comment

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

It's just prettier as I don't have to break the indentation in the function to write the message. If you prefer that I put it in the function, I have nothing against that.

This version of TensorFlow Addons requires TensorFlow {required}.
Detected an installation of version {present}.

While some functions might work, TensorFlow Addons was not tested
with this TensorFlow version. Also custom ops were not compiled
against this version of TensorFlow. If you use custom ops,
you might get errors (segmentation faults for example).

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

If you encounter errors, do *not* file bugs in GitHub because
the version of TensorFlow you are using is not supported.
"""


def _ensure_tf_install():
"""Attempt to import tensorflow, and ensure its version is sufficient.
Raises:
ImportError: if either tensorflow is not importable or its version is
inadequate.
"""Warn the user if the version of TensorFlow used is not supported.
"""
import tensorflow as tf
import distutils.version

#
# Update this whenever we need to depend on a newer TensorFlow release.
#
required_tensorflow_version = "2.1.0"

if distutils.version.LooseVersion(tf.__version__) < distutils.version.LooseVersion(
required_tensorflow_version
):
raise ImportError(
"This version of TensorFlow Addons requires TensorFlow "
"version >= {required}; Detected an installation of version "
"{present}. Please upgrade TensorFlow to proceed.".format(
required=required_tensorflow_version, present=tf.__version__
)
required_tf_version = "2.1.0"

if LooseVersion(tf.__version__) != LooseVersion(required_tf_version):
message = warning_template.format(
required=required_tf_version, present=tf.__version__
)
warnings.warn(message, UserWarning)