Skip to content

feat: jumpstart instance types #3686

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 21 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c28134a
feat: jumpstart instance types
evakravi Feb 28, 2023
37ad9e4
Merge branch 'master' into feat/jumpstart-instance-types
evakravi Mar 6, 2023
7baec98
chore: raise exception when no instances available in region
evakravi Mar 16, 2023
1da64e7
Merge remote-tracking branch 'origin' into feat/jumpstart-instance-types
evakravi Mar 16, 2023
975def8
chore: update integ test
evakravi Mar 16, 2023
54e6754
chore: address PR comments
evakravi Mar 20, 2023
af7639a
Merge remote-tracking branch 'origin' into feat/jumpstart-instance-types
evakravi Mar 20, 2023
980ea50
Merge branch 'master' into feat/jumpstart-instance-types
evakravi Mar 21, 2023
0375b61
chore: improve function name
evakravi Mar 21, 2023
a1a5d8c
Merge branch 'master' into feat/jumpstart-instance-types
evakravi Mar 22, 2023
ca767f4
Merge branch 'master' into feat/jumpstart-instance-types
evakravi Mar 23, 2023
044fcb2
Merge branch 'master' into feat/jumpstart-instance-types
evakravi Mar 23, 2023
d3424ab
Merge branch 'master' into feat/jumpstart-instance-types
evakravi Mar 23, 2023
9bc9629
Merge branch 'master' into feat/jumpstart-instance-types
evakravi Mar 24, 2023
db599df
Merge remote-tracking branch 'origin' into feat/jumpstart-instance-types
evakravi Mar 25, 2023
40d8680
fix: flake8 errors
evakravi Mar 27, 2023
4058e22
Merge branch 'master' into feat/jumpstart-instance-types
evakravi Mar 28, 2023
f9e2fb4
Merge branch 'master' into feat/jumpstart-instance-types
evakravi Mar 29, 2023
9a46fcb
Merge branch 'master' into feat/jumpstart-instance-types
evakravi Mar 29, 2023
d3c77aa
Merge branch 'master' into feat/jumpstart-instance-types
evakravi Mar 29, 2023
516da5b
Merge branch 'master' into feat/jumpstart-instance-types
evakravi Mar 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/sagemaker/environment_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def retrieve_default(
region=None,
model_id=None,
model_version=None,
tolerate_vulnerable_model: bool = False,
tolerate_deprecated_model: bool = False,
) -> Dict[str, str]:
"""Retrieves the default container environment variables for the model matching the arguments.

Expand All @@ -37,6 +39,13 @@ def retrieve_default(
retrieve the default environment variables. (Default: None).
model_version (str): Optional. The version of the model for which to retrieve the
default environment variables. (Default: None).
tolerate_vulnerable_model (bool): True if vulnerable versions of model
specifications should be tolerated (exception not raised). If False, raises an
exception if the script used by this version of the model has dependencies with known
security vulnerabilities. (Default: False).
tolerate_deprecated_model (bool): True if deprecated models should be tolerated
(exception not raised). False if these models should raise an exception.
(Default: False).
Returns:
dict: The variables to use for the model.

Expand All @@ -48,4 +57,6 @@ def retrieve_default(
"Must specify `model_id` and `model_version` when retrieving environment variables."
)

return artifacts._retrieve_default_environment_variables(model_id, model_version, region)
return artifacts._retrieve_default_environment_variables(
model_id, model_version, region, tolerate_vulnerable_model, tolerate_deprecated_model
)
21 changes: 19 additions & 2 deletions src/sagemaker/hyperparameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def retrieve_default(
model_id=None,
model_version=None,
include_container_hyperparameters=False,
tolerate_vulnerable_model: bool = False,
tolerate_deprecated_model: bool = False,
) -> Dict[str, str]:
"""Retrieves the default training hyperparameters for the model matching the given arguments.

Expand All @@ -47,6 +49,13 @@ def retrieve_default(
that indicates the entrypoint script to use. These hyperparameters may be required
when creating a training job with boto3, however the ``Estimator`` classes
add required container hyperparameters to the job. (Default: False).
tolerate_vulnerable_model (bool): True if vulnerable versions of model
specifications should be tolerated (exception not raised). If False, raises an
exception if the script used by this version of the model has dependencies with known
security vulnerabilities. (Default: False).
tolerate_deprecated_model (bool): True if deprecated models should be tolerated
(exception not raised). False if these models should raise an exception.
(Default: False).
Returns:
dict: The hyperparameters to use for the model.

Expand All @@ -59,7 +68,12 @@ def retrieve_default(
)

return artifacts._retrieve_default_hyperparameters(
model_id, model_version, region, include_container_hyperparameters
model_id,
model_version,
region,
include_container_hyperparameters,
tolerate_vulnerable_model,
tolerate_deprecated_model,
)


Expand All @@ -68,7 +82,7 @@ def validate(
model_id: Optional[str] = None,
model_version: Optional[str] = None,
hyperparameters: Optional[dict] = None,
validation_mode: Optional[HyperparameterValidationMode] = None,
validation_mode: HyperparameterValidationMode = HyperparameterValidationMode.VALIDATE_PROVIDED,
) -> None:
"""Validates hyperparameters for models.

Expand Down Expand Up @@ -99,6 +113,9 @@ def validate(
"Must specify `model_id` and `model_version` when validating hyperparameters."
)

if model_id is None or model_version is None:
raise RuntimeError("Model id and version must both be non-None")

if hyperparameters is None:
raise ValueError("Must specify hyperparameters.")

Expand Down
121 changes: 121 additions & 0 deletions src/sagemaker/instance_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# 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.
"""Accessors to retrieve instance types."""

from __future__ import absolute_import

import logging
from typing import List

from sagemaker.jumpstart import utils as jumpstart_utils
from sagemaker.jumpstart import artifacts

logger = logging.getLogger(__name__)


def retrieve_default(
region=None,
model_id=None,
model_version=None,
scope=None,
tolerate_vulnerable_model: bool = False,
tolerate_deprecated_model: bool = False,
) -> str:
"""Retrieves the default instance type for the model matching the given arguments.

Args:
region (str): The AWS Region for which to retrieve the default instance type.
Defaults to ``None``.
model_id (str): The model ID of the model for which to
retrieve the default instance type. (Default: None).
model_version (str): The version of the model for which to retrieve the
default instance type. (Default: None).
scope (str): The model type, i.e. what it is used for.
Valid values: "training" and "inference".
tolerate_vulnerable_model (bool): True if vulnerable versions of model
specifications should be tolerated (exception not raised). If False, raises an
exception if the script used by this version of the model has dependencies with known
security vulnerabilities. (Default: False).
tolerate_deprecated_model (bool): True if deprecated models should be tolerated
(exception not raised). False if these models should raise an exception.
(Default: False).
Returns:
str: The default instance type to use for the model.

Raises:
ValueError: If the combination of arguments specified is not supported.
"""
if not jumpstart_utils.is_jumpstart_model_input(model_id, model_version):
raise ValueError(
"Must specify `model_id` and `model_version` when retrieving instance types."
)

if scope is None:
raise ValueError("Must specify scope for instance types.")

return artifacts._retrieve_default_instance_type(
model_id,
model_version,
scope,
region,
tolerate_vulnerable_model,
tolerate_deprecated_model,
)


def retrieve(
region=None,
model_id=None,
model_version=None,
scope=None,
tolerate_vulnerable_model: bool = False,
tolerate_deprecated_model: bool = False,
) -> List[str]:
"""Retrieves the supported training instance types for the model matching the given arguments.

Args:
region (str): The AWS Region for which to retrieve the supported instance types.
Defaults to ``None``.
model_id (str): The model ID of the model for which to
retrieve the supported instance types. (Default: None).
model_version (str): The version of the model for which to retrieve the
supported instance types. (Default: None).
tolerate_vulnerable_model (bool): True if vulnerable versions of model
specifications should be tolerated (exception not raised). If False, raises an
exception if the script used by this version of the model has dependencies with known
security vulnerabilities. (Default: False).
tolerate_deprecated_model (bool): True if deprecated models should be tolerated
(exception not raised). False if these models should raise an exception.
(Default: False).
Returns:
list: The supported instance types to use for the model.

Raises:
ValueError: If the combination of arguments specified is not supported.
"""
if not jumpstart_utils.is_jumpstart_model_input(model_id, model_version):
raise ValueError(
"Must specify `model_id` and `model_version` when retrieving instance types."
)

if scope is None:
raise ValueError("Must specify scope for instance types.")

return artifacts._retrieve_instance_types(
model_id,
model_version,
scope,
region,
tolerate_vulnerable_model,
tolerate_deprecated_model,
)
Loading