######################################################## # _____ ____ ____ ___ # | ____/ ___|___ \ |_ _|_ __ ___ __ _ __ _ ___ # | _|| | __) | | || '_ ` _ \ / _` |/ _` |/ _ \ # | |__| |___ / __/ | || | | | | | (_| | (_| | __/ # |_____\____|_____| |___|_| |_| |_|\__,_|\__, |\___| # |___/ # ____ _ # | _ \ ___ ___(_)_ __ ___ # | |_) / _ \/ __| | '_ \ / _ \ # | _ < __/ (__| | |_) | __/ # |_| \_\___|\___|_| .__/ \___| # |_| ######################################################## FROM nvidia/cuda:11.2.1-base-ubuntu20.04 AS base_image ENV DEBIAN_FRONTEND=noninteractive \ LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib" RUN apt-get update \ && apt-get upgrade -y \ && apt-get autoremove -y \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* FROM base_image AS ec2 LABEL maintainer="Amazon AI" LABEL dlc_major_version="1" ARG PYTHON=python3.9 ARG PYTHON_PIP=python3-pip ARG PIP=pip3 ARG PYTHON_VERSION=3.9.10 ARG TFS_API_VERSION=2.10.1 ARG TFS_URL=https://framework-binaries.s3.us-west-2.amazonaws.com/tensorflow_serving/r2.10_aws/gpu/2022-12-09-01-04/tensorflow_model_server # ENV variable to be pased to SageMaker stage ENV PIP=${PIP} ENV PYTHON=${PYTHON} ENV NCCL_VERSION=2.8.4-1+cuda11.2 ENV CUDNN_VERSION=8.1.0.77-1+cuda11.2 # See http://bugs.python.org/issue19846 ENV LANG=C.UTF-8 ENV PYTHONDONTWRITEBYTECODE=1 # Python won’t try to write .pyc or .pyo files on the import of source modules ENV PYTHONUNBUFFERED=1 ENV MODEL_BASE_PATH=/models # The only required piece is the model name in order to differentiate endpoints ENV MODEL_NAME=model # Fix for the interactive mode during an install in step 21 ENV DEBIAN_FRONTEND=noninteractive # allow unauthenticated and allow downgrades for special libcublas library RUN apt-get update \ && apt-get install -y --no-install-recommends --allow-unauthenticated --allow-downgrades\ ca-certificates \ cuda-command-line-tools-11-2 \ cuda-nvrtc-11-2 \ cuda-nvrtc-dev-11-2 \ cuda-cudart-dev-11-2 \ libcufft-dev-11-2 \ libcurand-dev-11-2 \ libcusolver-dev-11-2 \ libcusparse-dev-11-2 \ libbz2-dev \ liblzma-dev \ #cuda-cublas-dev not available with 10-1, install libcublas instead libcublas-11-2 \ libcublas-dev-11-2 \ libcudnn8=${CUDNN_VERSION} \ libcudnn8-dev=${CUDNN_VERSION} \ libnccl2=${NCCL_VERSION} \ libnccl-dev=${NCCL_VERSION} \ libgomp1 \ libffi-dev \ curl \ emacs \ git \ wget \ unzip \ vim \ build-essential \ zlib1g-dev \ openssl \ libssl1.1 \ libreadline-gplv2-dev \ libncursesw5-dev \ libssl-dev \ libsqlite3-dev \ tk-dev \ libgdbm-dev \ libc6-dev \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Install python RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz \ && tar -xvf Python-$PYTHON_VERSION.tgz \ && cd Python-$PYTHON_VERSION \ && ./configure && make && make install -j \ && rm -rf ../Python-$PYTHON_VERSION* \ # Starting from Python39, a xxx.pem file will be generated under /tmp folder during installation. Remove it to complete cleanup after installation from python source. && rm /tmp/*.pem RUN ${PIP} --no-cache-dir install --upgrade \ pip \ setuptools # Install TensorRT # see https://github.com/NVIDIA/TensorRT/blob/master/docker/ubuntu-20.04.Dockerfile # ENV TRT_VERSION 8.0.1.6 # ENV CUDA_VERSION 11.3.1 RUN v="8.0.1-1+cuda11.3" && \ apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub &&\ apt-get update &&\ yes | apt-get install libnvinfer8=${v} libnvonnxparsers8=${v} libnvparsers8=${v} libnvinfer-plugin8=${v} \ libnvinfer-dev=${v} libnvonnxparsers-dev=${v} libnvparsers-dev=${v} libnvinfer-plugin-dev=${v} \ python3-libnvinfer=${v} # Upgrade libsasl2-2 for fixing cyrus-sasl2 related CVE RUN apt-get install -y --only-upgrade libsasl2-2 # Some TF tools expect a "python" binary RUN ln -s $(which ${PYTHON}) /usr/local/bin/python \ && ln -s $(which ${PIP}) /usr/bin/pip RUN apt-get update \ && apt-get -y install --no-install-recommends \ curl \ gnupg2 \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* RUN ${PIP} install -U --no-cache-dir \ "awscli<2" \ boto3 \ cython==0.29.30 \ gevent==21.12.0 \ requests==2.27.1 \ grpcio==1.46.3 \ "protobuf>=3.19.5,<3.20" \ packaging \ # using --no-dependencies to avoid installing tensorflow binary && ${PIP} install --no-dependencies --no-cache-dir \ tensorflow-serving-api-gpu==${TFS_API_VERSION} RUN curl $TFS_URL -o /usr/bin/tensorflow_model_server \ && chmod 555 /usr/bin/tensorflow_model_server # Expose gRPC and REST port EXPOSE 8500 8501 # Set where models should be stored in the container RUN mkdir -p ${MODEL_BASE_PATH} # Create a script that runs the model server so we can use environment variables # while also passing in arguments from the docker command line RUN echo '#!/bin/bash \n\n' > /usr/bin/tf_serving_entrypoint.sh \ && echo '/usr/bin/tensorflow_model_server --port=8500 --rest_api_port=8501 --model_name=${MODEL_NAME} --model_base_path=${MODEL_BASE_PATH}/${MODEL_NAME} "$@"' >> /usr/bin/tf_serving_entrypoint.sh \ && chmod +x /usr/bin/tf_serving_entrypoint.sh ADD https://raw.githubusercontent.com/aws/deep-learning-containers/master/src/deep_learning_container.py /usr/local/bin/deep_learning_container.py RUN chmod +x /usr/local/bin/deep_learning_container.py RUN HOME_DIR=/root \ && curl -o ${HOME_DIR}/oss_compliance.zip https://aws-dlinfra-utilities.s3.amazonaws.com/oss_compliance.zip \ && unzip ${HOME_DIR}/oss_compliance.zip -d ${HOME_DIR}/ \ && cp ${HOME_DIR}/oss_compliance/test/testOSSCompliance /usr/local/bin/testOSSCompliance \ && chmod +x /usr/local/bin/testOSSCompliance \ && chmod +x ${HOME_DIR}/oss_compliance/generate_oss_compliance.sh \ && ${HOME_DIR}/oss_compliance/generate_oss_compliance.sh ${HOME_DIR} ${PYTHON} \ && rm -rf ${HOME_DIR}/oss_compliance* RUN curl https://aws-dlc-licenses.s3.amazonaws.com/tensorflow-2.10/license.txt -o /license.txt RUN rm -rf /tmp/* CMD ["/usr/bin/tf_serving_entrypoint.sh"] ################################################################# # ____ __ __ _ # / ___| __ _ __ _ ___| \/ | __ _| | _____ _ __ # \___ \ / _` |/ _` |/ _ \ |\/| |/ _` | |/ / _ \ '__| # ___) | (_| | (_| | __/ | | | (_| | < __/ | # |____/ \__,_|\__, |\___|_| |_|\__,_|_|\_\___|_| # |___/ # ___ ____ _ # |_ _|_ __ ___ __ _ __ _ ___ | _ \ ___ ___(_)_ __ ___ # | || '_ ` _ \ / _` |/ _` |/ _ \ | |_) / _ \/ __| | '_ \ / _ \ # | || | | | | | (_| | (_| | __/ | _ < __/ (__| | |_) | __/ # |___|_| |_| |_|\__,_|\__, |\___| |_| \_\___|\___|_| .__/ \___| # |___/ |_| ################################################################# FROM ec2 AS sagemaker LABEL maintainer="Amazon AI" LABEL dlc_major_version="1" # Specify accept-bind-to-port LABEL for inference pipelines to use SAGEMAKER_BIND_TO_PORT # https://docs.aws.amazon.com/sagemaker/latest/dg/inference-pipeline-real-time.html LABEL com.amazonaws.sagemaker.capabilities.accept-bind-to-port=true ARG TFS_SHORT_VERSION=2.10 ENV SAGEMAKER_TFS_VERSION="${TFS_SHORT_VERSION}" ENV PATH="$PATH:/sagemaker" # nginx + njs RUN curl -s http://nginx.org/keys/nginx_signing.key | apt-key add - \ && echo 'deb http://nginx.org/packages/ubuntu/ focal nginx' >> /etc/apt/sources.list \ && apt-get update \ && apt-get -y install --no-install-recommends \ nginx \ nginx-module-njs \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* RUN ${PIP} install -U --no-cache-dir \ falcon==3.0.1 \ gunicorn==20.1.0 COPY ./sagemaker /sagemaker # Expose gRPC and REST port EXPOSE 8500 8501 RUN HOME_DIR=/root \ && curl -o ${HOME_DIR}/oss_compliance.zip https://aws-dlinfra-utilities.s3.amazonaws.com/oss_compliance.zip \ && unzip ${HOME_DIR}/oss_compliance.zip -d ${HOME_DIR}/ \ && cp ${HOME_DIR}/oss_compliance/test/testOSSCompliance /usr/local/bin/testOSSCompliance \ && chmod +x /usr/local/bin/testOSSCompliance \ && chmod +x ${HOME_DIR}/oss_compliance/generate_oss_compliance.sh \ && ${HOME_DIR}/oss_compliance/generate_oss_compliance.sh ${HOME_DIR} ${PYTHON} \ && rm -rf ${HOME_DIR}/oss_compliance* CMD ["/usr/bin/tf_serving_entrypoint.sh"]