1# syntax = docker/dockerfile:experimental 2ARG ROCM_VERSION=3.7 3ARG BASE_CUDA_VERSION=11.8 4ARG GPU_IMAGE=amd64/almalinux:8 5FROM quay.io/pypa/manylinux_2_28_x86_64 as base 6 7ENV LC_ALL en_US.UTF-8 8ENV LANG en_US.UTF-8 9ENV LANGUAGE en_US.UTF-8 10 11ARG DEVTOOLSET_VERSION=11 12RUN yum install -y sudo wget curl perl util-linux xz bzip2 git patch which perl zlib-devel yum-utils gcc-toolset-${DEVTOOLSET_VERSION}-toolchain 13ENV PATH=/opt/rh/gcc-toolset-${DEVTOOLSET_VERSION}/root/usr/bin:$PATH 14ENV LD_LIBRARY_PATH=/opt/rh/gcc-toolset-${DEVTOOLSET_VERSION}/root/usr/lib64:/opt/rh/gcc-toolset-${DEVTOOLSET_VERSION}/root/usr/lib:$LD_LIBRARY_PATH 15 16# cmake-3.18.4 from pip 17RUN yum install -y python3-pip && \ 18 python3 -mpip install cmake==3.18.4 && \ 19 ln -s /usr/local/bin/cmake /usr/bin/cmake3 20 21FROM base as openssl 22# Install openssl (this must precede `build python` step) 23# (In order to have a proper SSL module, Python is compiled 24# against a recent openssl [see env vars above], which is linked 25# statically. We delete openssl afterwards.) 26ADD ./common/install_openssl.sh install_openssl.sh 27RUN bash ./install_openssl.sh && rm install_openssl.sh 28 29 30# remove unncessary python versions 31RUN rm -rf /opt/python/cp26-cp26m /opt/_internal/cpython-2.6.9-ucs2 32RUN rm -rf /opt/python/cp26-cp26mu /opt/_internal/cpython-2.6.9-ucs4 33RUN rm -rf /opt/python/cp33-cp33m /opt/_internal/cpython-3.3.6 34RUN rm -rf /opt/python/cp34-cp34m /opt/_internal/cpython-3.4.6 35 36FROM base as cuda 37ARG BASE_CUDA_VERSION=11.8 38# Install CUDA 39ADD ./common/install_cuda.sh install_cuda.sh 40RUN bash ./install_cuda.sh ${BASE_CUDA_VERSION} && rm install_cuda.sh 41 42FROM base as intel 43# MKL 44ADD ./common/install_mkl.sh install_mkl.sh 45RUN bash ./install_mkl.sh && rm install_mkl.sh 46 47FROM base as magma 48ARG BASE_CUDA_VERSION=10.2 49# Install magma 50ADD ./common/install_magma.sh install_magma.sh 51RUN bash ./install_magma.sh ${BASE_CUDA_VERSION} && rm install_magma.sh 52 53FROM base as jni 54# Install java jni header 55ADD ./common/install_jni.sh install_jni.sh 56ADD ./java/jni.h jni.h 57RUN bash ./install_jni.sh && rm install_jni.sh 58 59FROM base as libpng 60# Install libpng 61ADD ./common/install_libpng.sh install_libpng.sh 62RUN bash ./install_libpng.sh && rm install_libpng.sh 63 64FROM ${GPU_IMAGE} as common 65ARG DEVTOOLSET_VERSION=11 66ENV LC_ALL en_US.UTF-8 67ENV LANG en_US.UTF-8 68ENV LANGUAGE en_US.UTF-8 69RUN yum -y install epel-release 70RUN yum -y update 71RUN yum install -y \ 72 autoconf \ 73 automake \ 74 bison \ 75 bzip2 \ 76 curl \ 77 diffutils \ 78 file \ 79 git \ 80 make \ 81 patch \ 82 perl \ 83 unzip \ 84 util-linux \ 85 wget \ 86 which \ 87 xz \ 88 gcc-toolset-${DEVTOOLSET_VERSION}-toolchain \ 89 glibc-langpack-en 90RUN yum install -y \ 91 https://repo.ius.io/ius-release-el7.rpm \ 92 https://ossci-linux.s3.amazonaws.com/epel-release-7-14.noarch.rpm 93 94RUN yum swap -y git git236-core 95# git236+ would refuse to run git commands in repos owned by other users 96# Which causes version check to fail, as pytorch repo is bind-mounted into the image 97# Override this behaviour by treating every folder as safe 98# For more details see https://github.com/pytorch/pytorch/issues/78659#issuecomment-1144107327 99RUN git config --global --add safe.directory "*" 100 101ENV SSL_CERT_FILE=/opt/_internal/certs.pem 102# Install LLVM version 103COPY --from=openssl /opt/openssl /opt/openssl 104COPY --from=base /opt/python /opt/python 105COPY --from=base /opt/_internal /opt/_internal 106COPY --from=base /usr/local/bin/auditwheel /usr/local/bin/auditwheel 107COPY --from=intel /opt/intel /opt/intel 108COPY --from=base /usr/local/bin/patchelf /usr/local/bin/patchelf 109COPY --from=libpng /usr/local/bin/png* /usr/local/bin/ 110COPY --from=libpng /usr/local/bin/libpng* /usr/local/bin/ 111COPY --from=libpng /usr/local/include/png* /usr/local/include/ 112COPY --from=libpng /usr/local/include/libpng* /usr/local/include/ 113COPY --from=libpng /usr/local/lib/libpng* /usr/local/lib/ 114COPY --from=libpng /usr/local/lib/pkgconfig /usr/local/lib/pkgconfig 115COPY --from=jni /usr/local/include/jni.h /usr/local/include/jni.h 116 117FROM common as cpu_final 118ARG BASE_CUDA_VERSION=11.8 119ARG DEVTOOLSET_VERSION=11 120# Ensure the expected devtoolset is used 121ENV PATH=/opt/rh/gcc-toolset-${DEVTOOLSET_VERSION}/root/usr/bin:$PATH 122ENV LD_LIBRARY_PATH=/opt/rh/gcc-toolset-${DEVTOOLSET_VERSION}/root/usr/lib64:/opt/rh/gcc-toolset-${DEVTOOLSET_VERSION}/root/usr/lib:$LD_LIBRARY_PATH 123 124# cmake-3.18.4 from pip 125RUN yum install -y python3-pip && \ 126 python3 -mpip install cmake==3.18.4 && \ 127 ln -s /usr/local/bin/cmake /usr/bin/cmake3 128 129FROM cpu_final as cuda_final 130RUN rm -rf /usr/local/cuda-${BASE_CUDA_VERSION} 131COPY --from=cuda /usr/local/cuda-${BASE_CUDA_VERSION} /usr/local/cuda-${BASE_CUDA_VERSION} 132COPY --from=magma /usr/local/cuda-${BASE_CUDA_VERSION} /usr/local/cuda-${BASE_CUDA_VERSION} 133 134FROM common as rocm_final 135ARG ROCM_VERSION=3.7 136# Install ROCm 137ADD ./common/install_rocm.sh install_rocm.sh 138RUN bash ./install_rocm.sh ${ROCM_VERSION} && rm install_rocm.sh 139# cmake is already installed inside the rocm base image, but both 2 and 3 exist 140# cmake3 is needed for the later MIOpen custom build, so that step is last. 141RUN yum install -y cmake3 && \ 142 rm -f /usr/bin/cmake && \ 143 ln -s /usr/bin/cmake3 /usr/bin/cmake 144ADD ./common/install_miopen.sh install_miopen.sh 145RUN bash ./install_miopen.sh ${ROCM_VERSION} && rm install_miopen.sh 146 147FROM cpu_final as xpu_final 148# XPU CD use rolling driver 149ENV XPU_DRIVER_TYPE ROLLING 150# cmake-3.28.4 from pip 151RUN python3 -m pip install --upgrade pip && \ 152 python3 -mpip install cmake==3.28.4 153# Install setuptools and wheel for python 3.13 154RUN /opt/python/cp313-cp313/bin/python -m pip install setuptools wheel 155ADD ./common/install_xpu.sh install_xpu.sh 156RUN bash ./install_xpu.sh && rm install_xpu.sh 157RUN pushd /opt/_internal && tar -xJf static-libs-for-embedding-only.tar.xz && popd 158