Skip to content

Commit 17116f4

Browse files
authored
Fix pysdk v3 Telemetry (aws#5331)
* Updated Telemetry UserAgent * update SDK version in user agent
1 parent 9827b07 commit 17116f4

File tree

2 files changed

+7
-118
lines changed

2 files changed

+7
-118
lines changed

sagemaker-core/src/sagemaker/core/helper/session_helper.py

Lines changed: 6 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,12 @@ def _initialize(
236236

237237
# Create sagemaker_client with the botocore_config object
238238
# This config is customized to append SageMaker Python SDK specific user_agent suffix
239-
self.sagemaker_client = sagemaker_client or self.boto_session.client("sagemaker")
239+
if sagemaker_client is not None:
240+
self.sagemaker_client = sagemaker_client
241+
else:
242+
from sagemaker.core.user_agent import get_user_agent_extra_suffix
243+
config = botocore.config.Config(user_agent_extra=get_user_agent_extra_suffix())
244+
self.sagemaker_client = self.boto_session.client("sagemaker", config=config)
240245

241246
if sagemaker_runtime_client is not None:
242247
self.sagemaker_runtime_client = sagemaker_runtime_client
@@ -1657,111 +1662,6 @@ def update_inference_component(
16571662
self.wait_for_inference_component(inference_component_name)
16581663
return inference_component_name
16591664

1660-
def transform(
1661-
self,
1662-
job_name,
1663-
model_name,
1664-
strategy,
1665-
max_concurrent_transforms,
1666-
max_payload,
1667-
input_config,
1668-
output_config,
1669-
resource_config,
1670-
experiment_config,
1671-
env: Optional[Dict[str, str]] = None,
1672-
tags=None,
1673-
data_processing=None,
1674-
model_client_config=None,
1675-
batch_data_capture_config: BatchDataCaptureConfig = None,
1676-
):
1677-
"""Create an Amazon SageMaker transform job.
1678-
1679-
Args:
1680-
job_name (str): Name of the transform job being created.
1681-
model_name (str): Name of the SageMaker model being used for the transform job.
1682-
strategy (str): The strategy used to decide how to batch records in a single request.
1683-
Possible values are 'MultiRecord' and 'SingleRecord'.
1684-
max_concurrent_transforms (int): The maximum number of HTTP requests to be made to
1685-
each individual transform container at one time.
1686-
max_payload (int): Maximum size of the payload in a single HTTP request to the
1687-
container in MB.
1688-
env (dict): Environment variables to be set for use during the transform job.
1689-
input_config (dict): A dictionary describing the input data (and its location) for the
1690-
job.
1691-
output_config (dict): A dictionary describing the output location for the job.
1692-
resource_config (dict): A dictionary describing the resources to complete the job.
1693-
experiment_config (dict[str, str]): Experiment management configuration.
1694-
Optionally, the dict can contain three keys:
1695-
'ExperimentName', 'TrialName', and 'TrialComponentDisplayName'.
1696-
The behavior of setting these keys is as follows:
1697-
* If `ExperimentName` is supplied but `TrialName` is not a Trial will be
1698-
automatically created and the job's Trial Component associated with the Trial.
1699-
* If `TrialName` is supplied and the Trial already exists the job's Trial Component
1700-
will be associated with the Trial.
1701-
* If both `ExperimentName` and `TrialName` are not supplied the trial component
1702-
will be unassociated.
1703-
* `TrialComponentDisplayName` is used for display in Studio.
1704-
tags (Optional[Tags]): List of tags for labeling a transform job.
1705-
data_processing(dict): A dictionary describing config for combining the input data and
1706-
transformed data. For more, see
1707-
https://docs.aws.amazon.com/sagemaker/latest/dg/API_Tag.html.
1708-
model_client_config (dict): A dictionary describing the model configuration for the
1709-
job. Dictionary contains two optional keys,
1710-
'InvocationsTimeoutInSeconds', and 'InvocationsMaxRetries'.
1711-
batch_data_capture_config (BatchDataCaptureConfig): Configuration object which
1712-
specifies the configurations related to the batch data capture for the transform job
1713-
"""
1714-
tags = _append_project_tags(format_tags(tags))
1715-
tags = self._append_sagemaker_config_tags(
1716-
tags, "{}.{}.{}".format(SAGEMAKER, TRANSFORM_JOB, TAGS)
1717-
)
1718-
batch_data_capture_config = resolve_class_attribute_from_config(
1719-
None,
1720-
batch_data_capture_config,
1721-
"kms_key_id",
1722-
TRANSFORM_JOB_KMS_KEY_ID_PATH,
1723-
sagemaker_session=self,
1724-
)
1725-
output_config = resolve_nested_dict_value_from_config(
1726-
output_config, [KMS_KEY_ID], TRANSFORM_OUTPUT_KMS_KEY_ID_PATH, sagemaker_session=self
1727-
)
1728-
resource_config = resolve_nested_dict_value_from_config(
1729-
resource_config,
1730-
[VOLUME_KMS_KEY_ID],
1731-
TRANSFORM_JOB_VOLUME_KMS_KEY_ID_PATH,
1732-
sagemaker_session=self,
1733-
)
1734-
env = resolve_value_from_config(
1735-
direct_input=env,
1736-
config_path=TRANSFORM_JOB_ENVIRONMENT_PATH,
1737-
default_value=None,
1738-
sagemaker_session=self,
1739-
)
1740-
1741-
transform_request = self._get_transform_request(
1742-
job_name=job_name,
1743-
model_name=model_name,
1744-
strategy=strategy,
1745-
max_concurrent_transforms=max_concurrent_transforms,
1746-
max_payload=max_payload,
1747-
env=env,
1748-
input_config=input_config,
1749-
output_config=output_config,
1750-
resource_config=resource_config,
1751-
experiment_config=experiment_config,
1752-
tags=tags,
1753-
data_processing=data_processing,
1754-
model_client_config=model_client_config,
1755-
batch_data_capture_config=batch_data_capture_config,
1756-
)
1757-
1758-
def submit(request):
1759-
logger.info("Creating transform job with name: %s", job_name)
1760-
logger.debug("Transform request: %s", json.dumps(request, indent=4))
1761-
self.sagemaker_client.create_transform_job(**request)
1762-
1763-
self._intercept_create_request(transform_request, submit, self.transform.__name__)
1764-
17651665
def _create_model_request(
17661666
self,
17671667
name,

sagemaker-core/src/sagemaker/core/user_agent.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,7 @@
2323
NOTEBOOK_METADATA_FILE = "/etc/opt/ml/sagemaker-notebook-instance-version.txt"
2424
STUDIO_METADATA_FILE = "/opt/ml/metadata/resource-metadata.json"
2525

26-
def _get_sdk_version():
27-
"""Read SDK version from VERSION file"""
28-
current_dir = os.path.dirname(os.path.abspath(__file__))
29-
repo_root = os.path.normpath(os.path.join(current_dir, '../../../..'))
30-
version_file_path = os.path.join(repo_root, 'VERSION')
31-
try:
32-
with open(version_file_path, 'r') as f:
33-
return f.read().strip()
34-
except (FileNotFoundError, IOError):
35-
return "3.0" # fallback version
36-
37-
SDK_VERSION = _get_sdk_version()
26+
SDK_VERSION ="3.0"
3827

3928

4029
def process_notebook_metadata_file():

0 commit comments

Comments
 (0)