Skip to content

Commit

Permalink
Merge pull request #186 from BWagener/feature/container-optimizations
Browse files Browse the repository at this point in the history
optimize container related configuration and documentation
  • Loading branch information
rakuri255 authored Dec 18, 2024
2 parents 26558b6 + 47411cf commit 4c57cf5
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 70 deletions.
20 changes: 20 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
33 changes: 21 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
62 changes: 6 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -285,65 +285,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)
16 changes: 16 additions & 0 deletions container/README.md
Original file line number Diff line number Diff line change
@@ -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.
File renamed without changes.
File renamed without changes.
47 changes: 47 additions & 0 deletions container/docker.md
Original file line number Diff line number Diff line change
@@ -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<gpu|nogpu>.yml` file under `output`
you may change this by editing the `compose<gpu|nogpu>.yml`

to edit the file.
use any text editor you wish. i would recoment nano.
run `nano compose<gpu|nogpu>.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`
52 changes: 52 additions & 0 deletions container/podman.md
Original file line number Diff line number Diff line change
@@ -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 <desired-output-folder> below
podman run `
--rm -it --name ultrasinger `
--device nvidia.com/gpu=all `
-v $env:USERPROFILE\.cache:/app/UltraSinger/src/.cache `
-v <desired-output-folder>:/app/UltraSinger/src/output `
ultrasinger `
python3 UltraSinger.py -i <refer to top-level README.md>
# 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 <desired-output-folder>:/app/UltraSinger/src/output ` # output directory
ultrasinger ` # container image name, we built this in step 3
python3 UltraSinger.py -i <refer to top-level README.md> # run UltraSinger, refer to top-level README.md for all options
```
1. Bash:
```bash
# remember to replace <desired-output-folder> below
podman run \
--rm -it --name ultrasinger \
--device nvidia.com/gpu=all \
-v $HOME/.cache:/app/UltraSinger/src/.cache \
-v <desired-output-folder>:/app/UltraSinger/src/output \
ultrasinger \
python3 UltraSinger.py -i <refer to top-level README.md>
1. to use cookies for YouTube downloads, you can mount your cookies.txt file into the container:
```powershell
podman run `
... ` # same as above
-v <path-to-cookies.txt>:/app/UltraSinger/src/cookies.txt `
ultrasinger `
python3 UltraSinger.py --cookiefile cookies.txt -i <refer to top-level README.md>
```
1 change: 0 additions & 1 deletion docker-compose/NonGPU/output/.dontremove

This file was deleted.

1 change: 0 additions & 1 deletion docker-compose/Nvidia/output/.donotremove

This file was deleted.

0 comments on commit 4c57cf5

Please sign in to comment.