Skip to content

Add support to delete model within Predictor and Pipeline class. #647

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 15 commits into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 8 additions & 4 deletions src/sagemaker/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,15 @@ def delete_model(self):
"""Deletes the Amazon SageMaker models backing this predictor.

"""
try:
for model_name in self._model_names:
request_failed = False
for model_name in self._model_names:
try:
self.sagemaker_session.delete_model(model_name)
except Exception:
raise Exception('One or more models cannot be deleted, the deletion is incomplete.')
except Exception: # pylint: disable=broad-except
request_failed = True

if request_failed:
raise Exception('One or more models cannot be deleted, please retry.')
Copy link
Contributor

Choose a reason for hiding this comment

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

let's print the failed model names here as well


def _get_endpoint_config_name(self):
endpoint_desc = self.sagemaker_session.sagemaker_client.describe_endpoint(EndpointName=self.endpoint)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def test_delete_model():
def test_delete_model_fail():
sagemaker_session = empty_sagemaker_session()
sagemaker_session.sagemaker_client.delete_model = Mock(side_effect='Could not find model.')
expected_error_message = 'One or more models cannot be deleted, the deletion is incomplete.'
expected_error_message = 'One or more models cannot be deleted, please retry.'

predictor = RealTimePredictor(ENDPOINT, sagemaker_session=sagemaker_session)

Expand Down