-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserve
More file actions
executable file
·42 lines (33 loc) · 1.81 KB
/
serve
File metadata and controls
executable file
·42 lines (33 loc) · 1.81 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
#!/usr/bin/env python
# Copyright 2017-2018 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://aws.amazon.com/apache2.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.
# This file implements the hosting solution, which just starts TensorFlow Model Serving.
import subprocess
def start_server():
print('Starting TensorFlow Serving.')
# link the log streams to stdout/err so they will be logged to the container logs
subprocess.check_call(['ln', '-sf', '/dev/stdout', '/var/log/nginx/access.log'])
subprocess.check_call(['ln', '-sf', '/dev/stderr', '/var/log/nginx/error.log'])
# start nginx server
nginx = subprocess.Popen(['nginx', '-c', '/opt/ml/code/nginx.conf'])
# start TensorFlow Serving
# https://www.tensorflow.org/serving/api_rest#start_modelserver_with_the_rest_api_endpoint
# SageMaker copies our model artifact from our Training Job into the /opt/ml/model.
# https://docs.aws.amazon.com/sagemaker/latest/dg/your-algorithms-inference-code.html#your-algorithms-inference-code-load-artifacts
tf_model_server = subprocess.call(['tensorflow_model_server',
'--rest_api_port=8501',
'--model_name=deepctr_model',
'--model_base_path=/opt/ml/model/export/Servo'])
# The main routine just invokes the start function.
if __name__ == '__main__':
start_server()