diff --git a/.github/workflows/build-rocm5.5-torch2.0-wheels.yaml b/.github/workflows/build-rocm5.5-torch2.0-wheels.yaml new file mode 100644 index 0000000..2b8bca1 --- /dev/null +++ b/.github/workflows/build-rocm5.5-torch2.0-wheels.yaml @@ -0,0 +1,16 @@ +name: build-rocm5.5-torch2.0-wheels + +on: workflow_dispatch + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: sudo bash scripts/prepare.sh + - run: sudo bash scripts/build_torch.sh + - uses: actions/upload-artifact@v3 + with: + name: wheels + path: | + **/dist/*.whl diff --git a/.github/workflows/build-rocm5.5-torchvision0.15-wheels.yaml b/.github/workflows/build-rocm5.5-torchvision0.15-wheels.yaml new file mode 100644 index 0000000..8b288f7 --- /dev/null +++ b/.github/workflows/build-rocm5.5-torchvision0.15-wheels.yaml @@ -0,0 +1,16 @@ +name: build-rocm5.5-torchvision0.15-wheels + +on: workflow_dispatch + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: sudo bash scripts/prepare.sh + - run: sudo bash scripts/build_torchvision.sh + - uses: actions/upload-artifact@v3 + with: + name: wheels + path: | + **/dist/*.whl diff --git a/.github/workflows/docker-build-rocm5.5-a1111-webui.yaml b/.github/workflows/docker-build-rocm5.5-a1111-webui.yaml new file mode 100644 index 0000000..8fb0ef8 --- /dev/null +++ b/.github/workflows/docker-build-rocm5.5-a1111-webui.yaml @@ -0,0 +1,19 @@ +name: docker-build-rocm5.5-a1111-webui + +on: workflow_dispatch + +jobs: + build: + permissions: + contents: read + packages: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - run: docker build -f dockerfiles/rocm5.5-a1111-webui -t ghcr.io/${{ github.actor }}/rocm_lab:rocm5.5-a1111-webui . + - run: docker push ghcr.io/${{ github.actor }}/rocm_lab:rocm5.5-a1111-webui diff --git a/.github/workflows/docker-build-rocm5.5-ub22.04-base.yaml b/.github/workflows/docker-build-rocm5.5-ub22.04-base.yaml new file mode 100644 index 0000000..ec5bc0c --- /dev/null +++ b/.github/workflows/docker-build-rocm5.5-ub22.04-base.yaml @@ -0,0 +1,19 @@ +name: docker-build-rocm5.5-ub22.04-base + +on: workflow_dispatch + +jobs: + build: + permissions: + contents: read + packages: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - run: docker build -f dockerfiles/rocm5.5-ub22.04-base -t ghcr.io/${{ github.actor }}/rocm_lab:rocm5.5-ub22.04-base . + - run: docker push ghcr.io/${{ github.actor }}/rocm_lab:rocm5.5-ub22.04-base \ No newline at end of file diff --git a/.github/workflows/docker-build-rocm5.5-ub22.04-torch2.0.1.yaml b/.github/workflows/docker-build-rocm5.5-ub22.04-torch2.0.1.yaml new file mode 100644 index 0000000..ecd8aae --- /dev/null +++ b/.github/workflows/docker-build-rocm5.5-ub22.04-torch2.0.1.yaml @@ -0,0 +1,19 @@ +name: docker-build-rocm5.5-ub22.04-torch2.0.1 + +on: workflow_dispatch + +jobs: + build: + permissions: + contents: read + packages: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - run: docker build -f dockerfiles/rocm5.5-ub22.04-torch2.0.1 -t ghcr.io/${{ github.actor }}/rocm_lab:rocm5.5-ub22.04-torch2.0.1 . + - run: docker push ghcr.io/${{ github.actor }}/rocm_lab:rocm5.5-ub22.04-torch2.0.1 diff --git a/dockerfiles/rocm5.5-a1111-webui b/dockerfiles/rocm5.5-a1111-webui new file mode 100644 index 0000000..9bc0bb6 --- /dev/null +++ b/dockerfiles/rocm5.5-a1111-webui @@ -0,0 +1,13 @@ +FROM ghcr.io/evshiron/rocm_lab:rocm5.5-ub22.04-torch2.0.1 + +SHELL ["/bin/bash", "-c"] +WORKDIR /root + +ADD scripts/build_a1111-webui.sh build_a1111-webui.sh + +RUN source venv/bin/activate \ + && bash build_a1111-webui.sh + +CMD source venv/bin/activate \ + && cd /root/stable-diffusion-webui \ + && LD_PRELOAD=libtcmalloc.so python3 launch.py --listen --no-half-vae diff --git a/dockerfiles/rocm5.5-ub22.04-base b/dockerfiles/rocm5.5-ub22.04-base new file mode 100644 index 0000000..4e25f3f --- /dev/null +++ b/dockerfiles/rocm5.5-ub22.04-base @@ -0,0 +1,9 @@ +FROM ubuntu:22.04 + +RUN apt update && apt install -y curl \ + && curl -O https://repo.radeon.com/amdgpu-install/5.5/ubuntu/jammy/amdgpu-install_5.5.50500-1_all.deb \ + && dpkg -i amdgpu-install_5.5.50500-1_all.deb \ + && DEBIAN_FRONTEND=noninteractive amdgpu-install --usecase=rocm --no-dkms --no-32 -y \ + && apt clean + +CMD bash diff --git a/dockerfiles/rocm5.5-ub22.04-torch2.0.1 b/dockerfiles/rocm5.5-ub22.04-torch2.0.1 new file mode 100644 index 0000000..eae49f5 --- /dev/null +++ b/dockerfiles/rocm5.5-ub22.04-torch2.0.1 @@ -0,0 +1,14 @@ +FROM ghcr.io/evshiron/rocm_lab:rocm5.5-ub22.04-base + +SHELL ["/bin/bash", "-c"] +WORKDIR /root + +RUN apt update && apt install -y curl python3-pip python3-venv && python3 -m venv venv +RUN source venv/bin/activate \ + && curl -O https://pub-1cbfe09f357e4aa1a82dc7a43cc443ab.r2.dev/wheel/torch-2.0.1%2Bgitd0d0524-cp310-cp310-linux_x86_64.whl \ + && pip install torch-2.0.1%2Bgitd0d0524-cp310-cp310-linux_x86_64.whl +RUN source venv/bin/activate \ + && curl -O https://pub-1cbfe09f357e4aa1a82dc7a43cc443ab.r2.dev/wheel/torchvision-0.15.2%2B6770a25-cp310-cp310-linux_x86_64.whl \ + && pip install torchvision-0.15.2%2B6770a25-cp310-cp310-linux_x86_64.whl + +CMD bash diff --git a/patches/torch.diff b/patches/torch.diff new file mode 100644 index 0000000..7d88e16 --- /dev/null +++ b/patches/torch.diff @@ -0,0 +1,14 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 471fc8a..c4d3a64 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -463,7 +463,7 @@ option(BUILD_EXECUTORCH "Master flag to build Executorch" ON) + # symbol lookup error: miniconda3/envs/pytorch-py3.7/lib/libmkl_intel_lp64.so: undefined symbol: mkl_blas_dsyrk + # https://software.intel.com/en-us/articles/symbol-lookup-error-when-linking-intel-mkl-with-gcc-on-ubuntu + if(LINUX) +- set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-as-needed") ++ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-as-needed,--verbose,-L/opt/rocm/lib") + endif() + + if(MSVC) + \ No newline at end of file diff --git a/scripts/build_a1111-webui.sh b/scripts/build_a1111-webui.sh new file mode 100644 index 0000000..32bd0e8 --- /dev/null +++ b/scripts/build_a1111-webui.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +set -ex + +# taken from https://github.com/camenduru/stable-diffusion-webui-colab + +apt install -y -qq git wget aria2 libcairo2-dev pkg-config python3-dev libgoogle-perftools-dev + +git clone -b v2.1 https://github.com/camenduru/stable-diffusion-webui + +aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/embed/upscale/resolve/main/4x-UltraSharp.pth -d /root/stable-diffusion-webui/models/ESRGAN -o 4x-UltraSharp.pth +git clone https://github.com/camenduru/stable-diffusion-webui-images-browser /root/stable-diffusion-webui/extensions/stable-diffusion-webui-images-browser +git clone https://github.com/kohya-ss/sd-webui-additional-networks /root/stable-diffusion-webui/extensions/sd-webui-additional-networks +git clone https://github.com/Mikubill/sd-webui-controlnet /root/stable-diffusion-webui/extensions/sd-webui-controlnet +git clone https://github.com/KohakuBlueleaf/a1111-sd-webui-locon /root/stable-diffusion-webui/extensions/a1111-sd-webui-locon +git clone https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111 /root/stable-diffusion-webui/extensions/multidiffusion-upscaler-for-automatic1111 +git clone https://github.com/thomasasfk/sd-webui-aspect-ratio-helper /root/stable-diffusion-webui/extensions/sd-webui-aspect-ratio-helper + +cd /root/stable-diffusion-webui + +pip install git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 +pip install git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 +pip install git+https://github.com/mlfoundations/open_clip.git@bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b + +mkdir -p /root/stable-diffusion-webui/repositories + +git clone https://github.com/Stability-AI/stablediffusion /root/stable-diffusion-webui/repositories/stable-diffusion-stability-ai +git clone https://github.com/CompVis/taming-transformers /root/stable-diffusion-webui/repositories/taming-transformers +git clone https://github.com/crowsonkb/k-diffusion /root/stable-diffusion-webui/repositories/k-diffusion +git clone https://github.com/sczhou/CodeFormer /root/stable-diffusion-webui/repositories/CodeFormer +git clone https://github.com/salesforce/BLIP /root/stable-diffusion-webui/repositories/BLIP + +pip install -r /root/stable-diffusion-webui/repositories/CodeFormer/requirements.txt +pip install -r /root/stable-diffusion-webui/requirements.txt + +# python launch.py --listen diff --git a/scripts/build_torch.sh b/scripts/build_torch.sh new file mode 100644 index 0000000..7b80186 --- /dev/null +++ b/scripts/build_torch.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +set -ex + +python3 -m venv venv + +source venv/bin/activate + +export USE_CUDA=0 +export PYTORCH_ROCM_ARCH=gfx1100 + +# build torch + +curl -L -O https://github.com/pytorch/pytorch/releases/download/v2.0.1/pytorch-v2.0.1.tar.gz +tar -xzvf pytorch-v2.0.1.tar.gz + +cd pytorch-v2.0.1 +echo 2.0.1 > version.txt + +pip install cmake ninja +pip install -r requirements.txt +pip install mkl mkl-include + +python3 tools/amd_build/build_amd.py + +git apply ../patches/torch.diff + +python setup.py bdist_wheel + +cd .. diff --git a/scripts/build_torchvision.sh b/scripts/build_torchvision.sh new file mode 100644 index 0000000..e60e389 --- /dev/null +++ b/scripts/build_torchvision.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +set -ex + +python3 -m venv venv + +source venv/bin/activate + +export FORCE_CUDA=1 + +# build torchvision + +curl -L -O https://pub-1cbfe09f357e4aa1a82dc7a43cc443ab.r2.dev/wheel/torch-2.0.1%2Bgitd0d0524-cp310-cp310-linux_x86_64.whl +pip install torch-2.0.1%2Bgitd0d0524-cp310-cp310-linux_x86_64.whl + +curl -L -O https://github.com/pytorch/vision/archive/refs/tags/v0.15.2.tar.gz +tar -xzvf v0.15.2.tar.gz + +cd vision-0.15.2 +echo 0.15.2 > version.txt + +pip install setuptools wheel cmake ninja + +python setup.py bdist_wheel + +cd .. diff --git a/scripts/prepare.sh b/scripts/prepare.sh new file mode 100644 index 0000000..b40b6fa --- /dev/null +++ b/scripts/prepare.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +apt update && apt install -y git vim curl build-essential python3-pip python3-venv libpython3-dev libpng-dev libjpeg-dev + +curl -O https://repo.radeon.com/amdgpu-install/5.5/ubuntu/jammy/amdgpu-install_5.5.50500-1_all.deb +dpkg -i amdgpu-install_5.5.50500-1_all.deb + +DEBIAN_FRONTEND=noninteractive amdgpu-install --usecase=rocm --no-dkms --no-32 -y