-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtest_hosting.py
More file actions
49 lines (41 loc) · 1.84 KB
/
Copy pathtest_hosting.py
File metadata and controls
49 lines (41 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright 2019-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
from __future__ import absolute_import
import os
from sagemaker.mxnet.model import MXNetModel
from sagemaker.predictor import StringDeserializer
from integration import RESOURCE_PATH
from utils import local_mode_utils
HOSTING_RESOURCE_PATH = os.path.join(RESOURCE_PATH, 'dummy_hosting')
MODEL_PATH = os.path.join(HOSTING_RESOURCE_PATH, 'model')
SCRIPT_PATH = os.path.join(HOSTING_RESOURCE_PATH, 'code', 'dummy_hosting_module.py')
# The image should use the model_fn and transform_fn defined
# in the user-provided script when serving.
def test_hosting(image_uri, sagemaker_local_session, local_instance_type):
model = MXNetModel('file://{}'.format(MODEL_PATH),
'SageMakerRole',
SCRIPT_PATH,
image=image_uri,
sagemaker_session=sagemaker_local_session)
with local_mode_utils.lock():
try:
predictor = model.deploy(1, local_instance_type)
predictor.serializer = None
predictor.deserializer = StringDeserializer()
predictor.accept = None
predictor.content_type = None
input = 'some data'
output = predictor.predict(input)
assert input == output
finally:
predictor.delete_endpoint()