From eaf6208950a3698dde33469ea896cac4bb4b2a0a Mon Sep 17 00:00:00 2001 From: Michael Mi Date: Mon, 13 May 2024 09:58:10 -0700 Subject: [PATCH] [CI] added base docker image for python wheel build (#182) --- .github/workflows/build.yml | 8 +-- .github/workflows/publish_image.yml | 53 +++++++++++++++++++ .../workflows/{docker.yml => release_cpp.yml} | 2 +- docker/Dockerfile.base | 48 +++++++++++++++++ docker/common/install_base.sh | 42 +++++++++++++++ docker/common/install_cmake.sh | 28 ++++++++++ docker/common/install_gcc.sh | 32 +++++++++++ docker/common/install_ninja.sh | 13 +++++ docker/common/install_python.sh | 38 +++++++++++++ python/scalellm/serve/__init__.py | 0 python/setup.py | 2 + 11 files changed, 261 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/publish_image.yml rename .github/workflows/{docker.yml => release_cpp.yml} (98%) create mode 100644 docker/Dockerfile.base create mode 100644 docker/common/install_base.sh create mode 100644 docker/common/install_cmake.sh create mode 100644 docker/common/install_gcc.sh create mode 100644 docker/common/install_ninja.sh create mode 100644 docker/common/install_python.sh create mode 100644 python/scalellm/serve/__init__.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 546f2c5f..9c2430f1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,8 +12,8 @@ on: - "**/*.md" - "**/*.txt" - "**/*.sh" - - "Dockerfile" - - "Dockerfile.*" + - "**/Dockerfile" + - "**/Dockerfile.*" branches: - main @@ -28,8 +28,8 @@ on: - "**/*.md" - "**/*.txt" - "**/*.sh" - - "Dockerfile" - - "Dockerfile.*" + - "**/Dockerfile" + - "**/Dockerfile.*" branches: - main diff --git a/.github/workflows/publish_image.yml b/.github/workflows/publish_image.yml new file mode 100644 index 00000000..1ce1d6c1 --- /dev/null +++ b/.github/workflows/publish_image.yml @@ -0,0 +1,53 @@ +name: Publish docker base image +on: + workflow_dispatch: + +jobs: + publish_base: + runs-on: [self-hosted, linux, build] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_HUB_USER }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + + - name: Build base for cuda 12.1 + uses: docker/build-push-action@v5 + with: + context: ./docker + file: ./docker/Dockerfile.base + push: true + build-args: | + UBUNTU_VERSION=22.04 + CUDA_VERSION=12.1 + GCC_VERSION=12 + CMAKE_VERSION=3.18.5 + NINJA_VERSION=1.9.0 + tags: | + vectorchai/scalellm_builder:cuda12.1-ubuntu22.04 + + - name: Build base for cuda 11.8 + uses: docker/build-push-action@v5 + with: + context: ./docker + file: ./docker/Dockerfile.base + push: true + build-args: | + UBUNTU_VERSION=22.04 + CUDA_VERSION=11.8 + GCC_VERSION=12 + CMAKE_VERSION=3.18.5 + NINJA_VERSION=1.9.0 + tags: | + vectorchai/scalellm_builder:cuda11.8-ubuntu22.04 + diff --git a/.github/workflows/docker.yml b/.github/workflows/release_cpp.yml similarity index 98% rename from .github/workflows/docker.yml rename to .github/workflows/release_cpp.yml index 752d6596..92eed5c1 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/release_cpp.yml @@ -1,4 +1,4 @@ -name: Publish docker image +name: Publish cpp docker image # Build & Push scalellm docker image on creation of tags to https://hub.docker.com/r/vectorchai/scalellm # Push events to matching v*, i.e. v1.0.0, v1.0.0-rc1, v20.15.10-rc5, etc. on: diff --git a/docker/Dockerfile.base b/docker/Dockerfile.base new file mode 100644 index 00000000..76adb4ba --- /dev/null +++ b/docker/Dockerfile.base @@ -0,0 +1,48 @@ +ARG UBUNTU_VERSION=22.04 + +FROM ubuntu:${UBUNTU_VERSION} + +ENV DEBIAN_FRONTEND noninteractive + +# Install common dependencies +COPY ./common/install_base.sh install_base.sh +RUN bash ./install_base.sh && rm install_base.sh + +# Install multiple python versions +COPY ./common/install_python.sh install_python.sh +RUN bash ./install_python.sh "3.9.0" +RUN bash ./install_python.sh "3.10.1" +RUN bash ./install_python.sh "3.11.0" +RUN bash ./install_python.sh "3.12.0" +RUN rm install_python.sh + +# Install cuda, cudnn and nccl +ARG CUDA_VERSION=12.1 +RUN wget -q https://raw.githubusercontent.com/pytorch/builder/main/common/install_cuda.sh -O install_cuda.sh +RUN bash ./install_cuda.sh ${CUDA_VERSION} && rm install_cuda.sh +ENV DESIRED_CUDA ${CUDA_VERSION} +ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH + +# Install gcc +ARG GCC_VERSION=12 +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + software-properties-common gpg-agent +COPY ./common/install_gcc.sh install_gcc.sh +RUN bash ./install_gcc.sh && rm install_gcc.sh + +ARG CMAKE_VERSION=3.18.5 +COPY ./common/install_cmake.sh install_cmake.sh +RUN if [ -n "${CMAKE_VERSION}" ]; then bash ./install_cmake.sh; fi +RUN rm install_cmake.sh + +ARG NINJA_VERSION=1.9.0 +COPY ./common/install_ninja.sh install_ninja.sh +RUN if [ -n "${NINJA_VERSION}" ]; then bash ./install_ninja.sh; fi +RUN rm install_ninja.sh + +# install rust +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y +ENV PATH=$HOME/.cargo/bin:$PATH + +CMD ["bash"] \ No newline at end of file diff --git a/docker/common/install_base.sh b/docker/common/install_base.sh new file mode 100644 index 00000000..7d5da3f2 --- /dev/null +++ b/docker/common/install_base.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -ex + +install_ubuntu() { + deploy_deps="libffi-dev libbz2-dev libreadline-dev libncurses5-dev libncursesw5-dev libgdbm-dev libsqlite3-dev uuid-dev tk-dev" + # Install common dependencies + apt-get update + apt-get install -y --no-install-recommends \ + ${deploy_deps} \ + build-essential \ + ccache \ + zip \ + pkg-config \ + libssl-dev \ + libboost-all-dev \ + software-properties-common \ + curl \ + git \ + wget \ + sudo \ + vim \ + jq \ + libtool \ + unzip \ + gdb + + # Cleanup package manager + apt-get autoclean && apt-get clean + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +} + +ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"') +case "$ID" in + ubuntu) + install_ubuntu + ;; + *) + echo "Unable to determine OS..." + exit 1 + ;; +esac \ No newline at end of file diff --git a/docker/common/install_cmake.sh b/docker/common/install_cmake.sh new file mode 100644 index 00000000..3332ac09 --- /dev/null +++ b/docker/common/install_cmake.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -ex + +[ -n "$CMAKE_VERSION" ] + +# Remove system cmake install so it won't get used instead +ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"') +case "$ID" in + ubuntu) + apt-get remove cmake -y + ;; + *) + echo "Unable to determine OS..." + exit 1 + ;; +esac + +# Turn 3.6.3 into v3.6 +path=$(echo "${CMAKE_VERSION}" | sed -e 's/\([0-9].[0-9]\+\).*/v\1/') +file="cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz" + +# Download and install specific CMake version in /usr/local +pushd /tmp +curl -Os --retry 3 "https://cmake.org/files/${path}/${file}" +tar -C /usr/local --strip-components 1 --no-same-owner -zxf cmake-*.tar.gz +rm -f cmake-*.tar.gz +popd \ No newline at end of file diff --git a/docker/common/install_gcc.sh b/docker/common/install_gcc.sh new file mode 100644 index 00000000..4890f070 --- /dev/null +++ b/docker/common/install_gcc.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -ex + +[ -n "$GCC_VERSION" ] + +install_ubuntu() { + # Need the official toolchain repo to get alternate packages + add-apt-repository ppa:ubuntu-toolchain-r/test + apt-get update + apt-get install -y g++-$GCC_VERSION + update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-"$GCC_VERSION" 50 + update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-"$GCC_VERSION" 50 + update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-"$GCC_VERSION" 50 + + + # Cleanup package manager + apt-get autoclean && apt-get clean + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +} + + +ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"') +case "$ID" in + ubuntu) + install_ubuntu + ;; + *) + echo "Unable to determine OS..." + exit 1 + ;; +esac \ No newline at end of file diff --git a/docker/common/install_ninja.sh b/docker/common/install_ninja.sh new file mode 100644 index 00000000..596f5e9d --- /dev/null +++ b/docker/common/install_ninja.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -ex + +[ -n "$NINJA_VERSION" ] + +url="https://github.com/ninja-build/ninja/releases/download/v${NINJA_VERSION}/ninja-linux.zip" + +pushd /tmp +wget --no-verbose --output-document=ninja-linux.zip "$url" +unzip ninja-linux.zip -d /usr/local/bin +rm -f ninja-linux.zip +popd \ No newline at end of file diff --git a/docker/common/install_python.sh b/docker/common/install_python.sh new file mode 100644 index 00000000..8d748818 --- /dev/null +++ b/docker/common/install_python.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +set -ex + +PYTHON_VERSION="$1" +shift + +NO_RC_PYTHON_VERSION="${PYTHON_VERSION%rc*}" + +url="https://www.python.org/ftp/python/${NO_RC_PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz" + +pushd /tmp +wget "$url" +tar xvzf "Python-${PYTHON_VERSION}.tgz" +cd "Python-${PYTHON_VERSION}" + +# Extract major and minor version number +MAJOR=$(echo "${PYTHON_VERSION}" | cut -d . -f 1) +MINOR=$(echo "${PYTHON_VERSION}" | cut -d . -f 2) + +INSTALL_FOLDER="/opt/python/cp${MAJOR}${MINOR}-cp${MAJOR}${MINOR}" + +./configure \ + --enable-shared \ + --enable-ipv6 \ + --prefix=${INSTALL_FOLDER} \ + LDFLAGS=-Wl,-rpath=${INSTALL_FOLDER}/lib,--disable-new-dtags + +make -j$(nproc) install +# upgrade pip, setuptools and wheel +${INSTALL_FOLDER}/bin/python3 -m pip install --upgrade pip setuptools wheel +# create symlinks +cp ${INSTALL_FOLDER}/bin/pip3 ${INSTALL_FOLDER}/bin/pip +ln -s ${INSTALL_FOLDER}/bin/python3 ${INSTALL_FOLDER}/bin/python + +rm -rf "Python-${PYTHON_VERSION}" +popd + diff --git a/python/scalellm/serve/__init__.py b/python/scalellm/serve/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/python/setup.py b/python/setup.py index 88eedaef..8a7ea7e9 100644 --- a/python/setup.py +++ b/python/setup.py @@ -172,6 +172,8 @@ def build_extension(self, ext: CMakeExtension): url="https://github.com/vectorch-ai/ScaleLLM", packages=[ "scalellm", + "scalellm/serve", + "examples" ], ext_modules=[CMakeExtension("_C", "scalellm/")], cmdclass={"build_ext": CMakeBuild},