-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Support for ModelBuilder In_Process Mode (1/2) #4784
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
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
2cc906b
InferenceSpec support for HF
b25295a
Merge branch 'aws:master' into hf-inf-spec-support
bryannahm1 fb28458
feat: InferenceSpec support for MMS and testing
3576ea9
Introduce changes for InProcess Mode
d3b8e9b
mb_inprocess updates
68cede1
In_Process mode for TGI transformers, edits
02e54ef
Remove InfSpec from branch
f39cca6
merge from master for inf spec
cc0ca14
changes to support in_process
18fc3f2
changes to get pre-checks passing
495c7b4
pylint fix
1121f47
unit test, test mb
b6062a7
period missing, added
1ec209c
suggestions and test added
ca6c818
pre-push fix
cd3dbaa
missing an @
f52f36c
fixes to test, added stubbing
1843210
removing for fixes
d0fe3ac
variable fixes
1b93244
init fix
b40f36c
tests for in process mode
68000e1
prepush fix
826c5c4
minor fix
1fd6291
Merge branch 'master' into mb_in_process
bryannahm1 de6f861
Merge branch 'master' into mb_in_process
sage-maker 5cc24ba
Merge branch 'master' into mb_in_process
sage-maker 64efa90
Merge branch 'master' into mb_in_process
sage-maker 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
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,89 @@ | ||
"""Module that defines the InProcessMode class""" | ||
|
||
from __future__ import absolute_import | ||
from pathlib import Path | ||
import logging | ||
from typing import Dict, Type | ||
import time | ||
from datetime import datetime, timedelta | ||
|
||
from sagemaker.base_predictor import PredictorBase | ||
from sagemaker.serve.spec.inference_spec import InferenceSpec | ||
from sagemaker.serve.builder.schema_builder import SchemaBuilder | ||
from sagemaker.serve.utils.types import ModelServer | ||
from sagemaker.serve.utils.exceptions import LocalDeepPingException | ||
from sagemaker.serve.model_server.multi_model_server.server import InProcessMultiModelServer | ||
from sagemaker.session import Session | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
_PING_HEALTH_CHECK_FAIL_MSG = ( | ||
"Ping health check did not pass. " | ||
+ "Please increase container_timeout_seconds or review your inference code." | ||
) | ||
|
||
|
||
class InProcessMode( | ||
InProcessMultiModelServer, | ||
): | ||
"""A class that holds methods to deploy model to a container in process environment""" | ||
|
||
def __init__( | ||
self, | ||
model_server: ModelServer, | ||
inference_spec: Type[InferenceSpec], | ||
schema_builder: Type[SchemaBuilder], | ||
session: Session, | ||
model_path: str = None, | ||
env_vars: Dict = None, | ||
): | ||
# pylint: disable=bad-super-call | ||
super().__init__() | ||
|
||
self.inference_spec = inference_spec | ||
self.model_path = model_path | ||
self.env_vars = env_vars | ||
self.session = session | ||
self.schema_builder = schema_builder | ||
self.model_server = model_server | ||
self._ping_container = None | ||
|
||
def load(self, model_path: str = None): | ||
"""Loads model path, checks that path exists""" | ||
path = Path(model_path if model_path else self.model_path) | ||
if not path.exists(): | ||
raise ValueError("model_path does not exist") | ||
if not path.is_dir(): | ||
raise ValueError("model_path is not a valid directory") | ||
|
||
return self.inference_spec.load(str(path)) | ||
|
||
def prepare(self): | ||
"""Prepares the server""" | ||
|
||
def create_server( | ||
self, | ||
predictor: PredictorBase, | ||
): | ||
"""Creating the server and checking ping health.""" | ||
logger.info("Waiting for model server %s to start up...", self.model_server) | ||
|
||
if self.model_server == ModelServer.MMS: | ||
self._ping_container = self._multi_model_server_deep_ping | ||
|
||
time_limit = datetime.now() + timedelta(seconds=5) | ||
while self._ping_container is not None: | ||
final_pull = datetime.now() > time_limit | ||
|
||
if final_pull: | ||
break | ||
|
||
time.sleep(10) | ||
|
||
healthy, response = self._ping_container(predictor) | ||
if healthy: | ||
logger.debug("Ping health check has passed. Returned %s", str(response)) | ||
break | ||
|
||
if not healthy: | ||
raise LocalDeepPingException(_PING_HEALTH_CHECK_FAIL_MSG) |
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 |
---|---|---|
|
@@ -20,6 +20,23 @@ | |
logger = logging.getLogger(__name__) | ||
|
||
|
||
class InProcessMultiModelServer: | ||
"""In Process Mode Multi Model server instance""" | ||
|
||
def _start_serving(self): | ||
"""Initializes the start of the server""" | ||
return Exception("Not implemented") | ||
|
||
def _invoke_multi_model_server_serving(self, request: object, content_type: str, accept: str): | ||
"""Invokes the MMS server by sending POST request""" | ||
return Exception("Not implemented") | ||
|
||
def _multi_model_server_deep_ping(self, predictor: PredictorBase): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this complete? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have stubbed it. |
||
"""Sends a deep ping to ensure prediction""" | ||
response = None | ||
return (True, response) | ||
|
||
|
||
class LocalMultiModelServer: | ||
"""Local Multi Model server instance""" | ||
|
||
|
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.
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.
I would leave these methods as stubs .... return an Exception("Not implemented")
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.
I have stubbed it, thank you.