ARG PYTHON=python3 ARG PYTHON_VERSION=3.8.13 ARG MAMBA_VERSION=4.12.0-2 # PyTorch Binaries ARG PT_INFERENCE_URL=https://aws-pytorch-unified-cicd-binaries.s3.us-west-2.amazonaws.com/r1.11.0_ec2/20221206-192811/6ead7f1c1f99d7cc5d15574e6698a855ddd7c823/torch-1.11.0%2Bcpu-cp38-cp38-linux_x86_64.whl ARG PT_TORCHVISION_URL=https://download.pytorch.org/whl/cpu/torchvision-0.12.0%2Bcpu-cp38-cp38-linux_x86_64.whl ARG PT_TORCHAUDIO_URL=https://download.pytorch.org/whl/cpu/torchaudio-0.11.0%2Bcpu-cp38-cp38-linux_x86_64.whl ARG PT_TORCHDATA_URL=https://aws-pytorch-cicd-v3-binaries.s3.us-west-2.amazonaws.com/r1.11.0_v3_e3/aws-torchdata/torchdata-0.4.0-cp38-cp38-linux_x86_64.whl ######################################################## # _____ ____ ____ ___ # | ____/ ___|___ \ |_ _|_ __ ___ __ _ __ _ ___ # | _|| | __) | | || '_ ` _ \ / _` |/ _` |/ _ \ # | |__| |___ / __/ | || | | | | | (_| | (_| | __/ # |_____\____|_____| |___|_| |_| |_|\__,_|\__, |\___| # |___/ # ____ _ # | _ \ ___ ___(_)_ __ ___ # | |_) / _ \/ __| | '_ \ / _ \ # | _ < __/ (__| | |_) | __/ # |_| \_\___|\___|_| .__/ \___| # |_| ######################################################## FROM ubuntu:20.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 ARG PYTHON_VERSION ARG OPEN_MPI_VERSION=4.0.1 ARG MAMBA_VERSION # PyTorch Binaries ARG PT_INFERENCE_URL ARG PT_TORCHVISION_URL ARG PT_TORCHAUDIO_URL ARG PT_TORCHDATA_URL ARG TS_VERSION=0.6.0 ENV LANG=C.UTF-8 ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/conda/lib" ENV PATH=/opt/conda/bin:$PATH ENV TEMP=/home/model-server/tmp # Set MKL_THREADING_LAYER=GNU to prevent issues between torch and numpy/mkl ENV MKL_THREADING_LAYER=GNU ENV DLC_CONTAINER_TYPE=inference RUN apt-get update \ # TODO: Remove systemd upgrade once it is updated in base image && apt-get -y upgrade --only-upgrade systemd \ && apt-get install -y --no-install-recommends software-properties-common \ && add-apt-repository ppa:openjdk-r/ppa \ && apt-get update \ && apt-get install -y --no-install-recommends \ build-essential \ ca-certificates \ cmake \ curl \ emacs \ git \ jq \ libcurl4-openssl-dev \ libgl1-mesa-glx \ libglib2.0-0 \ libsm6 \ libssl-dev \ libxext6 \ libxrender-dev \ openjdk-11-jdk \ openssl \ unzip \ vim \ wget \ zlib1g-dev \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean # https://github.com/docker-library/openjdk/issues/261 https://github.com/docker-library/openjdk/pull/263/files RUN keytool -importkeystore -srckeystore /etc/ssl/certs/java/cacerts -destkeystore /etc/ssl/certs/java/cacerts.jks -deststoretype JKS -srcstorepass changeit -deststorepass changeit -noprompt; \ mv /etc/ssl/certs/java/cacerts.jks /etc/ssl/certs/java/cacerts; \ /var/lib/dpkg/info/ca-certificates-java.postinst configure; RUN wget https://www.open-mpi.org/software/ompi/v4.0/downloads/openmpi-$OPEN_MPI_VERSION.tar.gz \ && gunzip -c openmpi-$OPEN_MPI_VERSION.tar.gz | tar xf - \ && cd openmpi-$OPEN_MPI_VERSION \ && ./configure --prefix=/home/.openmpi \ && make all install \ && cd .. \ && rm openmpi-$OPEN_MPI_VERSION.tar.gz \ && rm -rf openmpi-$OPEN_MPI_VERSION # The ENV variables declared below are changed in the previous section # Grouping these ENV variables in the first section causes # ompi_info to fail. This is only observed in CPU containers ENV PATH="$PATH:/home/.openmpi/bin" ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/.openmpi/lib/" RUN ompi_info --parsable --all | grep mpi_built_with_cuda_support:value RUN curl -L -o ~/mambaforge.sh https://github.com/conda-forge/miniforge/releases/download/${MAMBA_VERSION}/Mambaforge-${MAMBA_VERSION}-Linux-x86_64.sh \ && chmod +x ~/mambaforge.sh \ && ~/mambaforge.sh -b -p /opt/conda \ && rm ~/mambaforge.sh \ && /opt/conda/bin/conda install -c conda-forge \ python=$PYTHON_VERSION \ cython \ mkl \ mkl-include \ parso \ typing \ h5py \ requests \ # Below 2 are included in miniconda base, but not mamba so need to install conda-content-trust \ charset-normalizer \ # Upstream conda looks to have moved to 4.13 which is incompatible with mamba 0.22.1 and will fail the conda-forge installs. # having "conda update conda" before the "conda -c conda-forge" commands will automatically update conda to 4.13. # Moving conda update conda" after the "conda -c conda-forge" commands keep conda at 4.12 but will update other packages using # the current conda 4.12 && /opt/conda/bin/conda update -y conda \ && /opt/conda/bin/conda clean -ya # Conda installs links for libtinfo.so.6 and libtinfo.so.6.2 both # Which causes "/opt/conda/lib/libtinfo.so.6: no version information available" warning # Removing link for libtinfo.so.6. This change is needed only for ubuntu 20.04-conda, and can be reverted # once conda fixes the issue: https://github.com/conda/conda/issues/9680 RUN rm -rf /opt/conda/lib/libtinfo.so.6 # Install aws-sdk-cpp s3;transfer modules for torchdata # pin aws-sdk-cpp modules COPY pin_git_modules.py . RUN git clone https://github.com/aws/aws-sdk-cpp --branch main RUN python pin_git_modules.py --src $(pwd)/aws-sdk-cpp --date 2022-03-17 RUN rm pin_git_modules.py # add necessary flags RUN cd aws-sdk-cpp/ \ && export LD_LIBRARY_PATH="/usr/lib/x86_64-linux-gnu/:${LD_LIBRARY_PATH}" \ && mkdir sdk-build \ && cd sdk-build \ && cmake .. -DCMAKE_CXX_FLAGS="-lcurl" -DCMAKE_BUILD_TYPE=Release -DBUILD_ONLY="s3;transfer" -DAUTORUN_UNIT_TESTS=OFF \ && make \ && make install \ && cd ../.. \ && rm -rf aws-sdk-cpp # Install AWS-PyTorch, and other torch packages RUN pip install --upgrade pip --trusted-host pypi.org --trusted-host files.pythonhosted.org \ && ln -s /opt/conda/bin/pip /usr/local/bin/pip3 \ && pip install --no-cache-dir -U \ "awscli<2" \ boto3 \ "cryptography>3.2" \ enum-compat==0.0.3 \ "ipython>=8.10,<9" \ numpy==1.22.2 \ "opencv-python>=4.6,<5" \ packaging \ "Pillow>=9.3.0" \ "pyyaml>=5.4,<5.5" \ scipy \ && pip uninstall -y torch torchvision torchaudio torchdata \ && pip install --no-cache-dir -U ${PT_INFERENCE_URL} ${PT_TORCHVISION_URL} ${PT_TORCHAUDIO_URL} ${PT_TORCHDATA_URL} RUN pip uninstall -y model-archiver multi-model-server \ && pip install torchserve==${TS_VERSION} \ && pip install torch-model-archiver==${TS_VERSION} # Install TorchServe pypi dependencies directly from their requirements.txt file # NOTE: This also brings in unnecessary cpu dependencies like nvgpu RUN pip install --no-cache-dir -U -r https://raw.githubusercontent.com/pytorch/serve/v${TS_VERSION}/requirements/common.txt # Pillow is pinned in TS 0.6.0 to an obsolete version. To work around this, re-install in a separate line RUN pip install --no-cache-dir -U "Pillow>=9.3.0,<10" RUN useradd -m model-server \ && mkdir -p /home/model-server/tmp /opt/ml/model \ && chown -R model-server /home/model-server /opt/ml/model COPY torchserve-ec2-entrypoint.py /usr/local/bin/dockerd-entrypoint.py COPY config.properties /home/model-server RUN chmod +x /usr/local/bin/dockerd-entrypoint.py COPY 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* \ && rm -rf /tmp/tmp* RUN curl -o /license.txt https://aws-dlc-licenses.s3.amazonaws.com/pytorch-1.11/license.txt EXPOSE 8080 8081 ENTRYPOINT ["python", "/usr/local/bin/dockerd-entrypoint.py"] CMD ["torchserve", "--start", "--ts-config", "/home/model-server/config.properties", "--model-store", "/home/model-server/"] ################################################################# # ____ __ __ _ # / ___| __ _ __ _ ___| \/ | __ _| | _____ _ __ # \___ \ / _` |/ _` |/ _ \ |\/| |/ _` | |/ / _ \ '__| # ___) | (_| | (_| | __/ | | | (_| | < __/ | # |____/ \__,_|\__, |\___|_| |_|\__,_|_|\_\___|_| # |___/ # ___ ____ _ # |_ _|_ __ ___ __ _ __ _ ___ | _ \ ___ ___(_)_ __ ___ # | || '_ ` _ \ / _` |/ _` |/ _ \ | |_) / _ \/ __| | '_ \ / _ \ # | || | | | | | (_| | (_| | __/ | _ < __/ (__| | |_) | __/ # |___|_| |_| |_|\__,_|\__, |\___| |_| \_\___|\___|_| .__/ \___| # |___/ |_| ################################################################# FROM ec2 AS sagemaker LABEL maintainer="Amazon AI" LABEL dlc_major_version="1" LABEL com.amazonaws.sagemaker.capabilities.accept-bind-to-port=true LABEL com.amazonaws.sagemaker.capabilities.multi-models=true ARG PYTHON ENV SAGEMAKER_SERVING_MODULE sagemaker_pytorch_serving_container.serving:main # Install scikit-learn and pandas RUN conda install -y -c conda-forge \ scikit-learn \ pandas RUN pip install --no-cache-dir "sagemaker-pytorch-inference==2.0.10" COPY torchserve-entrypoint.py /usr/local/bin/dockerd-entrypoint.py RUN chmod +x /usr/local/bin/dockerd-entrypoint.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* EXPOSE 8080 8081 ENTRYPOINT ["python", "/usr/local/bin/dockerd-entrypoint.py"] CMD ["torchserve", "--start", "--ts-config", "/home/model-server/config.properties", "--model-store", "/home/model-server/"]