Skip to content

fix: fix tags in deploy call for generic estimators #1146

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 3 commits into from
Dec 5, 2019
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
15 changes: 8 additions & 7 deletions src/sagemaker/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ def deploy(
model_name=None,
kms_key=None,
data_capture_config=None,
tags=None,
**kwargs
):
"""Deploy the trained model to an Amazon SageMaker endpoint and return a
Expand Down Expand Up @@ -639,18 +640,18 @@ def deploy(
model completes (default: True).
model_name (str): Name to use for creating an Amazon SageMaker
model. If not specified, the name of the training job is used.
tags(List[dict[str, str]]): Optional. The list of tags to attach to this specific
endpoint. Example:
>>> tags = [{'Key': 'tagname', 'Value': 'tagvalue'}]
For more information about tags, see
https://boto3.amazonaws.com/v1/documentation\
/api/latest/reference/services/sagemaker.html#SageMaker.Client.add_tags
kms_key (str): The ARN of the KMS key that is used to encrypt the
data on the storage volume attached to the instance hosting the
endpoint.
data_capture_config (sagemaker.model_monitor.DataCaptureConfig): Specifies
configuration related to Endpoint data capture for use with
Amazon SageMaker Model Monitoring. Default: None.
tags(List[dict[str, str]]): Optional. The list of tags to attach to this specific
endpoint. Example:
>>> tags = [{'Key': 'tagname', 'Value': 'tagvalue'}]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need newlines around the ">>>" line for the formatting to work out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the >>> doesn't work as intended as shown here: https://sagemaker.readthedocs.io/en/v1.45.0/analytics.html#sagemaker.analytics.HyperparameterTuningJobAnalytics.tuning_ranges

Will fix in another PR D:

For more information about tags, see
https://boto3.amazonaws.com/v1/documentation\
/api/latest/reference/services/sagemaker.html#SageMaker.Client.add_tags
**kwargs: Passed to invocation of ``create_model()``.
Implementations may customize ``create_model()`` to accept
``**kwargs`` to customize model creation during deploy.
Expand Down Expand Up @@ -685,7 +686,7 @@ def deploy(
accelerator_type=accelerator_type,
endpoint_name=endpoint_name,
update_endpoint=update_endpoint,
tags=self.tags,
tags=tags or self.tags,
wait=wait,
kms_key=kms_key,
data_capture_config=data_capture_config,
Expand Down
42 changes: 41 additions & 1 deletion tests/unit/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,7 @@ def test_unsupported_type_in_dict():
)


def test_fit_deploy_keep_tags(sagemaker_session):
def test_fit_deploy_tags_in_estimator(sagemaker_session):
tags = [{"Key": "TagtestKey", "Value": "TagtestValue"}]
estimator = Estimator(
IMAGE_NAME,
Expand Down Expand Up @@ -1747,6 +1747,46 @@ def test_fit_deploy_keep_tags(sagemaker_session):
)


def test_fit_deploy_tags(sagemaker_session):
estimator = Estimator(
IMAGE_NAME, ROLE, INSTANCE_COUNT, INSTANCE_TYPE, sagemaker_session=sagemaker_session
)

estimator.fit()

tags = [{"Key": "TagtestKey", "Value": "TagtestValue"}]
estimator.deploy(INSTANCE_COUNT, INSTANCE_TYPE, tags=tags)

variant = [
{
"InstanceType": "c4.4xlarge",
"VariantName": "AllTraffic",
"ModelName": ANY,
"InitialVariantWeight": 1,
"InitialInstanceCount": 1,
}
]

job_name = estimator._current_job_name
sagemaker_session.endpoint_from_production_variants.assert_called_with(
name=job_name,
production_variants=variant,
tags=tags,
kms_key=None,
wait=True,
data_capture_config_dict=None,
)

sagemaker_session.create_model.assert_called_with(
ANY,
"DummyRole",
{"ModelDataUrl": "s3://bucket/model.tar.gz", "Environment": {}, "Image": "fakeimage"},
enable_network_isolation=False,
vpc_config=None,
tags=tags,
)


def test_generic_to_fit_no_input(sagemaker_session):
e = Estimator(
IMAGE_NAME,
Expand Down