Skip to content

change: use recommended inference image URI from Neo API #2806

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

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
dde8d00
fix: Set ProcessingStep upload locations deterministically to avoid c…
staubhp Dec 8, 2021
0f72907
fix: Prevent repack_model script from referencing nonexistent directo…
staubhp Dec 9, 2021
0bae071
fix: S3Input - add support for instance attributes (#2754)
mufaddal-rohawala Dec 15, 2021
17fe93e
fix: typos and broken link (#2765)
mohamed-ali Dec 16, 2021
0a8ca6a
fix: Model Registration with BYO scripts (#2797)
sreedes Dec 17, 2021
08c3a7b
change: use recommended inference image uri from Neo API
HappyAmazonian Dec 20, 2021
1d5a5dc
Merge branch 'master' into inference-url
shreyapandit Dec 21, 2021
edbf61f
change InferenceImage lookup in compilation job description API respo…
HappyAmazonian Dec 27, 2021
d28b89f
Merge branch 'inference-url' of https://github.com/HappyAmazonian/sag…
HappyAmazonian Dec 27, 2021
185b4b0
fix: Add ContentType in test_auto_ml_describe
navinns Dec 27, 2021
5ec2ff4
fix: Re-deploy static integ test endpoint if it is not found
Dec 27, 2021
cec05a5
Merge branch 'dev' into inference-url
mufaddal-rohawala Dec 30, 2021
1312575
documentation :SageMaker model parallel library 1.6.0 API doc (#2814)
mchoi8739 Dec 30, 2021
6319bce
fix: fix kmeans test deletion sequence, increment lineage statics (#2…
mufaddal-rohawala Dec 31, 2021
f728e11
Merge branch 'dev' into inference-url
mufaddal-rohawala Dec 31, 2021
beeabbd
fix: Increment static lineage pipeline (#2817)
mufaddal-rohawala Jan 3, 2022
005ded3
Merge branch 'dev' into inference-url
mufaddal-rohawala Jan 3, 2022
81b77c8
fix: Model Registration with BYO scripts (#2797)
sreedes Dec 17, 2021
c8ca3b7
fix: Add ContentType in test_auto_ml_describe
navinns Dec 27, 2021
7104337
fix: Re-deploy static integ test endpoint if it is not found
Dec 27, 2021
ad29a0c
documentation :SageMaker model parallel library 1.6.0 API doc (#2814)
mchoi8739 Dec 30, 2021
bbe6284
fix: fix kmeans test deletion sequence, increment lineage statics (#2…
mufaddal-rohawala Dec 31, 2021
b026769
fix: Increment static lineage pipeline (#2817)
mufaddal-rohawala Jan 3, 2022
439d085
Merge branch 'dev' into inference-url
mufaddal-rohawala Jan 4, 2022
de9ad6b
improve unit tests
HappyAmazonian Jan 4, 2022
6f98534
Merge branch 'inference-url' of https://github.com/HappyAmazonian/sag…
HappyAmazonian Jan 4, 2022
87c1d2c
fix: Fix lineage query integ tests (#2823)
staubhp Jan 5, 2022
b31dd14
Merge branch 'dev' into inference-url
shreyapandit Jan 6, 2022
8210375
fix: fixes unnecessary session call while generating pipeline definit…
xchen909 Jan 10, 2022
972a6d2
feature: Add models_v2 under lineage context (#2800)
yzhu0 Jan 10, 2022
7206b9e
feature: enable python 3.9 (#2802)
mufaddal-rohawala Jan 10, 2022
127c964
change: Update CHANGELOG.md (#2842)
shreyapandit Jan 11, 2022
554d735
fix: update pricing link (#2805)
ahsan-z-khan Jan 11, 2022
431e853
Merge branch 'dev' into inference-url
HappyAmazonian Jan 11, 2022
81af309
feature: Adds support for Serverless inference (#2831)
bhaoz Jan 14, 2022
a949e5f
feature: Add support for SageMaker lineage queries in action (#2853)
yzhu0 Jan 14, 2022
888153b
feature: Adds Lineage queries in artifact, context and trial componen…
yzhu0 Jan 18, 2022
b796a00
feature: Add EMRStep support in Sagemaker pipeline (#2848)
EthanShouhanCheng Jan 18, 2022
9d25fcf
feature: Add support for SageMaker lineage queries context (#2830)
yzhu0 Jan 19, 2022
64e4690
fix: support specifying a facet by its column index
xgchena Oct 30, 2021
814dd3d
doc: more documentation for serverless inference (#2859)
bhaoz Jan 20, 2022
13aa858
Merge branch 'dev' into inference-url
HappyAmazonian Jan 21, 2022
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
9 changes: 9 additions & 0 deletions doc/api/inference/serverless.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Serverless Inference
---------------------

This module contains classes related to Amazon Sagemaker Serverless Inference

.. automodule:: sagemaker.serverless.serverless_inference_config
:members:
:undoc-members:
:show-inheritance:
57 changes: 57 additions & 0 deletions doc/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,63 @@ For more detailed explanations of the classes that this library provides for aut
- `API docs for HyperparameterTuner and parameter range classes <https://sagemaker.readthedocs.io/en/stable/tuner.html>`__
- `API docs for analytics classes <https://sagemaker.readthedocs.io/en/stable/analytics.html>`__

*******************************
SageMaker Serverless Inference
*******************************
Amazon SageMaker Serverless Inference enables you to easily deploy machine learning models for inference without having
to configure or manage the underlying infrastructure. After you trained a model, you can deploy it to Amazon Sagemaker
Serverless endpoint and then invoke the endpoint with the model to get inference results back. More information about
SageMaker Serverless Inference can be found in the `AWS documentation <https://docs.aws.amazon.com/sagemaker/latest/dg/serverless-endpoints.html>`__.

To deploy serverless endpoint, you will need to create a ``ServerlessInferenceConfig``.
If you create ``ServerlessInferenceConfig`` without specifying its arguments, the default ``MemorySizeInMB`` will be **2048** and
the default ``MaxConcurrency`` will be **5** :

.. code:: python

from sagemaker.serverless import ServerlessInferenceConfig

# Create an empty ServerlessInferenceConfig object to use default values
serverless_config = new ServerlessInferenceConfig()

Or you can specify ``MemorySizeInMB`` and ``MaxConcurrency`` in ``ServerlessInferenceConfig`` (example shown below):

.. code:: python

# Specify MemorySizeInMB and MaxConcurrency in the serverless config object
serverless_config = new ServerlessInferenceConfig(
memory_size_in_mb=4096,
max_concurrency=10,
)

Then use the ``ServerlessInferenceConfig`` in the estimator's ``deploy()`` method to deploy a serverless endpoint:

.. code:: python

# Deploys the model that was generated by fit() to a SageMaker serverless endpoint
serverless_predictor = estimator.deploy(serverless_inference_config=serverless_config)

After deployment is complete, you can use predictor's ``predict()`` method to invoke the serverless endpoint just like
real-time endpoints:

.. code:: python

# Serializes data and makes a prediction request to the SageMaker serverless endpoint
response = serverless_predictor.predict(data)

Clean up the endpoint and model if needed after inference:

.. code:: python

# Tears down the SageMaker endpoint and endpoint configuration
serverless_predictor.delete_endpoint()

# Deletes the SageMaker model
serverless_predictor.delete_model()

For more details about ``ServerlessInferenceConfig``,
see the API docs for `Serverless Inference <https://sagemaker.readthedocs.io/en/stable/api/inference/serverless.html>`__

*************************
SageMaker Batch Transform
*************************
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def read_version():
# Declare minimal set for installation
required_packages = [
"attrs",
"boto3>=1.20.18",
"boto3>=1.20.21",
"google-pasta",
"numpy>=1.9.0",
"protobuf>=3.1",
Expand Down
65 changes: 45 additions & 20 deletions src/sagemaker/clarify.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,33 +111,58 @@ def __init__(
"""Initializes a configuration of the sensitive groups in the dataset.

Args:
label_values_or_threshold (Any): List of label values or threshold to indicate positive
outcome used for bias metrics.
facet_name (str or [str]): String or List of strings of sensitive attribute(s) in the
input data for which we like to compare metrics.
facet_values_or_threshold (list): Optional list of values to form a sensitive group or
threshold for a numeric facet column that defines the lower bound of a sensitive
group. Defaults to considering each possible value as sensitive group and
computing metrics vs all the other examples.
If facet_name is a list, this needs to be None or a List consisting of lists or None
with the same length as facet_name list.
label_values_or_threshold ([int or float or str]): List of label value(s) or threshold
to indicate positive outcome used for bias metrics. Dependency on the problem type,

* Binary problem: The list shall include one positive value.
* Categorical problem: The list shall include one or more (but not all) categories
which are the positive values.
* Regression problem: The list shall include one threshold that defines the lower
bound of positive values.

facet_name (str or int or [str] or [int]): Sensitive attribute column name (or index in
the input data) for which you like to compute bias metrics. It can also be a list
of names (or indexes) if you like to compute for multiple sensitive attributes.
facet_values_or_threshold ([int or float or str] or [[int or float or str]]):
The parameter indicates the sensitive group. If facet_name is a scalar, then it can
be None or a list. Depending on the data type of the facet column,

* Binary: None means computing the bias metrics for each binary value. Or add one
binary value to the list, to compute its bias metrics only.
* Categorical: None means computing the bias metrics for each category. Or add one
or more (but not all) categories to the list, to compute their bias metrics v.s.
the other categories.
* Continuous: The list shall include one and only one threshold which defines the
lower bound of a sensitive group.

If facet_name is a list, then it can be None if all facets are of binary type or
categorical type. Otherwise it shall be a list, and each element is the values or
threshold of the corresponding facet.
group_name (str): Optional column name or index to indicate a group column to be used
for the bias metric 'Conditional Demographic Disparity in Labels - CDDL' or
'Conditional Demographic Disparity in Predicted Labels - CDDPL'.
"""
if isinstance(facet_name, str):
if isinstance(facet_name, list):
assert len(facet_name) > 0, "Please provide at least one facet"
if facet_values_or_threshold is None:
facet_list = [
{"name_or_index": single_facet_name} for single_facet_name in facet_name
]
elif len(facet_values_or_threshold) == len(facet_name):
facet_list = []
for i, single_facet_name in enumerate(facet_name):
facet = {"name_or_index": single_facet_name}
if facet_values_or_threshold is not None:
_set(facet_values_or_threshold[i], "value_or_threshold", facet)
facet_list.append(facet)
else:
raise ValueError(
"The number of facet names doesn't match the number of facet values"
)
else:
facet = {"name_or_index": facet_name}
_set(facet_values_or_threshold, "value_or_threshold", facet)
facet_list = [facet]
elif facet_values_or_threshold is None or len(facet_name) == len(facet_values_or_threshold):
facet_list = []
for i, single_facet_name in enumerate(facet_name):
facet = {"name_or_index": single_facet_name}
if facet_values_or_threshold is not None:
_set(facet_values_or_threshold[i], "value_or_threshold", facet)
facet_list.append(facet)
else:
raise ValueError("Wrong combination of argument values passed")
self.analysis_config = {
"label_values_or_threshold": label_values_or_threshold,
"facet": facet_list,
Expand Down
26 changes: 19 additions & 7 deletions src/sagemaker/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,8 @@ def logs(self):

def deploy(
self,
initial_instance_count,
instance_type,
initial_instance_count=None,
instance_type=None,
serializer=None,
deserializer=None,
accelerator_type=None,
Expand All @@ -864,6 +864,7 @@ def deploy(
kms_key=None,
data_capture_config=None,
tags=None,
serverless_inference_config=None,
**kwargs,
):
"""Deploy the trained model to an Amazon SageMaker endpoint.
Expand All @@ -874,10 +875,14 @@ def deploy(
http://docs.aws.amazon.com/sagemaker/latest/dg/how-it-works-training.html

Args:
initial_instance_count (int): Minimum number of EC2 instances to
deploy to an endpoint for prediction.
instance_type (str): Type of EC2 instance to deploy to an endpoint
for prediction, for example, 'ml.c4.xlarge'.
initial_instance_count (int): The initial number of instances to run
in the ``Endpoint`` created from this ``Model``. If not using
serverless inference, then it need to be a number larger or equals
to 1 (default: None)
instance_type (str): The EC2 instance type to deploy this Model to.
For example, 'ml.p2.xlarge', or 'local' for local mode. If not using
serverless inference, then it is required to deploy a model.
(default: None)
serializer (:class:`~sagemaker.serializers.BaseSerializer`): A
serializer object, used to encode data for an inference endpoint
(default: None). If ``serializer`` is not None, then
Expand Down Expand Up @@ -910,6 +915,11 @@ def deploy(
data_capture_config (sagemaker.model_monitor.DataCaptureConfig): Specifies
configuration related to Endpoint data capture for use with
Amazon SageMaker Model Monitoring. Default: None.
serverless_inference_config (sagemaker.serverless.ServerlessInferenceConfig):
Specifies configuration related to serverless endpoint. Use this configuration
when trying to create serverless endpoint and make serverless inference. If
empty object passed through, we will use pre-defined values in
``ServerlessInferenceConfig`` class to deploy serverless endpoint (default: None)
tags(List[dict[str, str]]): Optional. The list of tags to attach to this specific
endpoint. Example:
>>> tags = [{'Key': 'tagname', 'Value': 'tagvalue'}]
Expand All @@ -927,14 +937,15 @@ def deploy(
endpoint and obtain inferences.
"""
removed_kwargs("update_endpoint", kwargs)
is_serverless = serverless_inference_config is not None
self._ensure_latest_training_job()
self._ensure_base_job_name()
default_name = name_from_base(self.base_job_name)
endpoint_name = endpoint_name or default_name
model_name = model_name or default_name

self.deploy_instance_type = instance_type
if use_compiled_model:
if use_compiled_model and not is_serverless:
family = "_".join(instance_type.split(".")[:-1])
if family not in self._compiled_models:
raise ValueError(
Expand All @@ -959,6 +970,7 @@ def deploy(
wait=wait,
kms_key=kms_key,
data_capture_config=data_capture_config,
serverless_inference_config=serverless_inference_config,
)

def register(
Expand Down
98 changes: 95 additions & 3 deletions src/sagemaker/lineage/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@
"""This module contains code to create and manage SageMaker ``Actions``."""
from __future__ import absolute_import

from typing import Optional, Iterator
from typing import Optional, Iterator, List
from datetime import datetime

from sagemaker import Session
from sagemaker.session import Session
from sagemaker.apiutils import _base_types
from sagemaker.lineage import _api_types, _utils
from sagemaker.lineage._api_types import ActionSource, ActionSummary
from sagemaker.lineage.artifact import Artifact

from sagemaker.lineage.query import (
LineageQuery,
LineageFilter,
LineageSourceEnum,
LineageEntityEnum,
LineageQueryDirectionEnum,
)


class Action(_base_types.Record):
Expand Down Expand Up @@ -116,7 +125,7 @@ def delete(self, disassociate: bool = False):
self._invoke_api(self._boto_delete_method, self._boto_delete_members)

@classmethod
def load(cls, action_name: str, sagemaker_session: Session = None) -> "Action":
def load(cls, action_name: str, sagemaker_session=None) -> "Action":
"""Load an existing action and return an ``Action`` object representing it.

Args:
Expand Down Expand Up @@ -250,3 +259,86 @@ def list(
max_results=max_results,
next_token=next_token,
)

def artifacts(
self, direction: LineageQueryDirectionEnum = LineageQueryDirectionEnum.BOTH
) -> List[Artifact]:
"""Use a lineage query to retrieve all artifacts that use this action.

Args:
direction (LineageQueryDirectionEnum, optional): The query direction.

Returns:
list of Artifacts: Artifacts.
"""
query_filter = LineageFilter(entities=[LineageEntityEnum.ARTIFACT])
query_result = LineageQuery(self.sagemaker_session).query(
start_arns=[self.action_arn],
query_filter=query_filter,
direction=direction,
include_edges=False,
)
return [vertex.to_lineage_object() for vertex in query_result.vertices]


class ModelPackageApprovalAction(Action):
"""An Amazon SageMaker model package approval action, which is part of a SageMaker lineage."""

def datasets(
self, direction: LineageQueryDirectionEnum = LineageQueryDirectionEnum.ASCENDANTS
) -> List[Artifact]:
"""Use a lineage query to retrieve all upstream datasets that use this action.

Args:
direction (LineageQueryDirectionEnum, optional): The query direction.

Returns:
list of Artifacts: Artifacts representing a dataset.
"""
query_filter = LineageFilter(
entities=[LineageEntityEnum.ARTIFACT], sources=[LineageSourceEnum.DATASET]
)
query_result = LineageQuery(self.sagemaker_session).query(
start_arns=[self.action_arn],
query_filter=query_filter,
direction=direction,
include_edges=False,
)
return [vertex.to_lineage_object() for vertex in query_result.vertices]

def model_package(self):
"""Get model package from model package approval action.

Returns:
Model package.
"""
source_uri = self.source.source_uri
if source_uri is None:
return None

model_package_name = source_uri.split("/")[1]
return self.sagemaker_session.sagemaker_client.describe_model_package(
ModelPackageName=model_package_name
)

def endpoints(
self, direction: LineageQueryDirectionEnum = LineageQueryDirectionEnum.DESCENDANTS
) -> List:
"""Use a lineage query to retrieve downstream endpoint contexts that use this action.

Args:
direction (LineageQueryDirectionEnum, optional): The query direction.

Returns:
list of Contexts: Contexts representing an endpoint.
"""
query_filter = LineageFilter(
entities=[LineageEntityEnum.CONTEXT], sources=[LineageSourceEnum.ENDPOINT]
)
query_result = LineageQuery(self.sagemaker_session).query(
start_arns=[self.action_arn],
query_filter=query_filter,
direction=direction,
include_edges=False,
)
return [vertex.to_lineage_object() for vertex in query_result.vertices]
Loading