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

Models in r2 rw support #9490

Merged

Conversation

shichengzhou-db
Copy link
Collaborator

@shichengzhou-db shichengzhou-db commented Aug 30, 2023

Related Issues/PRs

N/A

What changes are proposed in this pull request?

  • Added a R2ArtifactStore class to support registering uc models to be stored in R2 Storage. R2ArtifactStore subclasses S3ArtifactStore to do most of the heavy lifting but overrides some methods to 1) parse (bucket, path) from r2 uri 2) instantiate s3 client with virtual addressing style

How is this patch tested?

  • Added unit test for R2ArtifactStore to specifically test for parsing of R2 URI and if S3 client is initialized correctly for R2 artifact store.
  • Manually created a R2 Storage backed UC Catalog and successfully registered a model into it (Version 3 in screenshot).
Screenshot 2023-08-30 at 3 09 06 PM
  • Existing unit/integration tests
  • New unit/integration tests
  • Manual tests (describe details, including test results, below)

Does this PR require documentation 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.

Support registering model in a R2 Storage backed Databricks UC Catalog.

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/gateway: AI Gateway service, Gateway client APIs, third-party Gateway integrations
  • 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/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
Copy link

@shichengzhou-db Thank you for the contribution! Could you fix the following issue(s)?

⚠ DCO check

The DCO check failed. Please sign off your commit(s) by following the instructions here. See https://github.com/mlflow/mlflow/blob/master/CONTRIBUTING.md#sign-your-work for more details.

@mlflow-automation
Copy link
Collaborator

mlflow-automation commented Aug 30, 2023

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

More info

@github-actions github-actions bot added area/artifacts Artifact stores and artifact logging area/model-registry Model registry, model registry APIs, and the fluent client calls for model registry integrations/databricks Databricks integrations rn/feature Mention under Features in Changelogs. labels Aug 30, 2023
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.

Looks great @shichengzhou-db ! Were you also able to test loading the model that you registered to R2 via e.g. mlflow.pyfunc.load_model?

@smurching
Copy link
Collaborator

@jerrylian-db FYI there were some gotchas we ran into (e.g. needing to use virtual host style addressing) to get reading/writing model artifacts to R2 to work using UC temporary credentials. You might want to work with Shicheng to test that R2 model read/write still work once you have a PR ready to refactor S3ArtifactRepo to share the fast upload/download logic in DatabricksArtifactRepo

return bucket, path

def _get_s3_client(self, addressing_style="virtual"):
return super()._get_s3_client(addressing_style=addressing_style)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You may need to run black . to fix lint errors (e.g. having newlines at EOF)

Signed-off-by: shichengzhou-db <[email protected]>
@shichengzhou-db
Copy link
Collaborator Author

Looks great @shichengzhou-db ! Were you also able to test loading the model that you registered to R2 via e.g. mlflow.pyfunc.load_model?

yep loaded the model and did a prediction, works as expected (added this manual test code in the notebook shared with you earlier)

Signed-off-by: shichengzhou-db <[email protected]>
Copy link
Collaborator

@kriscon-db kriscon-db left a comment

Choose a reason for hiding this comment

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

LGTM

@shichengzhou-db
Copy link
Collaborator Author

@mlflow-automation autoformat

Comment on lines +29 to +30
if path.startswith("/"):
path = path[1:]
Copy link
Member

@harupy harupy Aug 31, 2023

Choose a reason for hiding this comment

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

Suggested change
if path.startswith("/"):
path = path[1:]
path = path.lstrip("/")

can we use lstrip here?

# r2 uri format(virtual): r2://<bucket-name>@<account-id>.r2.cloudflarestorage.com/<path>
parsed = urllib.parse.urlparse(uri)
if parsed.scheme != "r2":
raise Exception(f"Not an R2 URI: {uri}")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
raise Exception(f"Not an R2 URI: {uri}")
raise MlflowException.invalid_parameter_value(f"Not an R2 URI: {uri}")

Comment on lines +9 to +17
def __init__(
self, artifact_uri, access_key_id=None, secret_access_key=None, session_token=None
):
super().__init__(
artifact_uri,
access_key_id=access_key_id,
secret_access_key=secret_access_key,
session_token=session_token,
)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to override __init__?

@shichengzhou-db shichengzhou-db merged commit 419d0df into mlflow:master Aug 31, 2023
26 checks passed
alanzhangmg pushed a commit to alanzhangmg/mlflow that referenced this pull request Aug 31, 2023
Signed-off-by: shichengzhou-db <[email protected]>
Signed-off-by: mlflow-automation <[email protected]>
Co-authored-by: mlflow-automation <[email protected]>
jerrylian-db pushed a commit that referenced this pull request Sep 4, 2023
Signed-off-by: shichengzhou-db <[email protected]>
Signed-off-by: mlflow-automation <[email protected]>
Co-authored-by: mlflow-automation <[email protected]>
lu-ohai pushed a commit to lu-ohai/mlflow that referenced this pull request Sep 5, 2023
Signed-off-by: shichengzhou-db <[email protected]>
Signed-off-by: mlflow-automation <[email protected]>
Co-authored-by: mlflow-automation <[email protected]>
Signed-off-by: Lu Peng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/artifacts Artifact stores and artifact logging area/model-registry Model registry, model registry APIs, and the fluent client calls for model registry integrations/databricks Databricks integrations rn/feature Mention under Features in Changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants