Skip to content

breaking: deprecate delete_endpoint() for estimators and HyperparameterTuner #1651

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
Jun 30, 2020
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: 4 additions & 4 deletions doc/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Here is an end to end example of how to use a SageMaker Estimator:
# Deletes the SageMaker model
mxnet_predictor.delete_model()

The example above will eventually delete both the SageMaker endpoint and endpoint configuration through `delete_endpoint()`. If you want to keep your SageMaker endpoint configuration, use the value False for the `delete_endpoint_config` parameter, as shown below.
The example above will eventually delete both the SageMaker endpoint and endpoint configuration through ``delete_endpoint()``. If you want to keep your SageMaker endpoint configuration, use the value ``False`` for the ``delete_endpoint_config`` parameter, as shown below.

.. code:: python

Expand Down Expand Up @@ -180,10 +180,10 @@ Here is an example:
train_input = algo.sagemaker_session.upload_data(path='/path/to/your/data')

algo.fit({'training': train_input})
algo.deploy(1, 'ml.m4.xlarge')
predictor = algo.deploy(1, 'ml.m4.xlarge')

# When you are done using your endpoint
algo.delete_endpoint()
predictor.delete_endpoint()

Use Scripts Stored in a Git Repository
--------------------------------------
Expand Down Expand Up @@ -609,7 +609,7 @@ Here is a basic example of how to use it:
response = my_predictor.predict(my_prediction_data)

# Tear down the SageMaker endpoint
my_tuner.delete_endpoint()
my_predictor.delete_endpoint()

This example shows a hyperparameter tuning job that creates up to 100 training jobs, running up to 10 training jobs at a time.
Each training job's learning rate is a value between 0.05 and 0.06, but this value will differ between training jobs.
Expand Down
9 changes: 0 additions & 9 deletions src/sagemaker/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,15 +820,6 @@ class constructor

return init_params

def delete_endpoint(self):
"""Delete an Amazon SageMaker ``Endpoint``.

Raises:
botocore.exceptions.ClientError: If the endpoint does not exist.
"""
self._ensure_latest_training_job(error_message="Endpoint was not created yet")
self.sagemaker_session.delete_endpoint(self.latest_training_job.name)

def transformer(
self,
instance_count,
Expand Down
12 changes: 0 additions & 12 deletions src/sagemaker/tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,18 +820,6 @@ def _get_best_training_job(self):
)
)

def delete_endpoint(self, endpoint_name=None):
"""Delete an Amazon SageMaker endpoint.

If an endpoint name is not specified, this defaults to looking for an
endpoint that shares a name with the best training job for deletion.

Args:
endpoint_name (str): Name of the endpoint to delete
"""
endpoint_name = endpoint_name or self.best_training_job()
self.sagemaker_session.delete_endpoint(endpoint_name)

def _ensure_last_tuning_job(self):
"""Placeholder docstring"""
if self.latest_tuning_job is None:
Expand Down
4 changes: 2 additions & 2 deletions tests/integ/test_local_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_mxnet_local_mode(sagemaker_local_session, mxnet_full_version, mxnet_ful
data = numpy.zeros(shape=(1, 1, 28, 28))
predictor.predict(data)
finally:
mx.delete_endpoint()
predictor.delete_endpoint()


@pytest.mark.local_mode
Expand Down Expand Up @@ -209,7 +209,7 @@ def test_mxnet_local_data_local_script(mxnet_full_version, mxnet_full_py_version
data = numpy.zeros(shape=(1, 1, 28, 28))
predictor.predict(data)
finally:
mx.delete_endpoint()
predictor.delete_endpoint()


@pytest.mark.local_mode
Expand Down
2 changes: 1 addition & 1 deletion tests/integ/test_source_dirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ def test_source_dirs(tmpdir, sagemaker_local_session):
predict_response = predictor.predict([7])
assert predict_response == [49]
finally:
estimator.delete_endpoint()
predictor.delete_endpoint()
36 changes: 0 additions & 36 deletions tests/unit/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,42 +636,6 @@ def test_start_new_wait_called(strftime, sagemaker_session):
assert sagemaker_session.wait_for_job.assert_called_once


def test_delete_endpoint(sagemaker_session):
t = DummyFramework(
entry_point=SCRIPT_PATH,
role="DummyRole",
sagemaker_session=sagemaker_session,
train_instance_count=INSTANCE_COUNT,
train_instance_type=INSTANCE_TYPE,
container_log_level=logging.INFO,
)

class tj(object):
@property
def name(self):
return "myjob"

t.latest_training_job = tj()

t.delete_endpoint()

sagemaker_session.delete_endpoint.assert_called_with("myjob")


def test_delete_endpoint_without_endpoint(sagemaker_session):
t = DummyFramework(
entry_point=SCRIPT_PATH,
role="DummyRole",
sagemaker_session=sagemaker_session,
train_instance_count=INSTANCE_COUNT,
train_instance_type=INSTANCE_TYPE,
)

with pytest.raises(ValueError) as error:
t.delete_endpoint()
assert "Endpoint was not created yet" in str(error)


def test_enable_cloudwatch_metrics(sagemaker_session):
fw = DummyFramework(
entry_point=SCRIPT_PATH,
Expand Down
12 changes: 0 additions & 12 deletions tests/unit/test_tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,18 +917,6 @@ def test_wait(tuner):
tuner.estimator.sagemaker_session.wait_for_tuning_job.assert_called_once_with(JOB_NAME)


def test_delete_endpoint(tuner):
tuner.latest_tuning_job = _TuningJob(tuner.estimator.sagemaker_session, JOB_NAME)

tuning_job_description = {"BestTrainingJob": {"TrainingJobName": JOB_NAME}}
tuner.estimator.sagemaker_session.sagemaker_client.describe_hyper_parameter_tuning_job = Mock(
name="describe_hyper_parameter_tuning_job", return_value=tuning_job_description
)

tuner.delete_endpoint()
tuner.sagemaker_session.delete_endpoint.assert_called_with(JOB_NAME)


def test_fit_no_inputs(tuner, sagemaker_session):
script_path = os.path.join(DATA_DIR, "mxnet_mnist", "failure_script.py")
tuner.estimator = MXNet(
Expand Down