-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathserver_gunicorn.py
More file actions
61 lines (56 loc) · 2.05 KB
/
server_gunicorn.py
File metadata and controls
61 lines (56 loc) · 2.05 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
50
51
52
53
54
55
56
57
58
59
60
61
#
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License 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.
"""Launcher for the prediction_executor based encoder server.
Uses the serving framework to create a request server which
performs the logic for requests in separate processes and uses a local TFserving
instance to handle the model.
"""
from collections.abc import Sequence
import os
from absl import app
from absl import logging
from serving.serving_framework import inline_prediction_executor
from serving.serving_framework import server_gunicorn
from serving.serving_framework.tensorflow import server_model_runner
from serving import predictor
def main(argv: Sequence[str]) -> None:
if len(argv) > 1:
raise app.UsageError('Too many command-line arguments.')
if 'AIP_HTTP_PORT' not in os.environ:
raise ValueError(
'The environment variable AIP_HTTP_PORT needs to be specified.'
)
http_port = int(os.environ.get('AIP_HTTP_PORT'))
options = {
'bind': f'0.0.0.0:{http_port}',
'workers': 3,
'timeout': 120,
}
health_checker = server_gunicorn.ModelServerHealthCheck(
health_check_port=int(os.environ.get('MODEL_REST_PORT')),
model_name='elixr_c',
)
predictor_instance = predictor.Predictor()
logging.info('Launching gunicorn application.')
server_gunicorn.PredictionApplication(
inline_prediction_executor.InlinePredictionExecutor(
predictor_instance.predict,
server_model_runner.ServerModelRunner
),
health_check=health_checker,
options=options,
).run()
if __name__ == '__main__':
app.run(main)