Skip to content
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

Implementing TensorFlow 2.0 Compatibility #1872

Merged
merged 23 commits into from Sep 30, 2019
Merged

Conversation

juntai-zheng
Copy link
Collaborator

What changes are proposed in this pull request?

In order for MLflow to be compatible with the upcoming TensorFlow 2.0, several under the hood changes had to be made in the examples, MLflow code, and tests. The main difference is how we load back models - instead of loading back signature definitions in conjunction with tf.graphs and sessions, TF 2.0 allows us to abstract those away and load back models as callable functions for inference.

The main API change is in mlflow/tensorflow.py with the function load_model(model_uri, tf_sess). tf_sess is now optional, since TF 2.0 deprecated sessions. The code will error out if the user's TF version is < 2.0 and no argument is provided. The code will throw a warning that tf_sess is deprecated and ignore the input if the user's TF version is 2.0+.
In addition, load_model() originally returned a SignatureDef. Now, the function returns a function which can be fed data and returns inputs. See the docs for details.

The code has been modified to check for the user's TensorFlow version and be compatible with both TF 1.X and TF 2.0 (given correct arguments to APIs).

New files have been created for TF 2.0 tests and examples, with the underlying example dataset being changed to TensorFlow's iris_data example. A couple of tests testing loading a model into a tf.graph have been removed due to TF 2.0 abstracting graphs away. The Travis bash file has been modified to install the proper TF versions for each suite of tests.

StrictVersion has been changed to LooseVersion for version checks in order to allow for letters in version numbers (such as TensorFlow 2.0.0rc2) to be valid version numbers.

This PR does not address autologging, keras, or keras autologging - those will be in a future PR.

How is this patch tested?

I created a new suite of tests (mlflow/tests/tensorflow/test_tensorflow2_model_export.py), based on the original tests in order to test the changes. The changes to mlflow/tensorflow.py work with both the original test on TF 1.12 and with the new tests on TF 2.0.0rc2.

Release Notes

Is this a user-facing change?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release notes for MLflow users.

MLflow now supports TensorFlow 2.0. load_model() no longer takes a tf_sess, but still does if you are using TensorFlow 1.X. The function also returns a callable graph in the form of a tf.function rather than a SignatureDef now.

What component(s) does this PR affect?

  • UI
  • CLI
  • API
  • REST-API
  • Examples
  • Docs
  • Tracking
  • Projects
  • Artifacts
  • Models
  • Scoring
  • Serving
  • R
  • Java
  • Python

How should the PR be classified in the release notes? Choose one:

  • rn/breaking-change - The PR will be mentioned in the "Breaking Changes" section
  • rn/none - No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" section
  • rn/feature - A new user-facing feature worth mentioning in the release notes
  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes
  • rn/documentation - A user-facing documentation change worth mentioning in the release notes

mlflow/tensorflow.py Outdated Show resolved Hide resolved
mlflow/tensorflow.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@smurching smurching left a comment

Choose a reason for hiding this comment

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

BTW one comment I meant to add earlier but forgot...we ideally should have a test where we load a MLflow model persisted with 1.x using TF 2.0 (both in function form & as a pyfunc). I think it's fine if we add such a test in a follow-up PR, but seems important to have before we claim TF 2.0 compatibility, and we should make sure the follow-up work is tracked somewhere.

mlflow/tensorflow.py Outdated Show resolved Hide resolved
mlflow/tensorflow.py Outdated Show resolved Hide resolved
@@ -30,8 +30,8 @@
from tests.helper_functions import mock_s3_bucket # pylint: disable=unused-import

SavedModelInfo = collections.namedtuple(
"SavedModelInfo",
Copy link
Collaborator

Choose a reason for hiding this comment

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

BTW, super small nit but in general it's best to avoid these sort of no-op whitespace changes if possible (did your editor make them or something?). Not a big deal, it just makes the git blame harder to trace through

Co-Authored-By: Siddharth Murching <smurching@gmail.com>
mlflow/tensorflow.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@smurching smurching left a comment

Choose a reason for hiding this comment

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

Some small comments but otherwise looks good! Before we merge, we should manually test backwards compatibility when loading models persisted with TF 1.x using TF 2.0

juntai-zheng and others added 2 commits September 26, 2019 16:48
Co-Authored-By: Siddharth Murching <smurching@gmail.com>
Copy link
Collaborator

@smurching smurching left a comment

Choose a reason for hiding this comment

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

LGTM thanks @juntai-zheng!

Merge branch 'tf2' of github.com:juntai-zheng/mlflow into tf2
@smurching smurching added the rn/feature Mention under Features in Changelogs. label Sep 30, 2019
@smurching smurching changed the title [WIP] Implementing TensorFlow 2.0 Compatibility Implementing TensorFlow 2.0 Compatibility Sep 30, 2019
@smurching smurching merged commit 7e6613a into mlflow:master Sep 30, 2019
avflor pushed a commit to avflor/mlflow that referenced this pull request Aug 22, 2020
MLflow now supports logging & loading models using TensorFlow 2.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn/feature Mention under Features in Changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants