@@ -94,25 +94,24 @@ def __init__(self):
94
94
if low + 2 * self ._tfs_instance_count > hi :
95
95
raise ValueError ("not enough ports available in SAGEMAKER_SAFE_PORT_RANGE ({})"
96
96
.format (self ._sagemaker_port_range ))
97
- self ._tfs_grpc_port_range = "{}-{}" .format (low ,
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_selected_ports = "{}-{}" .format (low ,
98
100
low + 2 * self ._tfs_instance_count )
99
- self ._tfs_rest_port_range = "{}-{}" .format (low + 1 ,
101
+ self ._tfs_rest_selected_ports = "{}-{}" .format (low + 1 ,
100
102
low + 2 * self ._tfs_instance_count + 1 )
101
103
for i in range (self ._tfs_instance_count ):
102
104
self ._tfs_grpc_port .append (str (low + 2 * i ))
103
105
self ._tfs_rest_port .append (str (low + 2 * i + 1 ))
104
- # set environment variable for python service
105
- os .environ ["TFS_GRPC_PORT_RANGE" ] = self ._tfs_grpc_port_range
106
- os .environ ["TFS_REST_PORT_RANGE" ] = self ._tfs_rest_port_range
107
106
else :
108
107
# just use the standard default ports
109
108
self ._tfs_grpc_port = ["9000" ]
110
109
self ._tfs_rest_port = ["8501" ]
111
- self ._tfs_grpc_port_range = "9000-9000"
112
- self ._tfs_rest_port_range = "8501-8501"
113
- # 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
110
+ self ._tfs_grpc_selected_ports = "9000-9000"
111
+ self ._tfs_rest_selected_ports = "8501-8501"
112
+ # set environment variable for python service
113
+ os .environ ["TFS_GRPC_SELECTED_PORTS " ] = self ._tfs_grpc_selected_ports
114
+ os .environ ["TFS_REST_SELECTED_PORTS " ] = self ._tfs_rest_selected_ports
116
115
117
116
def _need_python_service (self ):
118
117
if os .path .exists (INFERENCE_PATH ):
@@ -194,13 +193,13 @@ def _setup_gunicorn(self):
194
193
gunicorn_command = (
195
194
"gunicorn -b unix:/tmp/gunicorn.sock -k {} --chdir /sagemaker "
196
195
"--workers {} --threads {} "
197
- "{}{} -e TFS_GRPC_PORT_RANGE ={} -e TFS_REST_PORT_RANGE ={} "
196
+ "{}{} -e TFS_GRPC_SELECTED_PORTS ={} -e TFS_REST_SELECTED_PORTS ={} "
198
197
"-e SAGEMAKER_MULTI_MODEL={} -e SAGEMAKER_SAFE_PORT_RANGE={} "
199
198
"-e SAGEMAKER_TFS_WAIT_TIME_SECONDS={} "
200
199
"python_service:app" ).format (self ._gunicorn_worker_class ,
201
200
self ._gunicorn_workers , self ._gunicorn_threads ,
202
201
python_path_option , "," .join (python_path_content ),
203
- self ._tfs_grpc_port_range , self ._tfs_rest_port_range ,
202
+ self ._tfs_grpc_selected_ports , self ._tfs_rest_selected_ports ,
204
203
self ._tfs_enable_multi_model_endpoint ,
205
204
self ._sagemaker_port_range ,
206
205
self ._tfs_wait_time_seconds )
0 commit comments