-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add tensorflow_serving support for mlflow models and enable lineage tracking for mlflow models #4662
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
Add tensorflow_serving support for mlflow models and enable lineage tracking for mlflow models #4662
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
92451cb
Initial commit for tensorflow_serving support of MLflow
jiapinw 8a723c9
Merge branch 'aws:master' into aloy-integration-ga-deployment-dev
jiapinw 8ba826b
Merge branch 'aws:master' into aloy-integration-ga-deployment-dev
jiapinw aa7b0c6
Add integ tests for mlflow tf_serving
jiapinw a549adb
fix style issues
jiapinw 6279dc4
Merge branch 'aws:master' into aloy-integration-ga-deployment-dev
jiapinw e198a79
remove unused attributes from tf builder
jiapinw 2f565d7
Add deep ping for tf_serving local mode
jiapinw 08096ff
Merge pull request #4 from jiapinw/aloy-integration-ga-deployment-dev
jiapinw 8408e7a
Initial commit for lineage impl
jiapinw f0440f1
Merge branch 'aws:master' into aloy-integration-ga-master
jiapinw 7961a74
Merge branch 'aws:master' into aloy-integration-ga-lineage-dev
jiapinw c75d7d3
Initial commit for tensorflow_serving support of MLflow
jiapinw 590b36e
Add integ tests for mlflow tf_serving
jiapinw c8262b7
fix style issues
jiapinw 47fa352
remove unused attributes from tf builder
jiapinw 2739c3e
Add deep ping for tf_serving local mode
jiapinw f9adf44
Add integ tests and uts
jiapinw f2d9d36
fix local mode for tf_serving
jiapinw 7cac6bc
Allow lineage tracking only in sagemaker endpoint mode
jiapinw 345e17a
Merge branch 'aloy-integration-ga-master' into aloy-integration-ga-li…
jiapinw 1b99418
fix regex pattern
jiapinw e45ad0f
Merge pull request #5 from jiapinw/aloy-integration-ga-lineage-dev
jiapinw 480e13e
Merge branch 'aws:master' into aloy-integration-ga-master
jiapinw e7c9e59
fix style issues
jiapinw 65ad677
fix regex pattern and hard coded py version in ut
jiapinw a276acc
fix missing session
jiapinw 2a86534
Resolve pr comments and fix regex for mlflow registry and ids
jiapinw d03df30
Merge branch 'master' into aloy-integration-ga-master
jiapinw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,3 +36,4 @@ onnx>=1.15.0 | |
| nbformat>=5.9,<6 | ||
| accelerate>=0.24.1,<=0.27.0 | ||
| schema==0.7.5 | ||
| tensorflow>=2.1,<=2.16 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"). You | ||
| # may not use this file except in compliance with the License. A copy of | ||
| # the License is located at | ||
| # | ||
| # http://aws.amazon.com/apache2.0/ | ||
| # | ||
| # or in the "license" file accompanying this file. This file is | ||
| # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
| # ANY KIND, either express or implied. See the License for the specific | ||
| # language governing permissions and limitations under the License. | ||
| """Holds mixin logic to support deployment of Model ID""" | ||
| from __future__ import absolute_import | ||
| import logging | ||
| import os | ||
| from pathlib import Path | ||
| from abc import ABC, abstractmethod | ||
|
|
||
| from sagemaker import Session | ||
| from sagemaker.serve.detector.pickler import save_pkl | ||
| from sagemaker.serve.model_server.tensorflow_serving.prepare import prepare_for_tf_serving | ||
| from sagemaker.tensorflow import TensorFlowModel, TensorFlowPredictor | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| _TF_SERVING_MODEL_BUILDER_ENTRY_POINT = "inference.py" | ||
| _CODE_FOLDER = "code" | ||
|
|
||
|
|
||
| # pylint: disable=attribute-defined-outside-init, disable=E1101 | ||
| class TensorflowServing(ABC): | ||
| """TensorflowServing build logic for ModelBuilder()""" | ||
|
|
||
| def __init__(self): | ||
| self.model = None | ||
| self.serve_settings = None | ||
| self.sagemaker_session = None | ||
| self.model_path = None | ||
| self.dependencies = None | ||
| self.modes = None | ||
| self.mode = None | ||
| self.model_server = None | ||
| self.image_uri = None | ||
| self._is_custom_image_uri = False | ||
| self.image_config = None | ||
| self.vpc_config = None | ||
| self._original_deploy = None | ||
| self.secret_key = None | ||
| self.engine = None | ||
| self.pysdk_model = None | ||
| self.schema_builder = None | ||
| self.env_vars = None | ||
|
|
||
| @abstractmethod | ||
| def _prepare_for_mode(self): | ||
jiapinw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Prepare model artifacts based on mode.""" | ||
|
|
||
| @abstractmethod | ||
| def _get_client_translators(self): | ||
| """Set up client marshaller based on schema builder.""" | ||
|
|
||
| def _save_schema_builder(self): | ||
| """Save schema builder for tensorflow serving.""" | ||
| if not os.path.exists(self.model_path): | ||
| os.makedirs(self.model_path) | ||
|
|
||
| code_path = Path(self.model_path).joinpath("code") | ||
| save_pkl(code_path, self.schema_builder) | ||
|
|
||
| def _get_tensorflow_predictor( | ||
| self, endpoint_name: str, sagemaker_session: Session | ||
| ) -> TensorFlowPredictor: | ||
| """Creates a TensorFlowPredictor object""" | ||
| serializer, deserializer = self._get_client_translators() | ||
|
|
||
| return TensorFlowPredictor( | ||
| endpoint_name=endpoint_name, | ||
| sagemaker_session=sagemaker_session, | ||
| serializer=serializer, | ||
| deserializer=deserializer, | ||
| ) | ||
|
|
||
| def _validate_for_tensorflow_serving(self): | ||
| """Validate for tensorflow serving""" | ||
| if not getattr(self, "_is_mlflow_model", False): | ||
| raise ValueError("Tensorflow Serving is currently only supported for mlflow models.") | ||
|
|
||
| def _create_tensorflow_model(self): | ||
| """Creates a TensorFlow model object""" | ||
| self.pysdk_model = TensorFlowModel( | ||
jiapinw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| image_uri=self.image_uri, | ||
| image_config=self.image_config, | ||
| vpc_config=self.vpc_config, | ||
| model_data=self.s3_upload_path, | ||
| role=self.serve_settings.role_arn, | ||
| env=self.env_vars, | ||
| sagemaker_session=self.sagemaker_session, | ||
| predictor_cls=self._get_tensorflow_predictor, | ||
| ) | ||
|
|
||
| self.pysdk_model.mode = self.mode | ||
| self.pysdk_model.modes = self.modes | ||
| self.pysdk_model.serve_settings = self.serve_settings | ||
|
|
||
| self._original_deploy = self.pysdk_model.deploy | ||
| self.pysdk_model.deploy = self._model_builder_deploy_wrapper | ||
| self._original_register = self.pysdk_model.register | ||
| self.pysdk_model.register = self._model_builder_register_wrapper | ||
| self.model_package = None | ||
| return self.pysdk_model | ||
|
|
||
| def _build_for_tensorflow_serving(self): | ||
| """Build the model for Tensorflow Serving""" | ||
| self._validate_for_tensorflow_serving() | ||
| self._save_schema_builder() | ||
|
|
||
| if not self.image_uri: | ||
| raise ValueError("image_uri is not set for tensorflow serving") | ||
|
|
||
| self.secret_key = prepare_for_tf_serving( | ||
| model_path=self.model_path, | ||
| shared_libs=self.shared_libs, | ||
| dependencies=self.dependencies, | ||
| ) | ||
|
|
||
| self._prepare_for_mode() | ||
|
|
||
| return self._create_tensorflow_model() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is
_is_mlflow_modelmethod defined?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sagemaker-python-sdk/src/sagemaker/serve/builder/model_builder.py
Line 724 in 2a902cd