Skip to content

Commit fc1f72a

Browse files
author
Deng
committed
add compile model warning and integ test
1 parent 18fb650 commit fc1f72a

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

src/sagemaker/model.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@ def deploy(
464464
if self.role is None:
465465
raise ValueError("Role can not be null for deploying a model")
466466

467+
if instance_type.startswith("ml.inf") and not self._is_compiled_model:
468+
LOGGER.warning(
469+
"Your model is not compiled, please compile your model before using Inferentia."
470+
)
471+
467472
compiled_model_suffix = "-".join(instance_type.split(".")[:-1])
468473
if self._is_compiled_model:
469474
name_prefix = self.name or utils.name_from_image(self.image)

tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ def cpu_instance_type(sagemaker_session, request):
269269
return "ml.m4.xlarge"
270270

271271

272+
@pytest.fixture(scope="session")
273+
def inf_instance_type(sagemaker_session, request):
274+
return "ml.inf1.xlarge"
275+
276+
272277
@pytest.fixture(scope="session")
273278
def ec2_instance_type(cpu_instance_type):
274279
return cpu_instance_type[3:]
@@ -289,6 +294,11 @@ def cpu_instance_family(cpu_instance_type):
289294
return "_".join(cpu_instance_type.split(".")[0:2])
290295

291296

297+
@pytest.fixture(scope="session")
298+
def inf_instance_family(inf_instance_type):
299+
return "_".join(inf_instance_type.split(".")[0:2])
300+
301+
292302
def pytest_generate_tests(metafunc):
293303
if "instance_type" in metafunc.fixturenames:
294304
boto_config = metafunc.config.getoption("--boto-config")

tests/integ/test_neo_mxnet.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from tests.integ.timeout import timeout, timeout_and_delete_endpoint_by_name
2525

2626
NEO_MXNET_VERSION = "1.4.1" # Neo doesn't support MXNet 1.6 yet.
27+
INF_MXNET_VERSION = "1.5.0"
2728

2829

2930
@pytest.fixture(scope="module")
@@ -110,3 +111,38 @@ def test_deploy_model(
110111
predictor.content_type = "application/vnd+python.numpy+binary"
111112
data = numpy.zeros(shape=(1, 1, 28, 28))
112113
predictor.predict(data)
114+
115+
116+
@pytest.mark.skip(reason="Inferentia is not supported yet.")
117+
def test_inferentia_deploy_model(
118+
mxnet_training_job, sagemaker_session, inf_instance_type, inf_instance_family
119+
):
120+
endpoint_name = unique_name_from_base("test-neo-deploy-model")
121+
122+
with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
123+
desc = sagemaker_session.sagemaker_client.describe_training_job(
124+
TrainingJobName=mxnet_training_job
125+
)
126+
model_data = desc["ModelArtifacts"]["S3ModelArtifacts"]
127+
script_path = os.path.join(DATA_DIR, "mxnet_mnist", "mnist_neo.py")
128+
role = "SageMakerRole"
129+
model = MXNetModel(
130+
model_data,
131+
role,
132+
entry_point=script_path,
133+
framework_version=NEO_MXNET_VERSION,
134+
sagemaker_session=sagemaker_session,
135+
)
136+
137+
model.compile(
138+
target_instance_family=inf_instance_family,
139+
input_shape={"data": [1, 1, 28, 28]},
140+
role=role,
141+
job_name=unique_name_from_base("test-deploy-model-compilation-job"),
142+
output_path="/".join(model_data.split("/")[:-1]),
143+
)
144+
predictor = model.deploy(1, inf_instance_type, endpoint_name=endpoint_name)
145+
146+
predictor.content_type = "application/vnd+python.numpy+binary"
147+
data = numpy.zeros(shape=(1, 1, 28, 28))
148+
predictor.predict(data)

tests/unit/test_model.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
ACCELERATOR_TYPE = "ml.eia.medium"
4040
IMAGE_NAME = "fakeimage"
4141
REGION = "us-west-2"
42+
NEO_REGION_ACCOUNT = "301217895009"
4243
MODEL_NAME = "{}-{}".format(MODEL_IMAGE, TIMESTAMP)
4344
GIT_REPO = "https://github.com/aws/sagemaker-python-sdk.git"
4445
BRANCH = "test-branch-git-config"
@@ -544,6 +545,29 @@ def test_delete_non_deployed_model(sagemaker_session):
544545
model.delete_model()
545546

546547

548+
def test_compile_model_for_inferentia(sagemaker_session, tmpdir):
549+
sagemaker_session.wait_for_compilation_job = Mock(
550+
return_value=DESCRIBE_COMPILATION_JOB_RESPONSE
551+
)
552+
model = DummyFrameworkModel(sagemaker_session, source_dir=str(tmpdir))
553+
model.compile(
554+
target_instance_family="ml_inf",
555+
input_shape={"data": [1, 3, 1024, 1024]},
556+
output_path="s3://output",
557+
role="role",
558+
framework="tensorflow",
559+
framework_version="1.15.0",
560+
job_name="compile-model",
561+
)
562+
assert (
563+
"{}.dkr.ecr.{}.amazonaws.com/sagemaker-neo-tensorflow:1.15.0-inf-py3".format(
564+
NEO_REGION_ACCOUNT, REGION
565+
)
566+
== model.image
567+
)
568+
assert model._is_compiled_model is True
569+
570+
547571
def test_compile_model_for_edge_device(sagemaker_session, tmpdir):
548572
sagemaker_session.wait_for_compilation_job = Mock(
549573
return_value=DESCRIBE_COMPILATION_JOB_RESPONSE

0 commit comments

Comments
 (0)