24
24
from sagemaker .serve .spec .inference_spec import InferenceSpec
25
25
from torchvision .transforms import transforms
26
26
from torchvision .models .squeezenet import squeezenet1_1
27
-
27
+ import tests . integ
28
28
from tests .integ .sagemaker .serve .constants import (
29
29
PYTORCH_SQUEEZENET_RESOURCE_DIR ,
30
30
SERVE_SAGEMAKER_ENDPOINT_TIMEOUT ,
31
31
PYTHON_VERSION_IS_NOT_310 ,
32
32
)
33
33
from tests .integ .timeout import timeout
34
- from tests .integ .utils import cleanup_model_resources
34
+ from tests .integ .utils import cleanup_model_resources , gpu_list , retry_with_instance_list
35
35
import logging
36
36
37
37
logger = logging .getLogger (__name__ )
@@ -140,6 +140,8 @@ def model_builder_inference_spec_schema_builder(squeezenet_inference_spec, squee
140
140
model_path = PYTORCH_SQUEEZENET_RESOURCE_DIR ,
141
141
inference_spec = squeezenet_inference_spec ,
142
142
schema_builder = squeezenet_schema ,
143
+ image_uri = "763104351884.dkr.ecr.us-west-2.amazonaws.com/pytorch-inference:2.0.0-cpu-py310" ,
144
+ instance_type = "ml.c6i.xlarge"
143
145
)
144
146
145
147
@@ -148,69 +150,39 @@ def model_builder(request):
148
150
return request .getfixturevalue (request .param )
149
151
150
152
151
- # @pytest.mark.skipif(
152
- # PYTHON_VERSION_IS_NOT_310,
153
- # reason="The goal of these test are to test the serving components of our feature",
154
- # )
155
- # @pytest.mark.parametrize(
156
- # "model_builder", ["model_builder_inference_spec_schema_builder"], indirect=True
157
- # )
158
- # @pytest.mark.slow_test
159
- # @pytest.mark.flaky(reruns=5, reruns_delay=2)
160
- # def test_happy_pytorch_local_container(sagemaker_session, model_builder, test_image):
161
- # logger.info("Running in LOCAL_CONTAINER mode...")
162
- # caught_ex = None
163
- #
164
- # model = model_builder.build(mode=Mode.LOCAL_CONTAINER, sagemaker_session=sagemaker_session)
165
- #
166
- # with timeout(minutes=SERVE_LOCAL_CONTAINER_TIMEOUT):
167
- # try:
168
- # logger.info("Deploying and predicting in LOCAL_CONTAINER mode...")
169
- # predictor = model.deploy()
170
- # logger.info("Local container successfully deployed.")
171
- # predictor.predict(test_image)
172
- # except Exception as e:
173
- # logger.exception("test failed")
174
- # caught_ex = e
175
- # finally:
176
- # if model.modes[str(Mode.LOCAL_CONTAINER)].container:
177
- # model.modes[str(Mode.LOCAL_CONTAINER)].container.kill()
178
- # if caught_ex:
179
- # assert (
180
- # False
181
- # ), f"{caught_ex} was thrown when running pytorch squeezenet local container test"
182
-
183
-
184
153
@pytest .mark .skipif (
185
- PYTHON_VERSION_IS_NOT_310 , # or NOT_RUNNING_ON_INF_EXP_DEV_PIPELINE,
186
- reason = "The goal of these test are to test the serving components of our feature" ,
154
+ PYTHON_VERSION_IS_NOT_310 ,
155
+ tests .integ .test_region () in tests .integ .TRAINING_NO_P2_REGIONS
156
+ and tests .integ .test_region () in tests .integ .TRAINING_NO_P3_REGIONS ,
157
+ reason = "no ml.p2 or ml.p3 instances in this region"
187
158
)
159
+ @retry_with_instance_list (gpu_list (tests .integ .test_region ()))
188
160
@pytest .mark .parametrize (
189
161
"model_builder" , ["model_builder_inference_spec_schema_builder" ], indirect = True
190
162
)
191
163
@pytest .mark .slow_test
192
164
def test_happy_pytorch_sagemaker_endpoint (
193
165
sagemaker_session ,
194
166
model_builder ,
195
- cpu_instance_type ,
196
167
test_image ,
168
+ ** kwargs
197
169
):
198
170
logger .info ("Running in SAGEMAKER_ENDPOINT mode..." )
199
171
caught_ex = None
200
-
201
- # iam_client = sagemaker_session.boto_session.client("iam")
202
- # role_arn = iam_client.get_role(RoleName=ROLE_NAME)["Role"]["Arn"]
203
-
204
- model = model_builder .build (mode = Mode .LOCAL_CONTAINER , sagemaker_session = sagemaker_session )
205
-
172
+ iam_client = sagemaker_session .boto_session .client ("iam" )
173
+ role_arn = iam_client .get_role (RoleName = ROLE_NAME )["Role" ]["Arn" ]
174
+ model = model_builder .build (role_arn = role_arn , sagemaker_session = sagemaker_session )
206
175
with timeout (minutes = SERVE_SAGEMAKER_ENDPOINT_TIMEOUT ):
207
176
try :
208
177
logger .info ("Deploying and predicting in SAGEMAKER_ENDPOINT mode..." )
209
- predictor = model .deploy ()
178
+ predictor = model .deploy (
179
+ mode = Mode .SAGEMAKER_ENDPOINT ,
180
+ instance_type = "ml.c6i.xlarge" ,
181
+ initial_instance_count = 1 ,
182
+ )
210
183
logger .info ("Endpoint successfully deployed." )
211
184
predictor .predict (test_image )
212
185
except Exception as e :
213
- logger .exception ("test failed" )
214
186
caught_ex = e
215
187
finally :
216
188
cleanup_model_resources (
@@ -223,89 +195,3 @@ def test_happy_pytorch_sagemaker_endpoint(
223
195
assert (
224
196
False
225
197
), f"{ caught_ex } was thrown when running pytorch squeezenet sagemaker endpoint test"
226
-
227
-
228
- # @pytest.mark.skipif(
229
- # PYTHON_VERSION_IS_NOT_310,
230
- # reason="The goal of these test are to test the serving components of our feature",
231
- # )
232
- # @pytest.mark.parametrize(
233
- # "model_builder", ["model_builder_inference_spec_schema_builder"], indirect=True
234
- # )
235
- # @pytest.mark.slow_test
236
- # def test_happy_pytorch_local_container_overwrite_to_sagemaker_endpoint(
237
- # sagemaker_session, model_builder, cpu_instance_type, test_image
238
- # ):
239
- # logger.info("Building model in LOCAL_CONTAINER mode...")
240
- # caught_ex = None
241
- #
242
- # iam_client = sagemaker_session.boto_session.client("iam")
243
- # role_arn = iam_client.get_role(RoleName=ROLE_NAME)["Role"]["Arn"]
244
- # logger.debug("Role arn: %s", role_arn)
245
- #
246
- # model = model_builder.build(
247
- # mode=Mode.LOCAL_CONTAINER, role_arn=role_arn, sagemaker_session=sagemaker_session
248
- # )
249
- #
250
- # with timeout(minutes=SERVE_SAGEMAKER_ENDPOINT_TIMEOUT):
251
- # try:
252
- # logger.info("Deploying and predicting in SAGEMAKER_ENDPOINT mode...")
253
- # predictor = model.deploy(
254
- # instance_type=cpu_instance_type,
255
- # initial_instance_count=1,
256
- # mode=Mode.SAGEMAKER_ENDPOINT,
257
- # )
258
- # logger.info("Endpoint successfully deployed.")
259
- # predictor.predict(test_image)
260
- # except Exception as e:
261
- # caught_ex = e
262
- # finally:
263
- # cleanup_model_resources(
264
- # sagemaker_session=model_builder.sagemaker_session,
265
- # model_name=model.name,
266
- # endpoint_name=model.endpoint_name,
267
- # )
268
- # if caught_ex:
269
- # logger.exception(caught_ex)
270
- # assert (
271
- # False
272
- # ), f"{caught_ex} was thrown when running pytorch squeezenet sagemaker endpoint test"
273
-
274
-
275
- # @pytest.mark.skipif(
276
- # PYTHON_VERSION_IS_NOT_310,
277
- # reason="The goal of these test are to test the serving components of our feature",
278
- # )
279
- # @pytest.mark.parametrize(
280
- # "model_builder", ["model_builder_inference_spec_schema_builder"], indirect=True
281
- # )
282
- # @pytest.mark.slow_test
283
- # def test_happy_pytorch_sagemaker_endpoint_overwrite_to_local_container(
284
- # sagemaker_session, model_builder, test_image
285
- # ):
286
- # logger.info("Building model in SAGEMAKER_ENDPOINT mode...")
287
- # caught_ex = None
288
- #
289
- # iam_client = sagemaker_session.boto_session.client("iam")
290
- # role_arn = iam_client.get_role(RoleName=ROLE_NAME)["Role"]["Arn"]
291
- #
292
- # model = model_builder.build(
293
- # mode=Mode.SAGEMAKER_ENDPOINT, role_arn=role_arn, sagemaker_session=sagemaker_session
294
- # )
295
- #
296
- # with timeout(minutes=SERVE_LOCAL_CONTAINER_TIMEOUT):
297
- # try:
298
- # logger.info("Deploying and predicting in LOCAL_CONTAINER mode...")
299
- # predictor = model.deploy(mode=Mode.LOCAL_CONTAINER)
300
- # logger.info("Local container successfully deployed.")
301
- # predictor.predict(test_image)
302
- # except Exception as e:
303
- # logger.exception("test failed")
304
- # caught_ex = e
305
- # finally:
306
- # if model.modes[str(Mode.LOCAL_CONTAINER)].container:
307
- # model.modes[str(Mode.LOCAL_CONTAINER)].container.kill()
308
- # if caught_ex:
309
- # assert (
310
- # False
311
- # ), f"{caught_ex} was thrown when running pytorch squeezenet local container test"
0 commit comments