Skip to content

Commit

Permalink
[CI] added base docker image for python wheel build (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
guocuimi authored May 13, 2024
1 parent e7c7425 commit eaf6208
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ on:
- "**/*.md"
- "**/*.txt"
- "**/*.sh"
- "Dockerfile"
- "Dockerfile.*"
- "**/Dockerfile"
- "**/Dockerfile.*"
branches:
- main

Expand All @@ -28,8 +28,8 @@ on:
- "**/*.md"
- "**/*.txt"
- "**/*.sh"
- "Dockerfile"
- "Dockerfile.*"
- "**/Dockerfile"
- "**/Dockerfile.*"
branches:
- main

Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/publish_image.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
48 changes: 48 additions & 0 deletions docker/Dockerfile.base
Original file line number Diff line number Diff line change
@@ -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"]
42 changes: 42 additions & 0 deletions docker/common/install_base.sh
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions docker/common/install_cmake.sh
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions docker/common/install_gcc.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions docker/common/install_ninja.sh
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions docker/common/install_python.sh
Original file line number Diff line number Diff line change
@@ -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

Empty file.
2 changes: 2 additions & 0 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit eaf6208

Please sign in to comment.