Skip to content

Commit 3ce2d95

Browse files
authored
Revert "fix issue-987 error by adding instance_type in endpoint_name (#1058)" (#1070)
1 parent a907597 commit 3ce2d95

File tree

5 files changed

+26
-36
lines changed

5 files changed

+26
-36
lines changed

src/sagemaker/model.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,13 @@ def deploy(
446446
if endpoint_name:
447447
self.endpoint_name = endpoint_name
448448
else:
449-
self.endpoint_name = self.name + "-" + instance_type.replace(".", "-")
449+
self.endpoint_name = self.name
450450
if self._is_compiled_model and not self.endpoint_name.endswith(compiled_model_suffix):
451451
self.endpoint_name += compiled_model_suffix
452452

453453
if update_endpoint:
454-
self.sagemaker_session.delete_endpoint_config(endpoint_config_name=self.endpoint_name)
455454
endpoint_config_name = self.sagemaker_session.create_endpoint_config(
456-
name=self.endpoint_name,
455+
name=self.name,
457456
model_name=self.name,
458457
initial_instance_count=initial_instance_count,
459458
instance_type=instance_type,

src/sagemaker/session.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,47 +1297,39 @@ def endpoint_from_model_data(
12971297
"""
12981298

12991299
model_environment_vars = model_environment_vars or {}
1300-
model_name = name or name_from_image(deployment_image)
1301-
endpoint_name = name or (
1302-
name_from_image(deployment_image) + "-" + instance_type.replace(".", "-")
1303-
)
1300+
name = name or name_from_image(deployment_image)
13041301
model_vpc_config = vpc_utils.sanitize(model_vpc_config)
13051302

13061303
if _deployment_entity_exists(
1307-
lambda: self.sagemaker_client.describe_endpoint(EndpointName=endpoint_name)
1304+
lambda: self.sagemaker_client.describe_endpoint(EndpointName=name)
13081305
):
13091306
raise ValueError(
1310-
'Endpoint with name "{}" already exists; please pick a different name.'.format(
1311-
endpoint_name
1312-
)
1307+
'Endpoint with name "{}" already exists; please pick a different name.'.format(name)
13131308
)
13141309

13151310
if not _deployment_entity_exists(
1316-
lambda: self.sagemaker_client.describe_model(ModelName=model_name)
1311+
lambda: self.sagemaker_client.describe_model(ModelName=name)
13171312
):
13181313
primary_container = container_def(
13191314
image=deployment_image, model_data_url=model_s3_location, env=model_environment_vars
13201315
)
13211316
self.create_model(
1322-
name=model_name,
1323-
role=role,
1324-
container_defs=primary_container,
1325-
vpc_config=model_vpc_config,
1317+
name=name, role=role, container_defs=primary_container, vpc_config=model_vpc_config
13261318
)
13271319

13281320
if not _deployment_entity_exists(
1329-
lambda: self.sagemaker_client.describe_endpoint_config(EndpointConfigName=endpoint_name)
1321+
lambda: self.sagemaker_client.describe_endpoint_config(EndpointConfigName=name)
13301322
):
13311323
self.create_endpoint_config(
1332-
name=endpoint_name,
1333-
model_name=model_name,
1324+
name=name,
1325+
model_name=name,
13341326
initial_instance_count=initial_instance_count,
13351327
instance_type=instance_type,
13361328
accelerator_type=accelerator_type,
13371329
)
13381330

1339-
self.create_endpoint(endpoint_name=endpoint_name, config_name=endpoint_name, wait=wait)
1340-
return endpoint_name
1331+
self.create_endpoint(endpoint_name=name, config_name=name, wait=wait)
1332+
return name
13411333

13421334
def endpoint_from_production_variants(
13431335
self, name, production_variants, tags=None, kms_key=None, wait=True

tests/integ/test_mxnet_train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def test_deploy_model_with_update_endpoint(
196196
EndpointConfigName=new_config_name
197197
)
198198

199-
assert old_config_name == new_config_name
199+
assert old_config_name != new_config_name
200200
assert new_config["ProductionVariants"][0]["InstanceType"] == cpu_instance_type
201201
assert new_config["ProductionVariants"][0]["InitialInstanceCount"] == 1
202202

tests/unit/test_endpoint_from_model_data.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
DEPLOY_ROLE = "mydeployrole"
3131
ENV_VARS = {"PYTHONUNBUFFERED": "TRUE", "some": "nonsense"}
3232
NAME_FROM_IMAGE = "namefromimage"
33-
DEFAULT_ENDPOINT_NAME = "namefromimage-ml-c4-xlarge"
3433
REGION = "us-west-2"
3534

3635

@@ -65,28 +64,28 @@ def test_all_defaults_no_existing_entities(name_from_image_mock, sagemaker_sessi
6564
)
6665

6766
sagemaker_session.sagemaker_client.describe_endpoint.assert_called_once_with(
68-
EndpointName=DEFAULT_ENDPOINT_NAME
67+
EndpointName=NAME_FROM_IMAGE
6968
)
7069
sagemaker_session.sagemaker_client.describe_model.assert_called_once_with(
7170
ModelName=NAME_FROM_IMAGE
7271
)
7372
sagemaker_session.sagemaker_client.describe_endpoint_config.assert_called_once_with(
74-
EndpointConfigName=DEFAULT_ENDPOINT_NAME
73+
EndpointConfigName=NAME_FROM_IMAGE
7574
)
7675
sagemaker_session.create_model.assert_called_once_with(
7776
name=NAME_FROM_IMAGE, role=DEPLOY_ROLE, container_defs=CONTAINER_DEF, vpc_config=None
7877
)
7978
sagemaker_session.create_endpoint_config.assert_called_once_with(
80-
name=DEFAULT_ENDPOINT_NAME,
79+
name=NAME_FROM_IMAGE,
8180
model_name=NAME_FROM_IMAGE,
8281
initial_instance_count=INITIAL_INSTANCE_COUNT,
8382
instance_type=INSTANCE_TYPE,
8483
accelerator_type=None,
8584
)
8685
sagemaker_session.create_endpoint.assert_called_once_with(
87-
endpoint_name=DEFAULT_ENDPOINT_NAME, config_name=DEFAULT_ENDPOINT_NAME, wait=False
86+
endpoint_name=NAME_FROM_IMAGE, config_name=NAME_FROM_IMAGE, wait=False
8887
)
89-
assert returned_name == DEFAULT_ENDPOINT_NAME
88+
assert returned_name == NAME_FROM_IMAGE
9089

9190

9291
@patch("sagemaker.session.name_from_image", return_value=NAME_FROM_IMAGE)
@@ -153,7 +152,7 @@ def test_model_and_endpoint_config_exist(name_from_image_mock, sagemaker_session
153152
sagemaker_session.create_model.assert_not_called()
154153
sagemaker_session.create_endpoint_config.assert_not_called()
155154
sagemaker_session.create_endpoint.assert_called_once_with(
156-
endpoint_name=DEFAULT_ENDPOINT_NAME, config_name=DEFAULT_ENDPOINT_NAME, wait=False
155+
endpoint_name=NAME_FROM_IMAGE, config_name=NAME_FROM_IMAGE, wait=False
157156
)
158157

159158

tests/unit/test_model.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
MODEL_DATA = "s3://bucket/model.tar.gz"
2727
MODEL_IMAGE = "mi"
2828
ENTRY_POINT = "blah.py"
29+
INSTANCE_TYPE = "p2.xlarge"
2930
ROLE = "some-role"
3031

3132
DATA_DIR = os.path.join(os.path.dirname(__file__), "..", "data")
@@ -39,7 +40,6 @@
3940
IMAGE_NAME = "fakeimage"
4041
REGION = "us-west-2"
4142
MODEL_NAME = "{}-{}".format(MODEL_IMAGE, TIMESTAMP)
42-
ENDPOINT_NAME = "{}-{}".format(MODEL_NAME, INSTANCE_TYPE.replace(".", "-"))
4343
GIT_REPO = "https://github.com/aws/sagemaker-python-sdk.git"
4444
BRANCH = "test-branch-git-config"
4545
COMMIT = "ae15c9d7d5b97ea95ea451e4662ee43da3401d73"
@@ -210,7 +210,7 @@ def test_deploy(sagemaker_session, tmpdir):
210210
model = DummyFrameworkModel(sagemaker_session, source_dir=str(tmpdir))
211211
model.deploy(instance_type=INSTANCE_TYPE, initial_instance_count=1)
212212
sagemaker_session.endpoint_from_production_variants.assert_called_with(
213-
ENDPOINT_NAME,
213+
MODEL_NAME,
214214
[
215215
{
216216
"InitialVariantWeight": 1,
@@ -255,7 +255,7 @@ def test_deploy_tags(sagemaker_session, tmpdir):
255255
tags = [{"ModelName": "TestModel"}]
256256
model.deploy(instance_type=INSTANCE_TYPE, initial_instance_count=1, tags=tags)
257257
sagemaker_session.endpoint_from_production_variants.assert_called_with(
258-
ENDPOINT_NAME,
258+
MODEL_NAME,
259259
[
260260
{
261261
"InitialVariantWeight": 1,
@@ -280,7 +280,7 @@ def test_deploy_accelerator_type(tfo, time, sagemaker_session):
280280
instance_type=INSTANCE_TYPE, initial_instance_count=1, accelerator_type=ACCELERATOR_TYPE
281281
)
282282
sagemaker_session.endpoint_from_production_variants.assert_called_with(
283-
ENDPOINT_NAME,
283+
MODEL_NAME,
284284
[
285285
{
286286
"InitialVariantWeight": 1,
@@ -305,7 +305,7 @@ def test_deploy_kms_key(tfo, time, sagemaker_session):
305305
model = DummyFrameworkModel(sagemaker_session)
306306
model.deploy(instance_type=INSTANCE_TYPE, initial_instance_count=1, kms_key=key)
307307
sagemaker_session.endpoint_from_production_variants.assert_called_with(
308-
ENDPOINT_NAME,
308+
MODEL_NAME,
309309
[
310310
{
311311
"InitialVariantWeight": 1,
@@ -350,7 +350,7 @@ def test_deploy_update_endpoint(sagemaker_session, tmpdir):
350350
accelerator_type=ACCELERATOR_TYPE,
351351
)
352352
sagemaker_session.create_endpoint_config.assert_called_with(
353-
name=endpoint_name,
353+
name=model.name,
354354
model_name=model.name,
355355
initial_instance_count=INSTANCE_COUNT,
356356
instance_type=INSTANCE_TYPE,
@@ -359,7 +359,7 @@ def test_deploy_update_endpoint(sagemaker_session, tmpdir):
359359
kms_key=None,
360360
)
361361
config_name = sagemaker_session.create_endpoint_config(
362-
name=endpoint_name,
362+
name=model.name,
363363
model_name=model.name,
364364
initial_instance_count=INSTANCE_COUNT,
365365
instance_type=INSTANCE_TYPE,

0 commit comments

Comments
 (0)