in tensorflow/inference/docker/build_artifacts/sagemaker/serve.py [0:0]
def _setup_gunicorn(self):
python_path_content = []
python_path_option = ""
bucket = os.environ.get("SAGEMAKER_MULTI_MODEL_UNIVERSAL_BUCKET", None)
prefix = os.environ.get("SAGEMAKER_MULTI_MODEL_UNIVERSAL_PREFIX", None)
if not os.path.exists(CODE_DIR) and bucket and prefix:
self._download_scripts(bucket, prefix)
if self._enable_python_service:
lib_path_exists = os.path.exists(PYTHON_LIB_PATH)
requirements_exists = os.path.exists(REQUIREMENTS_PATH)
python_path_content = ["/opt/ml/model/code"]
python_path_option = "--pythonpath "
if lib_path_exists:
python_path_content.append(PYTHON_LIB_PATH)
if requirements_exists:
if lib_path_exists:
log.warning(
"loading modules in '{}', ignoring requirements.txt".format(PYTHON_LIB_PATH)
)
else:
log.info("installing packages from requirements.txt...")
pip_install_cmd = "pip3 install -r {}".format(REQUIREMENTS_PATH)
try:
subprocess.check_call(pip_install_cmd.split())
except subprocess.CalledProcessError:
log.error("failed to install required packages, exiting.")
self._stop()
raise ChildProcessError("failed to install required packages.")
gunicorn_command = (
"python3 /sagemaker/python_service.py -b unix:/tmp/gunicorn.sock -k {} --chdir /sagemaker "
"--workers {} --threads {} --log-level {} --timeout {} "
).format(
self._gunicorn_worker_class,
self._gunicorn_workers,
self._gunicorn_threads,
self._gunicorn_loglevel,
self._gunicorn_timeout_seconds,
)
log.info("gunicorn command: {}".format(gunicorn_command))
self._gunicorn_command = gunicorn_command
gunicorn_env = {
"TFS_GRPC_PORTS": self._tfs_grpc_concat_ports,
"TFS_REST_PORTS": self._tfs_rest_concat_ports,
"SAGEMAKER_MULTI_MODEL": str(self._tfs_enable_multi_model_endpoint),
"SAGEMAKER_TFS_WAIT_TIME_SECONDS": str(self._tfs_wait_time_seconds),
"SAGEMAKER_TFS_INTER_OP_PARALLELISM": str(self._tfs_inter_op_parallelism),
"SAGEMAKER_TFS_INTRA_OP_PARALLELISM": str(self._tfs_intra_op_parallelism),
"SAGEMAKER_TFS_INSTANCE_COUNT": str(self._tfs_instance_count),
"PYTHONPATH": ":".join(python_path_content),
"SAGEMAKER_GUNICORN_WORKERS": str(self._gunicorn_workers),
}
if self._sagemaker_port_range is not None:
gunicorn_env["SAGEMAKER_SAFE_PORT_RANGE"] = self._sagemaker_port_range
log.info(f"gunicorn env: {gunicorn_env}")
self._gunicorn_env = gunicorn_env