commit 00ca459ba48b88c4da6880606cb636dd2033bbc7 Author: Mathieu Broillet Date: Sun Jun 30 22:06:23 2024 +0200 First push diff --git a/README.md b/README.md new file mode 100644 index 0000000..18bd5a9 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# ai-suite-rocm-local + +This is a simple project to make hosting multiple AI tools easily on Linux with AMD GPUs using ROCM locally (without docker). + +To use you have to clone the repo run the install script for the service you want to use. + +```bash +git clone https://git.broillet.ch/mathieu/ai-suite-rocm-local.git +cd ai-suite-rocm-local// +./install.sh +``` + +Then you can run whichever service you want using their respectives run.sh scripts. + +```bash +./run.sh +``` + + + +*This has been tested on Fedora 40 with kernel 6.9.6 with an AMD RX 6800 XT.* + diff --git a/background-removal-dis-rocm/.gitignore b/background-removal-dis-rocm/.gitignore new file mode 100644 index 0000000..70295cf --- /dev/null +++ b/background-removal-dis-rocm/.gitignore @@ -0,0 +1,2 @@ +venv/ +webui/ diff --git a/background-removal-dis-rocm/install.sh b/background-removal-dis-rocm/install.sh new file mode 100755 index 0000000..07089c9 --- /dev/null +++ b/background-removal-dis-rocm/install.sh @@ -0,0 +1,38 @@ +#!/bin/bash +source ../utils.sh +python_exec="$(pwd)/venv/bin/python3.10" + +# Function to install StableDiffusion +install_background_remover() { + echo "Cloning webui..." + git clone ssh://git@git.broillet.ch:222/Clone/dis-background-removal.git webui + + echo "Installing requirements..." + $python_exec -m pip install -r webui/requirements.txt + + echo "Cloning DIS repo" + git clone ssh://git@git.broillet.ch:222/Clone/DIS.git tmp-dis + mv tmp-dis/IS-Net/* webui/ + sudo rm -R tmp-dis + + echo "Finalizing..." + mkdir webui/saved_models -p + mv webui/isnet.pth webui/saved_models + sudo rm -R webui/.git + +} + +# Main function +main() { + prepare_env + + # Set it up + install_background_remover + + clean + + echo "BackgroundRemover installation complete." +} + +# Run main function +main diff --git a/background-removal-dis-rocm/run.sh b/background-removal-dis-rocm/run.sh new file mode 100755 index 0000000..11e3703 --- /dev/null +++ b/background-removal-dis-rocm/run.sh @@ -0,0 +1,19 @@ +#!/bin/bash +source ../utils.sh +python_exec="$(pwd)/venv/bin/python3.10" + +# Main function +main() { + # Create virtual environment + use_venv + + # Prints ROCM info with available GPUs + rocm-smi + + # Start BG-remover + cd webui/ + TORCH_BLAS_PREFER_HIPBLASLT=0 $python_exec app.py + +} + +main diff --git a/bitsandbytes-rocm-build/.gitignore b/bitsandbytes-rocm-build/.gitignore new file mode 100644 index 0000000..ac099bf --- /dev/null +++ b/bitsandbytes-rocm-build/.gitignore @@ -0,0 +1 @@ +build_output/ diff --git a/bitsandbytes-rocm-build/Dockerfile b/bitsandbytes-rocm-build/Dockerfile new file mode 100644 index 0000000..72e2d27 --- /dev/null +++ b/bitsandbytes-rocm-build/Dockerfile @@ -0,0 +1,32 @@ +FROM rocm/dev-ubuntu-22.04:6.1.2 + +ENV DEBIAN_FRONTEND=noninteractive \ + PYTHONUNBUFFERED=1 \ + PYTHONIOENCODING=UTF-8 \ + ROCM_ARCH="gfx1030" + +WORKDIR /tmp + +RUN apt-get update -y +RUN apt-get install -y wget git cron cmake make + +# Install python3 +RUN apt-get install -y python3 python3-dev +RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3 +RUN pip3 install --upgrade pip wheel setuptools +# Install pytorch for rocm +RUN pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.1 + +# ROCM bitsandbytes +RUN apt-get install -y hipblas hipblaslt hiprand hipsparse hipcub rocthrust-dev +## Clone repo and install python requirements +RUN git clone --recurse https://github.com/ROCm/bitsandbytes +WORKDIR /tmp/bitsandbytes +RUN git checkout rocm_enabled +RUN pip3 install -r requirements-dev.txt +## Build +RUN cmake -DCOMPUTE_BACKEND=hip -S . -DBNB_ROCM_ARCH=${ROCM_ARCH} +RUN make + +# Cleanup +RUN apt-get clean && pip3 cache purge \ No newline at end of file diff --git a/bitsandbytes-rocm-build/build.sh b/bitsandbytes-rocm-build/build.sh new file mode 100644 index 0000000..ef9cfd6 --- /dev/null +++ b/bitsandbytes-rocm-build/build.sh @@ -0,0 +1 @@ +docker build . -t 'bitsandbytes-rocm-build:6.1.2' -f Dockerfile \ No newline at end of file diff --git a/bitsandbytes-rocm-build/extract_build.sh b/bitsandbytes-rocm-build/extract_build.sh new file mode 100755 index 0000000..38a32d5 --- /dev/null +++ b/bitsandbytes-rocm-build/extract_build.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Set variables +IMAGE_NAME="bitsandbytes-rocm-build:6.1.2" +CONTAINER_NAME="bitsandbytes-rocm-build" +FILE_IN_CONTAINER="/tmp/bitsandbytes" +FILE_ON_HOST="./build_output/" + +# Run the Docker container +docker run -d --name $CONTAINER_NAME $IMAGE_NAME + +# Check if the container is running +if [ "$(docker ps -q -f name=$CONTAINER_NAME)" ]; then + echo "Container $CONTAINER_NAME is running." + + # Copy the file from the container to the host + docker cp $CONTAINER_NAME:$FILE_IN_CONTAINER $FILE_ON_HOST + + if [ $? -eq 0 ]; then + echo "File copied successfully to $FILE_ON_HOST" + else + echo "Failed to copy file." + fi +else + echo "Failed to start container $CONTAINER_NAME." +fi + +docker stop $CONTAINER_NAME +docker rm $CONTAINER_NAME + +echo "Now you can install bitsandbytes locally using \"pip install .\" in the build_output/bitsandbytes folder" \ No newline at end of file diff --git a/stablediffusion-rocm/.gitignore b/stablediffusion-rocm/.gitignore new file mode 100644 index 0000000..70295cf --- /dev/null +++ b/stablediffusion-rocm/.gitignore @@ -0,0 +1,2 @@ +venv/ +webui/ diff --git a/stablediffusion-rocm/install.sh b/stablediffusion-rocm/install.sh new file mode 100755 index 0000000..8e0364d --- /dev/null +++ b/stablediffusion-rocm/install.sh @@ -0,0 +1,30 @@ +#!/bin/bash +source ../utils.sh +python_exec=venv/bin/python3.10 + +# Function to install StableDiffusion +install_stablediffusion() { + if [ -d "webui" ]; then + echo "StableDiffusion repository already exists. Skipping clone." + else + echo "Cloning StableDiffusion repository..." + git clone -b dev https://github.com/AUTOMATIC1111/stable-diffusion-webui webui + fi + echo "Running StableDiffusion setup..." + $python_exec webui/launch.py --skip-torch-cuda-test --exit +} + +# Main function +main() { + prepare_env + + # Install StableDiffusion + install_stablediffusion + + clean + + echo "StableDiffusion installation complete." +} + +# Run main function +main diff --git a/stablediffusion-rocm/run.sh b/stablediffusion-rocm/run.sh new file mode 100755 index 0000000..e003f2b --- /dev/null +++ b/stablediffusion-rocm/run.sh @@ -0,0 +1,18 @@ +#!/bin/bash +source ../utils.sh +python_exec=venv/bin/python3.10 + +# Main function +main() { + # Create virtual environment + use_venv + + # Prints ROCM info with available GPUs + rocm-smi + + # Start SD + TORCH_BLAS_PREFER_HIPBLASLT=0 $python_exec webui/launch.py --listen --enable-insecure-extension-access --opt-split-attention + +} + +main diff --git a/utils.sh b/utils.sh new file mode 100644 index 0000000..391e3a6 --- /dev/null +++ b/utils.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +# Function to check if PyTorch is installed +check_pytorch_installed() { + python -c "import torch" >/dev/null 2>&1 + return $? +} + +# Function to create virtual environment +create_venv() { + if [ -d "venv" ]; then + echo "Virtual environment already exists. Skipping creation." + source venv/bin/activate + else + echo "Creating virtual environment..." + python3.10 -m venv --system-site-packages venv + source venv/bin/activate + python3.10 -m pip install --upgrade pip + fi +} + +use_venv() { + echo "Connecting to virtual environment..." + source venv/bin/activate +} + +# Function to install build-essential or equivalent +install_build_essentials() { + echo "Checking for build essentials..." + if [ -f /etc/debian_version ]; then + sudo apt-get update + sudo apt-get install -y build-essential python3.10-dev + elif [ -f /etc/fedora-release ]; then + if dnf list installed @development-tools &>/dev/null; then + echo "Development Tools are already installed." + else + echo "Installing Development Tools..." + sudo dnf groupinstall -y "Development Tools" + sudo dnf install python3.10-devel + fi + else + echo "Unsupported operating system. Please install build-essential or equivalent manually." + exit 1 + fi +} + +# Function to install PyTorch in the virtual environment +install_pytorch() { + # Check if PyTorch is installed + if check_pytorch_installed; then + echo "PyTorch is already installed." + else + echo "Installing PyTorch..." + python3.10 -m pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.1 + fi +} + +prepare_env(){ + # Create virtual environment + create_venv + + # Install build essentials + install_build_essentials + + # Install PyTorch in the virtual environment + install_pytorch +} + +clean() { + python3.10 -m pip cache purge +} \ No newline at end of file diff --git a/xtts-rocm/.gitignore b/xtts-rocm/.gitignore new file mode 100644 index 0000000..70295cf --- /dev/null +++ b/xtts-rocm/.gitignore @@ -0,0 +1,2 @@ +venv/ +webui/ diff --git a/xtts-rocm/install.sh b/xtts-rocm/install.sh new file mode 100755 index 0000000..20ff6f0 --- /dev/null +++ b/xtts-rocm/install.sh @@ -0,0 +1,39 @@ +#!/bin/bash +source ../utils.sh +python_exec=venv/bin/python3.10 + +# Function to install StableDiffusion +install_xtts() { + if [ -d "webui" ]; then + echo "XTTS repository already exists. Skipping clone." + else + echo "Cloning XTTS repository..." + git clone https://github.com/daswer123/xtts-webui webui + grep -v 'torch' requirements.txt > requirements_without_torch.txt + fi + + $python_exec -m pip install -r webui/requirements_without_torch.txt + + # Disable gpu for faster-whipser as ROCM isn't supported yet + sed -i 's/device = "cuda" if torch.cuda.is_available() else "cpu"/device = "cpu"/' webui/scripts/utils/formatter.py + sed -i 's/asr_model = WhisperModel(whisper_model, device=device, compute_type="float16")/asr_model = WhisperModel(whisper_model, device=device, compute_type="int8")/' webui/scripts/utils/formatter.py + + # Deepspeed and ninja (not working) + $python_exec -m pip install deepspeed ninja + # apt-get install -y ninja-build +} + +# Main function +main() { + prepare_env + + # Install XTTS + install_xtts + + clean + + echo "XTTS installation complete." +} + +# Run main function +main diff --git a/xtts-rocm/run.sh b/xtts-rocm/run.sh new file mode 100755 index 0000000..5df19f3 --- /dev/null +++ b/xtts-rocm/run.sh @@ -0,0 +1,17 @@ +#!/bin/bash +source ../utils.sh +python_exec=venv/bin/python3.10 + +# Main function +main() { + # Create virtual environment + use_venv + + # Prints ROCM info with available GPUs + rocm-smi + + # Start XTTS + $python_exec webui/app.py --host 0.0.0.0 -v v2.0.3 +} + +main \ No newline at end of file