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

Render code to load model when pyfunc flavor is unavailable #5006

Merged
merged 8 commits into from
Nov 17, 2021

Conversation

harupy
Copy link
Member

@harupy harupy commented Nov 4, 2021

Signed-off-by: harupy hkawamura0130@gmail.com

What changes are proposed in this pull request?

Currently, the model artifact viewer renders code to load the logged model as a pyfunc model and make predictions even when the logged model doesn't contain the pyfunc flavor. This PR fixes the issue by rendering code to load the logged model using the original flavor module.

Before

no-pyfunc-model.mov
  • The logged model doesn't contain the pyfunc flavor.
  • The model artifact viewer renders code that loads the model as a pyfunc model.

After

image

  • The model artifact viewer renders code that loads the model using mlflow.sklearn.
import numpy as np
from sklearn.decomposition import PCA

X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
pca = PCA(n_components=2)
pca.fit(X)

import mlflow

with mlflow.start_run():
    mlflow.sklearn.log_model(pca, "model")

How is this patch tested?

Unit tests

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.

(Details in 1-2 sentences. You can just refer to another PR with a description if this PR is part of a larger change.)

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/artifacts: Artifact stores and artifact logging
  • area/build: Build and test infrastructure for MLflow
  • area/docs: MLflow documentation pages
  • area/examples: Example code
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/projects: MLproject format, project running backends
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/server-infra: MLflow Tracking server backend
  • area/tracking: Tracking Service, tracking client APIs, autologging

Interface

  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/docker: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
  • area/sqlalchemy: Use of SQLAlchemy in the Tracking Service or Model Registry
  • area/windows: Windows support

Language

  • language/r: R APIs and clients
  • language/java: Java APIs and clients
  • language/new: Proposals for new client languages

Integrations

  • integrations/azure: Azure and Azure ML integrations
  • integrations/sagemaker: SageMaker integrations
  • integrations/databricks: Databricks integrations

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

@github-actions github-actions bot added the rn/bug-fix Mention under Bug Fixes in Changelogs. label Nov 4, 2021
@harupy harupy changed the title Avoid render conde snippets when mode doesn't have pyfunc flavor Avoid rendering code snippets when model doesn't have pyfunc flavor Nov 4, 2021
@harupy harupy changed the title Avoid rendering code snippets when model doesn't have pyfunc flavor Render code to load model when pyfunc flavor is unavailable Nov 8, 2021
@harupy harupy changed the title Render code to load model when pyfunc flavor is unavailable [WIP] Render code to load model when pyfunc flavor is unavailable Nov 15, 2021
@harupy harupy marked this pull request as draft November 15, 2021 15:11
Comment on lines +101 to +109
loadModelCodeText(modelPath, flavor) {
return (
`import mlflow\n` +
`logged_model = '${modelPath}'\n\n` +
`# Load model.\n` +
`loaded_model = mlflow.${flavor}.load_model(logged_model)\n`
);
}
Copy link
Collaborator

@dbczumar dbczumar Nov 15, 2021

Choose a reason for hiding this comment

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

@harupy This is perfect for everything except MLeap. MLeap models can't be reloaded in Python. Perhaps we can add a Java example for MLeap or show nothing for now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it. If so, I'd prefer to show nothing for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good!

Comment on lines 158 to 159
See <a href={CustomPyfuncModelsDocUrl}>Creating custom Pyfunc models</a> for how to log
this model as a PyFuncModel.
Copy link
Collaborator

@dbczumar dbczumar Nov 15, 2021

Choose a reason for hiding this comment

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

Suggested change
See <a href={CustomPyfuncModelsDocUrl}>Creating custom Pyfunc models</a> for how to log
this model as a PyFuncModel.
See <a href={CustomPyfuncModelsDocUrl}>creating custom Pyfunc models</a> to learn how
to customize this model and deploy it for batch or real-time scoring using the ``pyfunc`` model flavor.

It would be nice to link to the pyfunc docs too: https://www.mlflow.org/docs/latest/python_api/mlflow.pyfunc.html#module-mlflow.pyfunc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I'll add the pyfunc link!

@harupy harupy changed the title [WIP] Render code to load model when pyfunc flavor is unavailable Render code to load model when pyfunc flavor is unavailable Nov 16, 2021
harupy and others added 8 commits November 17, 2021 03:32
Signed-off-by: harupy <hkawamura0130@gmail.com>
Signed-off-by: harupy <hkawamura0130@gmail.com>
…iew-components/ShowArtifactLoggedModelView.js

Co-authored-by: dbczumar <39497902+dbczumar@users.noreply.github.com>
Signed-off-by: harupy <hkawamura0130@gmail.com>
Signed-off-by: harupy <hkawamura0130@gmail.com>
Signed-off-by: harupy <hkawamura0130@gmail.com>
Signed-off-by: harupy <hkawamura0130@gmail.com>
Signed-off-by: harupy <hkawamura0130@gmail.com>
Signed-off-by: harupy <hkawamura0130@gmail.com>
@harupy harupy marked this pull request as ready for review November 17, 2021 00:14
@harupy
Copy link
Member Author

harupy commented Nov 17, 2021

@dbczumar Let me add a few screenshots to show how it looks like now.

@harupy
Copy link
Member Author

harupy commented Nov 17, 2021

mleap

image

sklearn without pyfunc flavor

image

pyfunc

image

Copy link
Collaborator

@dbczumar dbczumar 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 @harupy !

@harupy
Copy link
Member Author

harupy commented Nov 17, 2021

Thanks for the review!

@harupy harupy merged commit 422c1c9 into mlflow:master Nov 17, 2021
@harupy harupy deleted the do-not-render-code branch November 17, 2021 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn/bug-fix Mention under Bug Fixes in Changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants