Skip to content

Merge master into benchmark feature #4652

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
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## v2.218.1 (2024-05-03)

### Bug Fixes and Other Changes

* Fix UserAgent logging in Python SDK
* chore: release tgi 2.0.1
* chore: update skipped flaky tests

## v2.218.0 (2024-05-01)

### Features
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.218.1.dev0
2.218.2.dev0
49 changes: 48 additions & 1 deletion src/sagemaker/image_uri_config/huggingface-llm.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"1.2": "1.2.0",
"1.3": "1.3.3",
"1.4": "1.4.5",
"2.0": "2.0.0"
"2.0": "2.0.1"
},
"versions": {
"0.6.0": {
Expand Down Expand Up @@ -578,6 +578,53 @@
"container_version": {
"gpu": "cu121-ubuntu22.04"
}
},
"2.0.1": {
"py_versions": [
"py310"
],
"registries": {
"af-south-1": "626614931356",
"il-central-1": "780543022126",
"ap-east-1": "871362719292",
"ap-northeast-1": "763104351884",
"ap-northeast-2": "763104351884",
"ap-northeast-3": "364406365360",
"ap-south-1": "763104351884",
"ap-south-2": "772153158452",
"ap-southeast-1": "763104351884",
"ap-southeast-2": "763104351884",
"ap-southeast-3": "907027046896",
"ap-southeast-4": "457447274322",
"ca-central-1": "763104351884",
"cn-north-1": "727897471807",
"cn-northwest-1": "727897471807",
"eu-central-1": "763104351884",
"eu-central-2": "380420809688",
"eu-north-1": "763104351884",
"eu-west-1": "763104351884",
"eu-west-2": "763104351884",
"eu-west-3": "763104351884",
"eu-south-1": "692866216735",
"eu-south-2": "503227376785",
"me-south-1": "217643126080",
"me-central-1": "914824155844",
"sa-east-1": "763104351884",
"us-east-1": "763104351884",
"us-east-2": "763104351884",
"us-gov-east-1": "446045086412",
"us-gov-west-1": "442386744353",
"us-iso-east-1": "886529160074",
"us-isob-east-1": "094389454867",
"us-west-1": "763104351884",
"us-west-2": "763104351884",
"ca-west-1": "204538143572"
},
"tag_prefix": "2.1.1-tgi2.0.1",
"repository": "huggingface-pytorch-tgi-inference",
"container_version": {
"gpu": "cu121-ubuntu22.04"
}
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/sagemaker/jumpstart/notebook_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,12 @@ def list_jumpstart_models( # pylint: disable=redefined-builtin
return sorted(list(model_id_version_dict.keys()))

if not list_old_models:
model_id_version_dict = {
model_id: set([max(versions)]) for model_id, versions in model_id_version_dict.items()
}
for model_id, versions in model_id_version_dict.items():
try:
model_id_version_dict.update({model_id: set([max(versions)])})
except TypeError:
versions = [str(v) for v in versions]
model_id_version_dict.update({model_id: set([max(versions)])})

model_id_version_set: Set[Tuple[str, str]] = set()
for model_id in model_id_version_dict:
Expand Down
6 changes: 5 additions & 1 deletion src/sagemaker/jumpstart/payload_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from sagemaker.jumpstart.constants import (
DEFAULT_JUMPSTART_SAGEMAKER_SESSION,
)
from sagemaker.jumpstart.enums import MIMEType
from sagemaker.jumpstart.enums import JumpStartModelType, MIMEType
from sagemaker.jumpstart.types import JumpStartSerializablePayload
from sagemaker.jumpstart.utils import (
get_jumpstart_content_bucket,
Expand Down Expand Up @@ -61,6 +61,7 @@ def _construct_payload(
tolerate_vulnerable_model: bool = False,
tolerate_deprecated_model: bool = False,
sagemaker_session: Session = DEFAULT_JUMPSTART_SAGEMAKER_SESSION,
model_type: JumpStartModelType = JumpStartModelType.OPEN_WEIGHTS,
) -> Optional[JumpStartSerializablePayload]:
"""Returns example payload from prompt.

Expand All @@ -83,6 +84,8 @@ def _construct_payload(
object, used for SageMaker interactions. If not
specified, one is created using the default AWS configuration
chain. (Default: sagemaker.jumpstart.constants.DEFAULT_JUMPSTART_SAGEMAKER_SESSION).
model_type (JumpStartModelType): The type of the model, can be open weights model or
proprietary model. (Default: JumpStartModelType.OPEN_WEIGHTS).
Returns:
Optional[JumpStartSerializablePayload]: serializable payload with prompt, or None if
this feature is unavailable for the specified model.
Expand All @@ -94,6 +97,7 @@ def _construct_payload(
tolerate_vulnerable_model=tolerate_vulnerable_model,
tolerate_deprecated_model=tolerate_deprecated_model,
sagemaker_session=sagemaker_session,
model_type=model_type,
)
if payloads is None or len(payloads) == 0:
return None
Expand Down
2 changes: 1 addition & 1 deletion src/sagemaker/jumpstart/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ def __init__(
config (Dict[str, Any]):
Dictionary representation of the config.
base_fields (Dict[str, Any]):
The default base fields that are used to construct the final resolved config.
The default base fields that are used to construct the resolved config.
config_components (Dict[str, JumpStartConfigComponent]):
The list of components that are used to construct the resolved config.
"""
Expand Down
29 changes: 21 additions & 8 deletions src/sagemaker/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
from sagemaker.deprecations import deprecated_class
from sagemaker.enums import EndpointType
from sagemaker.inputs import ShuffleConfig, TrainingInput, BatchDataCaptureConfig
from sagemaker.user_agent import prepend_user_agent
from sagemaker.user_agent import get_user_agent_extra_suffix
from sagemaker.utils import (
name_from_image,
secondary_training_status_changed,
Expand Down Expand Up @@ -285,6 +285,7 @@ def _initialize(
Creates or uses a boto_session, sagemaker_client and sagemaker_runtime_client.
Sets the region_name.
"""

self.boto_session = boto_session or boto3.DEFAULT_SESSION or boto3.Session()

self._region_name = self.boto_session.region_name
Expand All @@ -293,19 +294,30 @@ def _initialize(
"Must setup local AWS configuration with a region supported by SageMaker."
)

self.sagemaker_client = sagemaker_client or self.boto_session.client("sagemaker")
prepend_user_agent(self.sagemaker_client)
# Make use of user_agent_extra field of the botocore_config object
# to append SageMaker Python SDK specific user_agent suffix
# to the current User-Agent header value from boto3
# This config will also make sure that user_agent never fails to log the User-Agent string
# even if boto User-Agent header format is updated in the future
# Ref: https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html
botocore_config = botocore.config.Config(user_agent_extra=get_user_agent_extra_suffix())

# Create sagemaker_client with the botocore_config object
# This config is customized to append SageMaker Python SDK specific user_agent suffix
self.sagemaker_client = sagemaker_client or self.boto_session.client(
"sagemaker", config=botocore_config
)

if sagemaker_runtime_client is not None:
self.sagemaker_runtime_client = sagemaker_runtime_client
else:
config = botocore.config.Config(read_timeout=80)
config = botocore.config.Config(
read_timeout=80, user_agent_extra=get_user_agent_extra_suffix()
)
self.sagemaker_runtime_client = self.boto_session.client(
"runtime.sagemaker", config=config
)

prepend_user_agent(self.sagemaker_runtime_client)

if sagemaker_featurestore_runtime_client:
self.sagemaker_featurestore_runtime_client = sagemaker_featurestore_runtime_client
else:
Expand All @@ -316,8 +328,9 @@ def _initialize(
if sagemaker_metrics_client:
self.sagemaker_metrics_client = sagemaker_metrics_client
else:
self.sagemaker_metrics_client = self.boto_session.client("sagemaker-metrics")
prepend_user_agent(self.sagemaker_metrics_client)
self.sagemaker_metrics_client = self.boto_session.client(
"sagemaker-metrics", config=botocore_config
)

self.s3_client = self.boto_session.client("s3", region_name=self.boto_region_name)
self.s3_resource = self.boto_session.resource("s3", region_name=self.boto_region_name)
Expand Down
45 changes: 8 additions & 37 deletions src/sagemaker/user_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
"""Placeholder docstring"""
from __future__ import absolute_import

import platform
import sys
import json
import os

Expand All @@ -28,12 +26,6 @@
STUDIO_METADATA_FILE = "/opt/ml/metadata/resource-metadata.json"

SDK_VERSION = importlib_metadata.version("sagemaker")
OS_NAME = platform.system() or "UnresolvedOS"
OS_VERSION = platform.release() or "UnresolvedOSVersion"
OS_NAME_VERSION = "{}/{}".format(OS_NAME, OS_VERSION)
PYTHON_VERSION = "Python/{}.{}.{}".format(
sys.version_info.major, sys.version_info.minor, sys.version_info.micro
)


def process_notebook_metadata_file():
Expand Down Expand Up @@ -63,45 +55,24 @@ def process_studio_metadata_file():
return None


def determine_prefix(user_agent=""):
"""Determines the prefix for the user agent string.
def get_user_agent_extra_suffix():
"""Get the user agent extra suffix string specific to SageMaker Python SDK

Args:
user_agent (str): The user agent string to prepend the prefix to.
Adhers to new boto recommended User-Agent 2.0 header format

Returns:
str: The user agent string with the prefix prepended.
str: The user agent extra suffix string to be appended
"""
prefix = "{}/{}".format(SDK_PREFIX, SDK_VERSION)

if PYTHON_VERSION not in user_agent:
prefix = "{} {}".format(prefix, PYTHON_VERSION)

if OS_NAME_VERSION not in user_agent:
prefix = "{} {}".format(prefix, OS_NAME_VERSION)
suffix = "lib/{}#{}".format(SDK_PREFIX, SDK_VERSION)

# Get the notebook instance type and prepend it to the user agent string if exists
notebook_instance_type = process_notebook_metadata_file()
if notebook_instance_type:
prefix = "{} {}/{}".format(prefix, NOTEBOOK_PREFIX, notebook_instance_type)
suffix = "{} md/{}#{}".format(suffix, NOTEBOOK_PREFIX, notebook_instance_type)

# Get the studio app type and prepend it to the user agent string if exists
studio_app_type = process_studio_metadata_file()
if studio_app_type:
prefix = "{} {}/{}".format(prefix, STUDIO_PREFIX, studio_app_type)

return prefix


def prepend_user_agent(client):
"""Prepends the user agent string with the SageMaker Python SDK version.

Args:
client (botocore.client.BaseClient): The client to prepend the user agent string for.
"""
prefix = determine_prefix(client._client_config.user_agent)
suffix = "{} md/{}#{}".format(suffix, STUDIO_PREFIX, studio_app_type)

if client._client_config.user_agent is None:
client._client_config.user_agent = prefix
else:
client._client_config.user_agent = "{} {}".format(prefix, client._client_config.user_agent)
return suffix
1 change: 1 addition & 0 deletions tests/unit/sagemaker/image_uris/test_huggingface_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"1.4.2": "2.1.1-tgi1.4.2-gpu-py310-cu121-ubuntu22.04",
"1.4.5": "2.1.1-tgi1.4.5-gpu-py310-cu121-ubuntu22.04",
"2.0.0": "2.1.1-tgi2.0.0-gpu-py310-cu121-ubuntu22.04",
"2.0.1": "2.1.1-tgi2.0.1-gpu-py310-cu121-ubuntu22.04",
},
"inf2": {
"0.0.16": "1.13.1-optimum0.0.16-neuronx-py310-ubuntu22.04",
Expand Down
Loading