@@ -95,24 +95,23 @@ def __init__(self):
95
95
raise ValueError ("not enough ports available in SAGEMAKER_SAFE_PORT_RANGE ({})"
96
96
.format (self ._sagemaker_port_range ))
97
97
# select non-overlapping grpc and rest ports based on tfs instance count
98
- # record the init and end value in order to reconstruct them in python service
99
- self ._tfs_grpc_port_range = "{}-{}" .format (low ,
100
- low + self ._tfs_instance_count )
101
- self ._tfs_rest_port_range = "{}-{}" .format (low + self ._tfs_instance_count ,
102
- low + 2 * self ._tfs_instance_count )
103
98
for i in range (self ._tfs_instance_count ):
104
- self ._tfs_grpc_port .append (str (low + i ))
105
- self ._tfs_rest_port .append (str (low + self ._tfs_instance_count + i ))
99
+ self ._tfs_grpc_port .append (str (low + 2 * i ))
100
+ self ._tfs_rest_port .append (str (low + 2 * i + 1 ))
101
+ # concat selected ports respectively in order to pass them to python service
102
+ self ._tfs_grpc_concat_port = self ._concat_port (self ._tfs_grpc_port )
103
+ self ._tfs_rest_concat_port = self ._concat_port (self ._tfs_rest_port )
106
104
else :
107
105
# just use the standard default ports
108
106
self ._tfs_grpc_port = ["9000" ]
109
107
self ._tfs_rest_port = ["8501" ]
110
- self ._tfs_grpc_port_range = "9000-9000"
111
- self ._tfs_rest_port_range = "8501-8501"
108
+ # provide single concat port here for default case
109
+ self ._tfs_grpc_concat_port = "9000"
110
+ self ._tfs_rest_concat_port = "8501"
112
111
113
112
# set environment variable for python service
114
- os .environ ["TFS_GRPC_PORT_RANGE " ] = self ._tfs_grpc_port_range
115
- os .environ ["TFS_REST_PORT_RANGE " ] = self ._tfs_rest_port_range
113
+ os .environ ["TFS_GRPC_PORT " ] = self ._tfs_grpc_concat_port
114
+ os .environ ["TFS_REST_PORT " ] = self ._tfs_rest_concat_port
116
115
117
116
def _need_python_service (self ):
118
117
if os .path .exists (INFERENCE_PATH ):
@@ -121,6 +120,11 @@ def _need_python_service(self):
121
120
and os .environ .get ("SAGEMAKER_MULTI_MODEL_UNIVERSAL_PREFIX" ):
122
121
self ._enable_python_service = True
123
122
123
+ def _concat_port (self , ports ):
124
+ str_ports = [str (port ) for port in ports ]
125
+ concat_str_ports = "," .join (str_ports )
126
+ return concat_str_ports
127
+
124
128
def _create_tfs_config (self ):
125
129
models = tfs_utils .find_models ()
126
130
@@ -194,13 +198,13 @@ def _setup_gunicorn(self):
194
198
gunicorn_command = (
195
199
"gunicorn -b unix:/tmp/gunicorn.sock -k {} --chdir /sagemaker "
196
200
"--workers {} --threads {} "
197
- "{}{} -e TFS_GRPC_PORT_RANGE ={} -e TFS_REST_PORT_RANGE ={} "
201
+ "{}{} -e TFS_GRPC_PORT ={} -e TFS_REST_PORT ={} "
198
202
"-e SAGEMAKER_MULTI_MODEL={} -e SAGEMAKER_SAFE_PORT_RANGE={} "
199
203
"-e SAGEMAKER_TFS_WAIT_TIME_SECONDS={} "
200
204
"python_service:app" ).format (self ._gunicorn_worker_class ,
201
205
self ._gunicorn_workers , self ._gunicorn_threads ,
202
206
python_path_option , "," .join (python_path_content ),
203
- self ._tfs_grpc_port_range , self ._tfs_rest_port_range ,
207
+ self ._tfs_grpc_concat_port , self ._tfs_rest_concat_port ,
204
208
self ._tfs_enable_multi_model_endpoint ,
205
209
self ._sagemaker_port_range ,
206
210
self ._tfs_wait_time_seconds )
0 commit comments