From 47411cf059ea6871ba2df05adadd073e53e79412 Mon Sep 17 00:00:00 2001 From: Benedikt Wagener Date: Fri, 13 Dec 2024 17:39:08 +0100 Subject: [PATCH] optimize container related configuration and documentation --- .dockerignore | 20 ++++++ Dockerfile | 33 ++++++---- README.md | 62 ++----------------- container/README.md | 16 +++++ .../compose-gpu.yml | 0 .../compose-nogpu.yml | 0 container/docker.md | 47 ++++++++++++++ container/podman.md | 52 ++++++++++++++++ docker-compose/NonGPU/output/.dontremove | 1 - docker-compose/Nvidia/output/.donotremove | 1 - 10 files changed, 162 insertions(+), 70 deletions(-) create mode 100644 .dockerignore create mode 100644 container/README.md rename docker-compose/Nvidia/docker-compose.yml => container/compose-gpu.yml (100%) rename docker-compose/NonGPU/docker-compose.yml => container/compose-nogpu.yml (100%) create mode 100644 container/docker.md create mode 100644 container/podman.md delete mode 100644 docker-compose/NonGPU/output/.dontremove delete mode 100644 docker-compose/Nvidia/output/.donotremove diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7399416 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,20 @@ +evaluation +.git + +.env +.vscode/ +# virtual environment +venv +.venv + +# python +**__pycache__ + +# test data +test_input +test_output + +# default output folder +output +/UltraSinger*.spec +/registry_path.txt diff --git a/Dockerfile b/Dockerfile index 3034fe6..ed33e07 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,27 @@ -FROM nvidia/cuda:12.5.0-runtime-ubuntu22.04 +FROM nvidia/cuda:12.6.3-runtime-ubuntu22.04 -WORKDIR /app -RUN apt-get update && apt-get install git python3-pip -y && apt-get clean && rm -rf /var/lib/apt/lists/* +# note: the python3-pip package contains Python 3.10 on Ubuntu 22.04 +RUN apt-get update \ + && apt-get install git python3-pip python3.10-venv ffmpeg curl -y \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* -RUN git clone https://github.com/rakuri255/UltraSinger.git +COPY . /app/UltraSinger WORKDIR /app/UltraSinger -RUN apt-get update && apt-get install ffmpeg curl -y && apt-get clean && rm -rf /var/lib/apt/lists/* -RUN pip install --no-cache-dir -r requirements.txt -RUN pip install --no-cache-dir torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu121 -RUN pip install --no-cache-dir tensorflow[and-cuda]==2.16.1 -ENV UID=0 -ENV GID=0 -ENV UMASK=022 -EXPOSE 8088 +# no need to run as root +RUN chown -R 1000:1000 /app/UltraSinger +USER 1000:1000 + +# setup venv +ENV VIRTUAL_ENV=/app/UltraSinger/.venv +RUN python3 -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +# install dependencies +RUN pip install --no-cache-dir -r requirements.txt \ + && pip install --no-cache-dir torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu121 \ + && pip install --no-cache-dir tensorflow[and-cuda]==2.16.1 + WORKDIR /app/UltraSinger/src CMD ["bash" ] diff --git a/README.md b/README.md index d7b6595..738fc54 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,8 @@ This will help me a lot to keep this project alive and improve it. - [🏆 Ultrastar Score Calculation](#-ultrastar-score-calculation) - [📟 Use GPU](#-use-gpu) - [Considerations for Windows users](#considerations-for-windows-users) - - [Info](#info) - - [Docker](#docker) + - [Crashes due to low VRAM](#crashes-due-to-low-vram) + - [📦 Containerized](#containerized-docker-or-podman) ## 💻 How to use this source code @@ -276,65 +276,15 @@ TensorFlow dropped GPU support for Windows for versions >2.10 as you can see in For now UltraSinger runs the latest version available that still supports GPUs on windows. -For running later versions of TensorFlow on windows while still taking advantage of GPU support the suggested solution is: +For running later versions of TensorFlow on windows while still taking advantage of GPU support the suggested solution is to [run UltraSinger in a container](container/README.md). -* [install WSL2](https://learn.microsoft.com/en-us/windows/wsl/install) -* within the Ubuntu WSL2 installation - * run `sudo apt update && sudo apt install nvidia-cuda-toolkit` - * follow the setup instructions for UltraSinger at the top of this document - -#### Info +#### Crashes due to low VRAM If something crashes because of low VRAM then use a smaller model. Whisper needs more than 8GB VRAM in the `large` model! You can also force cpu usage with the extra option `--force_cpu`. -#### Docker -to run the docker run `git clone https://github.com/rakuri255/UltraSinger.git` -enter the UltraSinger folder. -run this command to build the docker -`docker build -t ultrasinger .` make sure to include the "." at the end -let this run till complete. -then run this command -`docker run --gpus all -it --name UltraSinger -v $pwd/src/output:/app/src/output ultrasinger` - -Docker-Compose -there are two files that you can pick from. -cd into `docker-compose` folder and then cd into `Nvidia` or `NonGPU` -Run `docker-compose up` to download and setup - -Nvidia is for if you have a nvidia gpu to use with UltraSinger. -NonGPU is for if you wish to only use the CPU for UltraSinger. - -Output -by default the docker-compose will setup the output folder as `/output` inside the docker. -on the host machine it will map to the folder with the `docker-compose.yml` file under `output` -you may chnage this by editing the `docker-compose.yml` - -to edit the file. -use any text editor you wish. i would recoment nano. -run `nano docker-compose.yml` -then change this line -` - ./output:/app/UltraSinger/src/output` -to anything you line for on your host machine. -` - /yourfolderpathhere:/app/UltraSinger/src/output` -sample -` - /mnt/user/appdata/UltraSinger:/output` -note the blank space before the `-` -formating is important here in this file. - -this will create and drop you into the docker. -now run this command. -`python3 UltraSinger.py -i file` -or -`python3 UltraSinger.py -i youtube_url` -to use mp3's in the folder you git cloned you must place all songs you like in UltraSinger/src/output. -this will be the place for youtube links aswell. - - -to quit the docker just type exit. - -to reenter docker run this command -`docker start UltraSinger && Docker exec -it UltraSinger /bin/bash` +### Containerized (Docker or Podman) +See [container/README.md](container/README.md) diff --git a/container/README.md b/container/README.md new file mode 100644 index 0000000..ea4021c --- /dev/null +++ b/container/README.md @@ -0,0 +1,16 @@ +# Containerized UltraSinger + +## Getting started + +1. There are specific instructions for either Docker or Podman: + 1. [Docker](docker.md) + 1. [Podman](podman.md) + +## Why run UltraSinger as a container? + +Running UltraSinger in a container bears the following advantages + +- Environment Consistency: Containers ensure that the application runs in the same environment across different machines, reducing the "it works on my machine" problem. +- Isolation: Containers isolate the application from the host system, preventing conflicts with other applications and dependencies. +- Simplified Deployment: Containers package the application and its dependencies together, simplifying the deployment process. +- Security: Containers provide an additional layer of security by isolating applications from the host system and each other. diff --git a/docker-compose/Nvidia/docker-compose.yml b/container/compose-gpu.yml similarity index 100% rename from docker-compose/Nvidia/docker-compose.yml rename to container/compose-gpu.yml diff --git a/docker-compose/NonGPU/docker-compose.yml b/container/compose-nogpu.yml similarity index 100% rename from docker-compose/NonGPU/docker-compose.yml rename to container/compose-nogpu.yml diff --git a/container/docker.md b/container/docker.md new file mode 100644 index 0000000..35d21c1 --- /dev/null +++ b/container/docker.md @@ -0,0 +1,47 @@ +# Containerized UltraSinger (Docker) + +To run the docker run `git clone https://github.com/rakuri255/UltraSinger.git` +enter the UltraSinger folder. +run this command to build the docker +`docker build -t ultrasinger .` make sure to include the "." at the end +let this run till complete. +then run this command +`docker run --gpus all -it --name UltraSinger -v $pwd/src/output:/app/src/output ultrasinger` + +Docker-Compose +- there are two files that you can pick from. +- cd into the `container` folder +- to download and setup, run either + - `docker-compose -f compose-gpu.yml up` if you have an nvidia gpu to use with UltraSinger + - or`docker-compose -f compose-nogpu.yml up` if you wish to only use the CPU for UltraSinger + +Output +by default the docker-compose will setup the output folder as `/output` inside the docker. +on the host machine it will map to the folder with the `compose.yml` file under `output` +you may change this by editing the `compose.yml` + +to edit the file. +use any text editor you wish. i would recoment nano. +run `nano compose.yml` +then change this line +` - ./output:/app/UltraSinger/src/output` +to anything you line for on your host machine. +` - /yourfolderpathhere:/app/UltraSinger/src/output` +sample +` - /mnt/user/appdata/UltraSinger:/output` +note the blank space before the `-` +formating is important here in this file. + +this will create and drop you into the docker. +now run this command. +`python3 UltraSinger.py -i file` +or +`python3 UltraSinger.py -i youtube_url` +to use mp3's in the folder you git cloned you must place all songs you like in UltraSinger/src/output. +this will be the place for youtube links aswell. + + +to quit the docker just type exit. + +to reenter docker run this command +`docker start UltraSinger && Docker exec -it UltraSinger /bin/bash` diff --git a/container/podman.md b/container/podman.md new file mode 100644 index 0000000..b5c6207 --- /dev/null +++ b/container/podman.md @@ -0,0 +1,52 @@ +# Containerized UltraSinger (Podman) + +1. prerequisites + 1. Podman installed (for Windows WSL2 machine provider is recommended) -> [installation instructions](https://podman-desktop.io/docs/installation) + 1. (optional) for GPU acceleration Nvidia Container Toolkit installed -> [GPU container access](https://podman-desktop.io/docs/podman/gpu) +1. clone this repository: + ```commandline + git clone https://github.com/rakuri255/UltraSinger.git + ``` +1. build the container image + ```commandline + podman build -t ultrasinger . + ``` +1. run the container (note that the first time you run the container models will be downloaded which may take a while) + 1. PowerShell: + ```powershell + # remember to replace below + podman run ` + --rm -it --name ultrasinger ` + --device nvidia.com/gpu=all ` + -v $env:USERPROFILE\.cache:/app/UltraSinger/src/.cache ` + -v :/app/UltraSinger/src/output ` + ultrasinger ` + python3 UltraSinger.py -i + + # explanation: + podman run ` + --rm -it --name ultrasinger ` # remove container after run, interactive mode, name the container + --device nvidia.com/gpu=all ` # optional, enables GPU acceleration if available, requires step 1.ii + -v $env:USERPROFILE\.cache:/app/UltraSinger/src/.cache ` # cache directory for models + -v :/app/UltraSinger/src/output ` # output directory + ultrasinger ` # container image name, we built this in step 3 + python3 UltraSinger.py -i # run UltraSinger, refer to top-level README.md for all options + ``` + 1. Bash: + ```bash + # remember to replace below + podman run \ + --rm -it --name ultrasinger \ + --device nvidia.com/gpu=all \ + -v $HOME/.cache:/app/UltraSinger/src/.cache \ + -v :/app/UltraSinger/src/output \ + ultrasinger \ + python3 UltraSinger.py -i + 1. to use cookies for YouTube downloads, you can mount your cookies.txt file into the container: + ```powershell + podman run ` + ... ` # same as above + -v :/app/UltraSinger/src/cookies.txt ` + ultrasinger ` + python3 UltraSinger.py --cookiefile cookies.txt -i + ``` diff --git a/docker-compose/NonGPU/output/.dontremove b/docker-compose/NonGPU/output/.dontremove deleted file mode 100644 index f36cc91..0000000 --- a/docker-compose/NonGPU/output/.dontremove +++ /dev/null @@ -1 +0,0 @@ -this file is here to save folder path diff --git a/docker-compose/Nvidia/output/.donotremove b/docker-compose/Nvidia/output/.donotremove deleted file mode 100644 index f36cc91..0000000 --- a/docker-compose/Nvidia/output/.donotremove +++ /dev/null @@ -1 +0,0 @@ -this file is here to save folder path