From 847adbc75cbd311b75001b508452d0b6e90d1df6 Mon Sep 17 00:00:00 2001 From: kaixuanliu Date: Mon, 16 Dec 2024 17:03:50 +0800 Subject: [PATCH] refine Dockerfile to support both cpu and xpu platform (#981) * refine Dockerfile to support both cpu and xpu Signed-off-by: Liu, Kaixuan * nice code Signed-off-by: Liu, Kaixuan * fix CI issue Signed-off-by: Liu, Kaixuan * rename Dockerfile.intel to Dockerfile.ipex Signed-off-by: Liu, Kaixuan * upgrade ipex to 2.5 version; replace extra-index-url Signed-off-by: Liu, Kaixuan --------- Signed-off-by: Liu, Kaixuan --- .github/workflows/dockerfile_sanity.yml | 8 +-- Dockerfile.ipex | 73 +++++++++++++++++++++++++ docker/Dockerfile.intel | 53 ------------------ 3 files changed, 77 insertions(+), 57 deletions(-) create mode 100644 Dockerfile.ipex delete mode 100644 docker/Dockerfile.intel diff --git a/.github/workflows/dockerfile_sanity.yml b/.github/workflows/dockerfile_sanity.yml index 060b80ca45..738be80319 100644 --- a/.github/workflows/dockerfile_sanity.yml +++ b/.github/workflows/dockerfile_sanity.yml @@ -5,13 +5,13 @@ on: branches: - main paths: - - "docker/Dockerfile.intel" - + - 'Dockerfile.ipex' + pull_request: branches: - main paths: - - "docker/Dockerfile.intel" + - 'Dockerfile.ipex' jobs: build_and_run: @@ -27,7 +27,7 @@ jobs: - name: Build and Run Docker Image run: | IMAGE_NAME="intel_image:latest" - docker build -f docker/Dockerfile.intel -t $IMAGE_NAME . + docker build -f Dockerfile.ipex -t $IMAGE_NAME . if [ $? -ne 0 ]; then echo "Docker image build failed." exit 1 diff --git a/Dockerfile.ipex b/Dockerfile.ipex new file mode 100644 index 0000000000..a03b1d26a3 --- /dev/null +++ b/Dockerfile.ipex @@ -0,0 +1,73 @@ +ARG PLATFORM=cpu + +FROM ubuntu:22.04 as cpu +WORKDIR /usr/src/ +RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \ + sh -c "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ + ca-certificates \ + git \ + curl \ + vim \ + build-essential \ + ccache \ + libgoogle-perftools-dev \ + numactl \ + cmake \ + libjpeg-dev \ + pybind11-dev \ + libpng-dev \ + python3 \ + python3-pip \ + && rm -rf /var/lib/apt/lists/*" +RUN /usr/sbin/update-ccache-symlinks +RUN mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache + +ARG IPEX_VERSION=2.5.0 +ARG PYTORCH_VERSION=2.5.1 +ARG TORCHVISION_VERSION=0.20.1+cpu +ARG TORCHAUDIO_VERSION=2.5.1+cpu + +RUN python3 -m pip install --no-cache-dir \ + torch==${PYTORCH_VERSION}+cpu \ + torchvision==${TORCHVISION_VERSION} \ + torchaudio==${TORCHAUDIO_VERSION} \ + --index-url https://download.pytorch.org/whl/cpu && \ + python3 -m pip install intel-openmp -f https://download.pytorch.org/whl/torch_stable.html && \ + python3 -m pip install intel-extension-for-pytorch==$IPEX_VERSION && \ + python3 -m pip install oneccl_bind_pt --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/cpu/cn/ && \ + python3 -m pip install --no-cache-dir py-libnuma + +ARG KMP_BLOCKTIME=1 +ENV KMP_BLOCKTIME=${KMP_BLOCKTIME} +ARG KMP_HW_SUBSET=1T +ENV KMP_HW_SUBSET=${KMP_HW_SUBSET} +ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libtcmalloc.so" + +FROM intel/intel-extension-for-pytorch:2.3.110-xpu as xpu +WORKDIR /usr/src/ + +RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \ + sh -c "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ + ca-certificates \ + git \ + curl \ + vim \ + ccache \ + libgoogle-perftools-dev \ + numactl \ + libjpeg-dev \ + pybind11-dev \ + libpng-dev \ + && rm -rf /var/lib/apt/lists/*" +RUN wget -qO - https://repositories.intel.com/gpu/intel-graphics.key | gpg --dearmor | tee /usr/share/keyrings/intel-graphics.gpg > /dev/null + +RUN wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \ +| gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null && echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | tee /etc/apt/sources.list.d/oneAPI.list + +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt install -y intel-basekit xpu-smi cmake ninja-build pciutils + +FROM ${PLATFORM} + +COPY optimum optimum +COPY Makefile setup.cfg setup.py pyproject.toml README.md ./ +RUN pip install . diff --git a/docker/Dockerfile.intel b/docker/Dockerfile.intel deleted file mode 100644 index ad4ff63e8c..0000000000 --- a/docker/Dockerfile.intel +++ /dev/null @@ -1,53 +0,0 @@ -# syntax = docker/dockerfile:1 -# based onhttps://github.com/pytorch/pytorch/blob/master/Dockerfile -# -# NOTE: To build this you will need a docker version >= 19.03 and DOCKER_BUILDKIT=1 -# -# If you do not use buildkit you are not going to have a good time -# -# For reference: -# https://docs.docker.com/develop/develop-images/build_enhancements/ - -ARG BASE_IMAGE=ubuntu:22.04 -FROM ${BASE_IMAGE} - -RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \ - sh -c "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ - ca-certificates \ - git \ - curl \ - vim \ - build-essential \ - ccache \ - libgoogle-perftools-dev \ - numactl \ - cmake \ - libjpeg-dev \ - pybind11-dev \ - libpng-dev \ - python3 \ - python3-pip \ - && rm -rf /var/lib/apt/lists/*" -RUN /usr/sbin/update-ccache-symlinks -RUN mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache - -ARG IPEX_VERSION=2.3.100 -ARG PYTORCH_VERSION=2.3.1 -ARG TORCHVISION_VERSION=0.18.1+cpu -ARG TORCHAUDIO_VERSION=2.3.1+cpu - -RUN python3 -m pip install --no-cache-dir \ - intel-openmp \ - torch==${PYTORCH_VERSION}+cpu \ - torchvision==${TORCHVISION_VERSION} \ - torchaudio==${TORCHAUDIO_VERSION} \ - -f https://download.pytorch.org/whl/torch_stable.html && \ - python3 -m pip install intel-extension-for-pytorch==$IPEX_VERSION && \ - python3 -m pip install oneccl_bind_pt --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/cpu/us/ && \ - python3 -m pip install --no-cache-dir py-libnuma - -ARG KMP_BLOCKTIME=1 -ENV KMP_BLOCKTIME=${KMP_BLOCKTIME} -ARG KMP_HW_SUBSET=1T -ENV KMP_HW_SUBSET=${KMP_HW_SUBSET} -ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libtcmalloc.so"