-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: combined model + script artifact #3715
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
Changes from 1 commit
8bb9cba
02f3a82
38f8634
29243ae
939c77c
b87f794
29724c2
39bb144
1949f9c
65a5543
1bd89e5
c1f9587
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,10 +173,11 @@ def _retrieve_image_uri( | |
def _retrieve_model_uri( | ||
model_id: str, | ||
model_version: str, | ||
model_scope: Optional[str], | ||
region: Optional[str], | ||
tolerate_vulnerable_model: bool, | ||
tolerate_deprecated_model: bool, | ||
model_scope: Optional[str] = None, | ||
region: Optional[str] = None, | ||
tolerate_vulnerable_model: bool = False, | ||
tolerate_deprecated_model: bool = False, | ||
include_script: bool = False, | ||
): | ||
"""Retrieves the model artifact S3 URI for the model matching the given arguments. | ||
|
||
|
@@ -197,6 +198,8 @@ def _retrieve_model_uri( | |
tolerate_deprecated_model (bool): True if deprecated versions of model | ||
specifications should be tolerated (exception not raised). If False, raises | ||
an exception if the version of the model is deprecated. | ||
include_script (bool): True if script artifact should be packaged alongside model | ||
tarball. (Default: False). | ||
Returns: | ||
str: the model artifact S3 URI for the corresponding model. | ||
|
||
|
@@ -205,6 +208,8 @@ def _retrieve_model_uri( | |
VulnerableJumpStartModelError: If any of the dependencies required by the script have | ||
known security vulnerabilities. | ||
DeprecatedJumpStartModelError: If the version of the model is deprecated. | ||
NotImplementedError: If the combination of arguments doesn't support combined model | ||
and script artifact. | ||
""" | ||
if region is None: | ||
region = JUMPSTART_DEFAULT_REGION_NAME | ||
|
@@ -218,10 +223,24 @@ def _retrieve_model_uri( | |
tolerate_deprecated_model=tolerate_deprecated_model, | ||
) | ||
|
||
error_msg_no_combined_artifact = ( | ||
"No combined script + model tarball available " | ||
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. nit: |
||
f"for {model_id} with version {model_version} for {model_scope}." | ||
) | ||
|
||
if model_scope == JumpStartScriptScope.INFERENCE: | ||
model_artifact_key = model_specs.hosting_artifact_key | ||
if not include_script: | ||
model_artifact_key = model_specs.hosting_artifact_key | ||
else: | ||
model_artifact_key = getattr(model_specs, "hosting_prepacked_artifact_key", None) | ||
if model_artifact_key is None: | ||
raise NotImplementedError(error_msg_no_combined_artifact) | ||
|
||
elif model_scope == JumpStartScriptScope.TRAINING: | ||
model_artifact_key = model_specs.training_artifact_key | ||
if not include_script: | ||
model_artifact_key = model_specs.training_artifact_key | ||
else: | ||
raise NotImplementedError(error_msg_no_combined_artifact) | ||
|
||
bucket = os.environ.get( | ||
ENV_VARIABLE_JUMPSTART_MODEL_ARTIFACT_BUCKET_OVERRIDE | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,6 +293,7 @@ class JumpStartModelSpecs(JumpStartDataHolderType): | |
"training_vulnerabilities", | ||
"deprecated", | ||
"metrics", | ||
"hosting_prepacked_artifact_key", | ||
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. Would you be opposed to adding the 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. Let's do that in another PR |
||
] | ||
|
||
def __init__(self, spec: Dict[str, Any]): | ||
|
@@ -330,6 +331,9 @@ def from_json(self, json_obj: Dict[str, Any]) -> None: | |
self.training_vulnerabilities: List[str] = json_obj["training_vulnerabilities"] | ||
self.deprecated: bool = bool(json_obj["deprecated"]) | ||
self.metrics: Optional[List[Dict[str, str]]] = json_obj.get("metrics", None) | ||
self.hosting_prepacked_artifact_key: Optional[str] = json_obj.get( | ||
"hosting_prepacked_artifact_key", None | ||
) | ||
|
||
if self.training_supported: | ||
self.training_ecr_specs: JumpStartECRSpecs = JumpStartECRSpecs( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# 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. | ||
from __future__ import absolute_import | ||
|
||
from mock.mock import patch | ||
|
||
from sagemaker import model_uris | ||
import pytest | ||
|
||
from tests.unit.sagemaker.jumpstart.utils import get_prototype_model_spec | ||
|
||
|
||
@patch("sagemaker.jumpstart.accessors.JumpStartModelsAccessor.get_model_specs") | ||
def test_jumpstart_combined_artifacts(patched_get_model_specs): | ||
|
||
patched_get_model_specs.side_effect = get_prototype_model_spec | ||
|
||
model_id_combined_model_artifact = "huggingface-text2text-flan-t5-xxl-fp16" | ||
|
||
uri = model_uris.retrieve( | ||
region="us-west-2", | ||
model_scope="inference", | ||
model_id=model_id_combined_model_artifact, | ||
model_version="*", | ||
include_script=True, | ||
) | ||
assert ( | ||
uri == "s3://jumpstart-cache-prod-us-west-2/huggingface-infer/" | ||
"prepack/v1.0.0/infer-prepack-huggingface-text2text-flan-t5-xxl-fp16.tar.gz" | ||
) | ||
|
||
with pytest.raises(NotImplementedError): | ||
model_uris.retrieve( | ||
region="us-west-2", | ||
model_scope="transfer_learning", | ||
model_id=model_id_combined_model_artifact, | ||
model_version="*", | ||
include_script=True, | ||
) | ||
|
||
model_id_combined_model_artifact_unsupported = "xgboost-classification-model" | ||
|
||
with pytest.raises(NotImplementedError): | ||
model_uris.retrieve( | ||
region="us-west-2", | ||
model_scope="inference", | ||
model_id=model_id_combined_model_artifact_unsupported, | ||
model_version="*", | ||
include_script=True, | ||
) |
Uh oh!
There was an error while loading. Please reload this page.