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

Enhance predict API to serve for env validation purpose. #10759

Merged
merged 21 commits into from
Jan 10, 2024

Conversation

B-Step62
Copy link
Collaborator

@B-Step62 B-Step62 commented Dec 27, 2023

🛠 DevTools 🛠

Open in GitHub Codespaces

Install mlflow from this PR

pip install git+https://github.com/mlflow/mlflow.git@refs/pull/10759/merge

Checkout with GitHub CLI

gh pr checkout 10759

What changes are proposed in this pull request?

Enhance mlflow models predict CLI command so that users can use it (more easily) for validating model environment before deployment.

  1. Add Python API for convenience in the notebook environment. Almost same as CLI, but also support serialized json/csv string as input data (while CLI only supports file path or stdin) for the sake of notebook experience.
  2. Show better error message and guidance when some packages are missing in the model. Basically introduce usage of extra_pip_requirements.
  3. Add pip-requirement-override argument to both Python/CLI APIs, so that users can try additional/updated dependencies without having to create and log model (as Python only emits error one by one, this process can be very annoying otherwise).

Note
Will work on OSS/Databricks docs as a follow-up.

How is this PR tested?

  • Existing unit/integration tests
  • New unit/integration tests
  • Manual tests

Verified the functionality works in Databricks. Note that it takes a bit log for the first time creating virtualenv (0:20~0:45 in the video).

Screen.Recording.2023-12-27.at.20.42.35.mov

In Databricks, I was able to test only with virtualenv as we don't have conda installed. For conda, I tested on devbox and it worked as same.

Does this PR require documentation update?

Will work on doc update.

  • No. You can skip the rest of this section.
  • Yes. I've updated:
    • Examples
    • API references
    • Instructions

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.

Enhanced predict API for MLflow Model so it can be used for inference environment validation before model deployment: (1) add Python API for the sake of notebook convenience (2) introduce pip-requirement-overrides argument to test dependency change (3) enrich error message.

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/deployments: MLflow Deployments client APIs, server, and third-party Deployments integrations
  • 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/recipes: Recipes, Recipe APIs, Recipe configs, Recipe Templates
  • 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/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/breaking-change - The PR will be mentioned in the "Breaking Changes" 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

@B-Step62 B-Step62 requested a review from dbczumar December 27, 2023 11:51
Copy link

github-actions bot commented Dec 27, 2023

Documentation preview for 7d31b19 will be available here when this CircleCI job completes successfully.

More info

@github-actions github-actions bot added area/models MLmodel format, model serialization/deserialization, flavors rn/feature Mention under Features in Changelogs. labels Dec 27, 2023
@B-Step62 B-Step62 requested a review from harupy December 27, 2023 15:38
from mlflow.utils.file_utils import TempDir


def build_docker(
Copy link
Collaborator Author

@B-Step62 B-Step62 Dec 28, 2023

Choose a reason for hiding this comment

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

build_docker has no change from the original definition in mlflow/models/__init__.py. Just moved to avoid complicating __init__.py.

model_uri: str,
# TODO: This is currently subset of PyfuncInput, ideally we should cover all
input_data: Union[str, Dict[str, Any], List[Any], "pd.DataFrame", None] = None, # noqa: F821
input_path: Optional[str] = None,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Separated input_path and input_data arguments, as pandas read_csv combined with StringIO is too permissive. For exampl,e pd.read_csv(StringIO("some-incorrect-file-path.csv")) will be read as single column DF (while we want to say file not exists).

Copy link
Member

Choose a reason for hiding this comment

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

Good idea; the API makes sense and is clear.

raise MlflowException.invalid_parameter_value(
"Both input_data and input_path are provided. Only one of them should be specified."
)
elif input_data is not None:
Copy link
Collaborator Author

@B-Step62 B-Step62 Dec 29, 2023

Choose a reason for hiding this comment

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

Not elif input_data: as this can be pandas dataframe, which doesn't allow casting to single boolean.

type=click.UNPROCESSED,
callback=_resolve_env_manager,
help=help_string,
)


ENV_MANAGER = _create_env_manager_option(
default=_EnvManager.VIRTUALENV,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Every cli command was using this default (by doing env_manager = env_manager or _EnvMangager.VIRTUALENV)

@B-Step62 B-Step62 requested a review from dbczumar December 29, 2023 02:24
Copy link
Member

@BenWilson2 BenWilson2 left a comment

Choose a reason for hiding this comment

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

Nice implementation!

B-Step62 and others added 20 commits January 9, 2024 15:19
Signed-off-by: B-Step62 <[email protected]>
Signed-off-by: B-Step62 <[email protected]>
Signed-off-by: B-Step62 <[email protected]>
Signed-off-by: B-Step62 <[email protected]>
Signed-off-by: B-Step62 <[email protected]>
Signed-off-by: B-Step62 <[email protected]>
Signed-off-by: B-Step62 <[email protected]>
Signed-off-by: B-Step62 <[email protected]>
Signed-off-by: B-Step62 <[email protected]>
Signed-off-by: B-Step62 <[email protected]>
Signed-off-by: B-Step62 <[email protected]>
Signed-off-by: B-Step62 <[email protected]>
Signed-off-by: B-Step62 <[email protected]>
Co-authored-by: Ben Wilson <[email protected]>
Signed-off-by: Yuki Watanabe <[email protected]>
Signed-off-by: B-Step62 <[email protected]>
Signed-off-by: B-Step62 <[email protected]>
Copy link
Member

@harupy harupy left a comment

Choose a reason for hiding this comment

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

LGTM :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/models MLmodel format, model serialization/deserialization, flavors rn/feature Mention under Features in Changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants