Skip to content

Commit

Permalink
Update build process
Browse files Browse the repository at this point in the history
  • Loading branch information
robballantyne committed Apr 18, 2024
1 parent 2bd9cab commit 34ceda1
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 138 deletions.
159 changes: 79 additions & 80 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,24 @@ name: Docker Build

on:
workflow_dispatch:
push:
branches: [ "main" ]
#push:
# branches: [ "main" ]

env:
UBUNTU_VERSION: 22.04
BUILDX_NO_DEFAULT_ATTESTATIONS: 1
# Until py3.11 is available on all platforms
LATEST_CUDA: "pytorch-2.2.0-py3.10-cuda-11.8.0-runtime-22.04"
LATEST_CUDA_JUPYTER: "jupyter-pytorch-2.2.0-py3.10-cuda-11.8.0-runtime-22.04"
LATEST_ROCM: "pytorch-2.2.0-py3.10-rocm-5.7-runtime-22.04"
LATEST_ROCM_JUPYTER: "jupyter-pytorch-2.2.0-py3.10-rocm-5.7-runtime-22.04"
LATEST_CPU: "pytorch-2.2.0-py3.10-cpu-22.04"
LATEST_CPU_JUPYTER: "jupyter-pytorch-2.2.0-py3.10-cpu-22.04"

jobs:
cpu-base:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
base:
- "pytorch"
- "jupyter-pytorch"
python:
- "3.10"
pytorch:
- "2.1.2"
- "2.2.0"
build:
# Undeclared release tag finds latest from GitHub tags
#- {latest: "true", tag: "v1.9.0", python: "3.10", pytorch: "2.2.2"}
- {latest: "false", tag: "v1.9.0", python: "3.10", pytorch: "2.2.2"}
- {latest: "false", tag: "v1.8.0", python: "3.10", pytorch: "2.2.2"}
steps:
-
name: Free Space
Expand Down Expand Up @@ -65,24 +55,34 @@ jobs:
-
name: Set tags
run: |
img_path="ghcr.io/${{ env.PACKAGE_NAME }}"
ver_tag="${{ matrix.base }}-${{ matrix.pytorch }}-py${{ matrix.python }}-cpu-${{ env.UBUNTU_VERSION }}"
if [[ $ver_tag == ${{ env.LATEST_CPU }} ]]; then
TAGS="${img_path}:latest-cpu, ${img_path}:$ver_tag"
elif [[ $ver_tag == ${{ env.LATEST_CPU_JUPYTER }} ]]; then
TAGS="${img_path}:latest-cpu-jupyter, ${img_path}:$ver_tag"
else
TAGS="${img_path}:$ver_tag"
fi
echo "TAGS=${TAGS}" >> ${GITHUB_ENV}
img_path="ghcr.io/${{ env.PACKAGE_NAME }}"
if [[ -z '${{ matrix.build.tag }}' ]]; then
WEBUI_TAG="$(curl -s https://api.github.com/repos/AUTOMATIC1111/stable-diffusion-webui/tags | jq -r '.[0].name')"
else
WEBUI_TAG="${{ matrix.build.tag }}"
fi
[ -z "$WEBUI_TAG" ] && { echo "Error: WEBUI_TAG is empty. Exiting script." >&2; exit 1; }
echo "WEBUI_TAG=${WEBUI_TAG}" >> ${GITHUB_ENV}
base_tag="cpu-${{ env.UBUNTU_VERSION }}"
if [[ ${{ matrix.build.latest }} == "true" ]]; then
echo "Marking latest"
TAGS="${img_path}:${base_tag}, ${img_path}:latest-cpu, ${img_path}:latest-cpu-jupyter"
else
TAGS="${img_path}:${base_tag}-${WEBUI_TAG}"
fi
echo "TAGS=${TAGS}" >> ${GITHUB_ENV}
-
name: Build and push
uses: docker/build-push-action@v4
with:
context: build
build-args: |
IMAGE_BASE=ghcr.io/ai-dock/${{ matrix.base }}:${{ matrix.pytorch }}-py${{ matrix.python }}-cpu-${{ env.UBUNTU_VERSION }}
IMAGE_BASE=ghcr.io/ai-dock/python:${{ matrix.build.python }}-cpu-${{ env.UBUNTU_VERSION }}
PYTHON_VERSION=${{ matrix.build.python }}
PYTORCH_VERSION=${{ matrix.build.pytorch }}
WEBUI_TAG=${{ env.WEBUI_TAG }}
push: true
# Avoids unknown/unknown architecture and extra metadata
provenance: false
Expand All @@ -93,20 +93,12 @@ jobs:
strategy:
fail-fast: false
matrix:
base:
- "pytorch"
- "jupyter-pytorch"
python:
- "3.10"
pytorch:
- "2.1.2"
- "2.2.0"
cuda:
- "11.8.0"
- "12.1.0"
level:
- "runtime"

build:
# Undeclared release tag finds latest from GitHub tags
#- {latest: "true", tag: "v1.9.0", python: "3.10", pytorch: "2.2.2", cuda: "11.8.0-runtime"}
- {latest: "false", tag: "v1.9.0", python: "3.10", pytorch: "2.2.2", cuda: "12.2.1-runtime"}
- {latest: "false", tag: "v1.8.0", python: "3.10", pytorch: "2.2.2", cuda: "12.2.1-runtime"}

steps:
-
name: Free Space
Expand Down Expand Up @@ -143,24 +135,34 @@ jobs:
name: Set tags
run: |
img_path="ghcr.io/${{ env.PACKAGE_NAME }}"
ver_tag="${{ matrix.base }}-${{ matrix.pytorch }}-py${{ matrix.python }}-cuda-${{ matrix.cuda }}-${{ matrix.level }}-${{ env.UBUNTU_VERSION }}"
if [[ $ver_tag == ${{ env.LATEST_CUDA }} ]]; then
TAGS="${img_path}:latest, ${img_path}:latest-cuda, ${img_path}:$ver_tag"
elif [[ $ver_tag == ${{ env.LATEST_CUDA_JUPYTER }} ]]; then
TAGS="${img_path}:latest-jupyter, ${img_path}:latest-cuda-jupyter, ${img_path}:$ver_tag"
else
TAGS="${img_path}:$ver_tag"
fi
if [[ -z '${{ matrix.build.tag }}' ]]; then
WEBUI_TAG="$(curl -s https://api.github.com/repos/AUTOMATIC1111/stable-diffusion-webui/tags | jq -r '.[0].name')"
else
WEBUI_TAG="${{ matrix.build.tag }}"
fi
[ -z "$WEBUI_TAG" ] && { echo "Error: WEBUI_TAG is empty. Exiting script." >&2; exit 1; }
echo "WEBUI_TAG=${WEBUI_TAG}" >> ${GITHUB_ENV}
base_tag="cuda-${{ matrix.build.cuda }}-${{ env.UBUNTU_VERSION }}"
if [[ ${{ matrix.build.latest }} == "true" ]]; then
echo "Marking latest"
TAGS="${img_path}:${base_tag}, ${img_path}:latest, ${img_path}:latest-jupyter, ${img_path}:latest-cuda"
else
TAGS="${img_path}:${base_tag}-${WEBUI_TAG}"
fi
echo "TAGS=${TAGS}" >> ${GITHUB_ENV}
-
name: Build and push
uses: docker/build-push-action@v4
with:
context: build
build-args: |
IMAGE_BASE=ghcr.io/ai-dock/${{ matrix.base }}:${{ matrix.pytorch }}-py${{ matrix.python }}-cuda-${{ matrix.cuda }}-${{ matrix.level }}-${{ env.UBUNTU_VERSION }}
PYTORCH_VERSION=${{ matrix.pytorch }}
IMAGE_BASE=ghcr.io/ai-dock/python:${{ matrix.build.python }}-cuda-${{ matrix.build.cuda }}-${{ env.UBUNTU_VERSION }}
PYTHON_VERSION=${{ matrix.build.python }}
PYTORCH_VERSION=${{ matrix.build.pytorch }}
WEBUI_TAG=${{ env.WEBUI_TAG }}
push: true
provenance: false
tags: ${{ env.TAGS }}
Expand All @@ -170,24 +172,10 @@ jobs:
strategy:
fail-fast: false
matrix:
base:
- "pytorch"
- "jupyter-pytorch"
python:
- "3.10"
pytorch:
- "2.1.2"
- "2.2.0"
rocm:
- "5.7"
- "5.6"
level:
- "runtime"
exclude:
- rocm: "5.7"
pytorch: "2.1.2"
- rocm: "5.6"
pytorch: "2.2.0"
build:
#- {latest: "true", tag: "v1.9.0", python: "3.10", pytorch: "2.2.2", rocm: "5.7-runtime"}
- {latest: "false", tag: "v1.9.0", python: "3.10", pytorch: "2.2.2", rocm: "5.7-runtime"}
- {latest: "false", tag: "v1.8.0", python: "3.10", pytorch: "2.2.2", rocm: "5.7-runtime"}
steps:
-
name: Free Space
Expand Down Expand Up @@ -224,23 +212,34 @@ jobs:
name: Set tags
run: |
img_path="ghcr.io/${{ env.PACKAGE_NAME }}"
ver_tag="${{ matrix.base }}-${{ matrix.pytorch }}-py${{ matrix.python }}-rocm-${{ matrix.rocm }}-${{ matrix.level }}-${{ env.UBUNTU_VERSION }}"
if [[ $ver_tag == ${{ env.LATEST_ROCM }} ]]; then
TAGS="${img_path}:latest-rocm, ${img_path}:$ver_tag"
elif [[ $ver_tag == ${{ env.LATEST_ROCM_JUPYTER }} ]]; then
TAGS="${img_path}:latest-rocm-jupyter, ${img_path}:$ver_tag"
else
TAGS="${img_path}:$ver_tag"
fi
if [[ -z '${{ matrix.build.tag }}' ]]; then
WEBUI_TAG="$(curl -s https://api.github.com/repos/AUTOMATIC1111/stable-diffusion-webui/tags | jq -r '.[0].name')"
else
WEBUI_TAG="${{ matrix.build.tag }}"
fi
[ -z "$WEBUI_TAG" ] && { echo "Error: WEBUI_TAG is empty. Exiting script." >&2; exit 1; }
echo "WEBUI_TAG=${WEBUI_TAG}" >> ${GITHUB_ENV}
base_tag="rocm-${{ matrix.build.rocm }}-${{ env.UBUNTU_VERSION }}"
if [[ ${{ matrix.build.latest }} == "true" ]]; then
echo "Marking latest"
TAGS="${img_path}:${base_tag}, ${img_path}:latest-rocm, ${img_path}:latest-rocm-jupyter"
else
TAGS="${img_path}:${base_tag}-${WEBUI_TAG}"
fi
echo "TAGS=${TAGS}" >> ${GITHUB_ENV}
-
name: Build and push
uses: docker/build-push-action@v4
with:
context: build
build-args: |
IMAGE_BASE=ghcr.io/ai-dock/${{ matrix.base }}:${{ matrix.pytorch }}-py${{ matrix.python }}-rocm-${{ matrix.rocm }}-${{ matrix.level }}-${{ env.UBUNTU_VERSION }}
IMAGE_BASE=ghcr.io/ai-dock/python:${{ matrix.build.python }}-rocm-${{ matrix.build.rocm }}-${{ env.UBUNTU_VERSION }}
PYTHON_VERSION=${{ matrix.build.python }}
PYTORCH_VERSION=${{ matrix.build.pytorch }}
WEBUI_TAG=${{ env.WEBUI_TAG }}
push: true
provenance: false
tags: ${{ env.TAGS }}
9 changes: 2 additions & 7 deletions build/COPY_ROOT/opt/ai-dock/bin/build/layer0/amd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

build_amd_main() {
build_amd_install_webui
build_common_run_tests
}

build_amd_install_webui() {
# Mamba export does not include pip packages.
# We need to get torch again - todo find a better way?
micromamba -n webui run pip install \
--no-cache-dir \
--index-url https://download.pytorch.org/whl/rocm${ROCM_VERSION} \
torch==${PYTORCH_VERSION} torchvision torchaudio
/opt/ai-dock/bin/update-webui.sh
build_common_install_webui
}

build_amd_main "$@"
87 changes: 54 additions & 33 deletions build/COPY_ROOT/opt/ai-dock/bin/build/layer0/common.sh
Original file line number Diff line number Diff line change
@@ -1,54 +1,75 @@
#!/bin/false

source /opt/ai-dock/etc/environment.sh
webui_git="https://github.com/AUTOMATIC1111/stable-diffusion-webui"

build_common_main() {
build_common_create_env
build_common_install_jupyter_kernels
build_common_clone_webui
}

build_common_create_env() {
apt-get update
$APT_INSTALL libgl1 libgoogle-perftools4
ln -sf $(ldconfig -p | grep -Po "libtcmalloc.so.\d" | head -n 1) \
$APT_INSTALL \
libgl1-mesa-glx \
libtcmalloc-minimal4

ln -sf $(ldconfig -p | grep -Po "libtcmalloc_minimal.so.\d" | head -n 1) \
/lib/x86_64-linux-gnu/libtcmalloc.so
# A new pytorch env costs ~ 300Mb
exported_env=/tmp/${MAMBA_DEFAULT_ENV}.yaml
micromamba env export -n ${MAMBA_DEFAULT_ENV} > "${exported_env}"
$MAMBA_CREATE -n webui --file "${exported_env}"
$MAMBA_INSTALL -n webui \
httpx=0.24.1

micromamba create -n webui
micromamba run -n webui mamba-skel
micromamba install -n webui -y \
python="${PYTHON_VERSION}" \
ipykernel \
ipywidgets \
nano
micromamba run -n webui install-pytorch -v "$PYTORCH_VERSION"
}

build_common_install_jupyter_kernels() {
if [[ $IMAGE_BASE =~ "jupyter-pytorch" ]]; then
$MAMBA_INSTALL -n webui \
ipykernel \
ipywidgets

kernel_path=/usr/local/share/jupyter/kernels

# Add the often-present "Python3 (ipykernel) as a comfyui alias"
rm -rf ${kernel_path}/python3
dir="${kernel_path}/python3"
file="${dir}/kernel.json"
cp -rf ${kernel_path}/../_template ${dir}
sed -i 's/DISPLAY_NAME/'"Python3 (ipykernel)"'/g' ${file}
sed -i 's/PYTHON_MAMBA_NAME/'"webui"'/g' ${file}

dir="${kernel_path}/webui"
file="${dir}/kernel.json"
cp -rf ${kernel_path}/../_template ${dir}
sed -i 's/DISPLAY_NAME/'"WebUI"'/g' ${file}
sed -i 's/PYTHON_MAMBA_NAME/'"webui"'/g' ${file}
fi
micromamba install -n webui -y \
ipykernel \
ipywidgets

kernel_path=/usr/local/share/jupyter/kernels

# Add the often-present "Python3 (ipykernel) as a webui alias"
rm -rf ${kernel_path}/python3
dir="${kernel_path}/python3"
file="${dir}/kernel.json"
cp -rf ${kernel_path}/../_template ${dir}
sed -i 's/DISPLAY_NAME/'"Python3 (ipykernel)"'/g' ${file}
sed -i 's/PYTHON_MAMBA_NAME/'"webui"'/g' ${file}

dir="${kernel_path}/webui"
file="${dir}/kernel.json"
cp -rf ${kernel_path}/../_template ${dir}
sed -i 's/DISPLAY_NAME/'"WebUI"'/g' ${file}
sed -i 's/PYTHON_MAMBA_NAME/'"webui"'/g' ${file}
}

build_common_clone_webui() {
build_common_install_webui() {
# Get latest tag from GitHub if not provided
if [[ -z $WEBUI_TAG ]]; then
export WEBUI_TAG="$(curl -s https://api.github.com/repos/AUTOMATIC1111/stable-diffusion-webui/tags | \
jq -r '.[0].name')"
env-store WEBUI_TAG
fi

cd /opt
git clone ${webui_git}
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
cd /opt/stable-diffusion-webui
git checkout "$WEBUI_TAG"

micromamba run -n webui ${PIP_INSTALL} -r requirements_versions.txt
}

build_common_run_tests() {
installed_pytorch_version=$(micromamba run -n webui python -c "import torch; print(torch.__version__)")
if [[ "$installed_pytorch_version" != "$PYTORCH_VERSION"* ]]; then
echo "Expected PyTorch ${PYTORCH_VERSION} but found ${installed_pytorch_version}\n"
exit 1
fi
}

build_common_main "$@"
3 changes: 2 additions & 1 deletion build/COPY_ROOT/opt/ai-dock/bin/build/layer0/cpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

build_cpu_main() {
build_cpu_install_webui
build_common_run_tests
}

build_cpu_install_webui() {
/opt/ai-dock/bin/update-webui.sh
build_common_install_webui
}

build_cpu_main "$@"
2 changes: 0 additions & 2 deletions build/COPY_ROOT/opt/ai-dock/bin/build/layer0/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ else
exit 1
fi

$MAMBA_DEFAULT_RUN python /opt/ai-dock/tests/assert-torch-version.py

source /opt/ai-dock/bin/build/layer0/clean.sh
Loading

0 comments on commit 34ceda1

Please sign in to comment.