Skip to content

Commit 8a28ab4

Browse files
author
wanyixia
committed
change: revise integration test for compilation
1 parent f1fa18e commit 8a28ab4

File tree

3 files changed

+108
-53
lines changed

3 files changed

+108
-53
lines changed

tests/conftest.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,31 @@ def neo_pytorch_cpu_instance_type():
223223
return "ml.c5.xlarge"
224224

225225

226+
@pytest.fixture(scope="module")
227+
def tfs_eia_latest_py_version():
228+
return "py3"
229+
230+
231+
@pytest.fixture(scope="module")
232+
def tfs_eia_latest_version():
233+
return "2.3"
234+
235+
236+
@pytest.fixture(scope="module")
237+
def tfs_eia_target_device():
238+
return "ml_eia2"
239+
240+
241+
@pytest.fixture(scope="module")
242+
def tfs_eia_cpu_instance_type():
243+
return "ml.c5.xlarge"
244+
245+
246+
@pytest.fixture(scope="module")
247+
def tfs_eia_compilation_job_name():
248+
return utils.name_from_base("tfs-eia-compilation")
249+
250+
226251
@pytest.fixture(scope="module")
227252
def xgboost_framework_version(xgboost_version):
228253
if xgboost_version in ("1", "latest"):

tests/integ/test_tfs.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -138,42 +138,6 @@ def tfs_predictor_with_accelerator(
138138
yield predictor
139139

140140

141-
@pytest.fixture(scope="module")
142-
def tfs_trt_predictor_with_accelerator(
143-
sagemaker_session, tensorflow_eia_latest_version, cpu_instance_type
144-
):
145-
endpoint_name = sagemaker.utils.unique_name_from_base("sagemaker-tensorflow-serving")
146-
model_data = sagemaker_session.upload_data(
147-
path=os.path.join(tests.integ.DATA_DIR, "tensorflow-serving-test-model.tar.gz"),
148-
key_prefix="tensorflow-serving/compiledmodels",
149-
)
150-
bucket = sagemaker_session.default_bucket()
151-
with tests.integ.timeout.timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
152-
model = TensorFlowModel(
153-
model_data=model_data,
154-
role="SageMakerRole",
155-
framework_version=tensorflow_eia_latest_version,
156-
sagemaker_session=sagemaker_session,
157-
name=endpoint_name,
158-
)
159-
data_shape = {"input": [1, 224, 224, 3]}
160-
tfs_eia_compilation_job_name = "tfs_eia_compilation_job_name"
161-
compiled_model_path = "s3://{}/{}/output".format(bucket, tfs_eia_compilation_job_name)
162-
compiled_model = model.compile(
163-
target_instance_family='ml_eia2',
164-
input_shape=data_shape,
165-
output_path=compiled_model_path,
166-
role="SageMakerRole",
167-
job_name=tfs_eia_compilation_job_name,
168-
framework='tensorflow',
169-
framework_version='2.3'
170-
)
171-
predictor = compiled_model.deploy(
172-
1, cpu_instance_type, endpoint_name=endpoint_name, accelerator_type="ml.eia2.large"
173-
)
174-
yield predictor
175-
176-
177141
@pytest.mark.release
178142
def test_predict(tfs_predictor):
179143
input_data = {"instances": [1.0, 2.0, 5.0]}
@@ -196,23 +160,6 @@ def test_predict_with_accelerator(tfs_predictor_with_accelerator):
196160
assert expected_result == result
197161

198162

199-
@pytest.mark.skipif(
200-
tests.integ.test_region() not in tests.integ.EI_SUPPORTED_REGIONS,
201-
reason="EI is not supported in region {}".format(tests.integ.test_region()),
202-
)
203-
@pytest.mark.release
204-
def test_trt_predict_with_accelerator(tfs_predictor_with_accelerator):
205-
import numpy as np
206-
import matplotlib.image as mpimg
207-
path = os.path.join(tests.integ.DATA_DIR, "cuteCat.jpg")
208-
img = mpimg.imread(path)
209-
img = np.resize(img, (299, 299, 3))
210-
img = np.expand_dims(img, axis=0)
211-
input_data = {"inputs": img}
212-
result = tfs_trt_predictor_with_accelerator.predict(input_data)
213-
print("trt predictor result is: " + result)
214-
215-
216163
@pytest.mark.local_mode
217164
def test_predict_with_entry_point(tfs_predictor_with_model_and_entry_point_same_tar):
218165
input_data = {"instances": [1.0, 2.0, 5.0]}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright 2017-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
from __future__ import absolute_import
14+
15+
import tarfile
16+
17+
import botocore.exceptions
18+
import os
19+
20+
import pytest
21+
import sagemaker
22+
import sagemaker.predictor
23+
import sagemaker.utils
24+
import tests.integ
25+
import tests.integ.timeout
26+
import numpy as np
27+
import matplotlib.image as mpimg
28+
from sagemaker.deserializers import JSONDeserializer
29+
from sagemaker.tensorflow.model import TensorFlowModel, TensorFlowPredictor
30+
from sagemaker.serializers import CSVSerializer, IdentitySerializer
31+
from tests.integ import (
32+
DATA_DIR,
33+
)
34+
from tests.integ.timeout import timeout_and_delete_endpoint_by_name
35+
36+
INPUT_MODEL = os.path.join(DATA_DIR, "tensorflow-serving-test-model.tar.gz")
37+
INFERENCE_IMAGE = os.path.join(DATA_DIR, "cuteCat.jpg")
38+
39+
40+
def test_compile_and_deploy_with_accelerator(
41+
sagemaker_session,
42+
tfs_eia_cpu_instance_type,
43+
tfs_eia_latest_version,
44+
tfs_eia_latest_py_version,
45+
tfs_eia_target_device,
46+
tfs_eia_compilation_job_name
47+
):
48+
endpoint_name = sagemaker.utils.unique_name_from_base("sagemaker-tensorflow-serving")
49+
model_data = sagemaker_session.upload_data(
50+
path=os.path.join(tests.integ.DATA_DIR, "tensorflow-serving-test-model.tar.gz"),
51+
key_prefix="tensorflow-serving/compiledmodels",
52+
)
53+
bucket = sagemaker_session.default_bucket()
54+
with tests.integ.timeout.timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
55+
model = TensorFlowModel(
56+
model_data=model_data,
57+
role="SageMakerRole",
58+
framework_version=tfs_eia_latest_version,
59+
py_version=tfs_eia_latest_py_version
60+
sagemaker_session=sagemaker_session,
61+
name=endpoint_name,
62+
)
63+
data_shape = {"input": [1, 224, 224, 3]}
64+
compiled_model_path = "s3://{}/{}/output".format(bucket, tfs_eia_compilation_job_name)
65+
compiled_model = model.compile(
66+
target_instance_family=tfs_eia_target_device,
67+
input_shape=data_shape,
68+
output_path=compiled_model_path,
69+
role="SageMakerRole",
70+
job_name=tfs_eia_compilation_job_name,
71+
framework='tensorflow',
72+
framework_version=tfs_eia_latest_version
73+
)
74+
predictor = compiled_model.deploy(
75+
1, tfs_eia_cpu_instance_type, endpoint_name=endpoint_name, accelerator_type="ml.eia2.large"
76+
)
77+
78+
image_path = os.path.join(tests.integ.DATA_DIR, "cuteCat.jpg")
79+
img = mpimg.imread(image_path)
80+
img = np.resize(img, (224, 224, 3))
81+
img = np.expand_dims(img, axis=0)
82+
input_data = {"inputs": img}
83+
result = predictor.predict(input_data)

0 commit comments

Comments
 (0)