Skip to content

Commit

Permalink
update: gpu docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Artrajz committed Sep 9, 2023
1 parent 1fc6b26 commit 7a9f4b7
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 28 deletions.
39 changes: 21 additions & 18 deletions Dockerfile_GPU
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
FROM python:3.10.11-slim-bullseye
FROM nvidia/cuda:11.3.1-cudnn8-runtime-ubuntu20.04

RUN mkdir -p /app
WORKDIR /app

ENV DEBIAN_FRONTEND=noninteractive

COPY . /app
ENV PYTHON_VERSION=3.10.11

RUN apt-get update && \
apt-get install -yq build-essential espeak-ng cmake wget && \
RUN apt-get update && apt-get install -y --no-install-recommends \
python3=$PYTHON_VERSION* \
python3-pip \
build-essential \
espeak-ng \
cmake \
wget && \
apt-get clean && \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \
rm -rf /var/lib/apt/lists/*
rm -rf /var/lib/apt/lists/* && \
ln -s python3 /usr/bin/python && \
ln -s pip3 /usr/bin/pip

WORKDIR /app

COPY . /app

RUN pip install --upgrade pip --no-cache-dir && \
pip install MarkupSafe==2.1.2 numpy==1.23.3 cython six==1.16.0 safetensors==0.3.2 --no-cache-dir
pip install MarkupSafe==2.1.2 numpy==1.23.3 cython six==1.16.0 safetensors==0.3.2 --no-cache-dir && \
pip install -r requirements.txt --no-cache-dir && \
pip install gunicorn --no-cache-dir

RUN pip install torch --index-url https://download.pytorch.org/whl/cu117 --no-cache-dir

RUN wget https://raw.githubusercontent.com/Artrajz/archived/main/openjtalk/openjtalk-0.3.0.dev2.tar.gz && \
tar -zxvf openjtalk-0.3.0.dev2.tar.gz && \
Expand All @@ -25,12 +35,5 @@ RUN wget https://raw.githubusercontent.com/Artrajz/archived/main/openjtalk/openj
rm -f openjtalk-0.3.0.dev2.tar.gz && \
rm -rf openjtalk-0.3.0.dev2

RUN pip install torch --index-url https://download.pytorch.org/whl/cu117 --no-cache-dir

RUN pip install -r requirements.txt --no-cache-dir

RUN pip install gunicorn --no-cache-dir

EXPOSE 23456

CMD ["gunicorn", "-c", "gunicorn_config.py", "app:app"]
7 changes: 5 additions & 2 deletions docker-compose-gpu.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version: '3.4'
version: '3.8'

services:
vits:
image: artrajz/vits-simple-api:latest-gpu
Expand All @@ -13,4 +14,6 @@ services:
- ./config.py:/app/config.py # 挂载配置文件
- ./logs:/app/logs # logging logs
- ./gunicorn_config.py:/app/gunicorn_config.py # gunicorn configuration
- ./bert_vits2/bert/chinese-roberta-wwm-ext-large:/app/bert_vits2/bert/chinese-roberta-wwm-ext-large
- ./bert_vits2/bert/chinese-roberta-wwm-ext-large:/app/bert_vits2/bert/chinese-roberta-wwm-ext-large
devices:
- "/dev/nvidia0:/dev/nvidia0"
67 changes: 59 additions & 8 deletions vits-simple-api-installer-latest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,41 @@ PLAIN='\033[0m'

mkdir -p $INSTALL_DIR
cd $INSTALL_DIR

download_with_fallback() {
local filename=$1
shift # Shift arguments to the left to handle URLs

local success=0
local url
for url in "$@"; do
echo -e "${YELLOW}Attempting to download $filename from $url\n${PLAIN}"
if wget -O "$INSTALL_DIR/$filename" "$url"; then
success=1
break
fi
done

if [ "$success" -ne 1 ]; then
echo -e "${RED}Failed to download $filename from all provided URLs.${PLAIN}"
exit 1
fi
}

version_gt() {
test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"
}

if [ ! -f config.py ]; then
echo -e "${YELLOW}download config.py\n${PLAIN}"
wget -O $INSTALL_DIR/config.py https://raw.githubusercontent.com/Artrajz/vits-simple-api/main/config.py
download_with_fallback config.py \
"https://raw.githubusercontent.com/Artrajz/vits-simple-api/main/config.py" \
"https://ghproxy.com/https://raw.githubusercontent.com/Artrajz/vits-simple-api/main/config.py"
fi

if [ ! -f gunicorn_config.py ]; then
echo -e "${YELLOW}download config.py\n${PLAIN}"
wget -O $INSTALL_DIR/gunicorn_config.py https://raw.githubusercontent.com/Artrajz/vits-simple-api/main/gunicorn_config.py
download_with_fallback gunicorn_config.py \
"https://raw.githubusercontent.com/Artrajz/vits-simple-api/main/gunicorn_config.py" \
"https://ghproxy.com/https://raw.githubusercontent.com/Artrajz/vits-simple-api/main/gunicorn_config.py"
fi

while true; do
Expand All @@ -24,13 +51,15 @@ while true; do
read -p "Enter your choice (1 or 2): " choice
case $choice in
1)
echo -e "${YELLOW}Downloading docker-compose.yaml (CPU version)\n${PLAIN}"
wget -O $INSTALL_DIR/docker-compose.yaml https://raw.githubusercontent.com/Artrajz/vits-simple-api/main/docker-compose.yaml
download_with_fallback docker-compose.yaml \
"https://raw.githubusercontent.com/Artrajz/vits-simple-api/main/docker-compose.yaml" \
"https://ghproxy.com/https://raw.githubusercontent.com/Artrajz/vits-simple-api/main/docker-compose.yaml"
break
;;
2)
echo -e "${YELLOW}Downloading docker-compose-gpu.yaml (GPU version)\n${PLAIN}"
wget -O $INSTALL_DIR/docker-compose.yaml https://raw.githubusercontent.com/Artrajz/vits-simple-api/main/docker-compose-gpu.yaml
download_with_fallback docker-compose.yaml \
"https://raw.githubusercontent.com/Artrajz/vits-simple-api/main/docker-compose-gpu.yaml" \
"https://ghproxy.com/https://raw.githubusercontent.com/Artrajz/vits-simple-api/main/docker-compose-gpu.yaml"
break
;;
*)
Expand All @@ -39,11 +68,33 @@ while true; do
esac
done

if [ "$choice" -eq 2 ]; then
DOCKER_VERSION=$(docker version --format '{{.Server.Version}}')
MIN_DOCKER_VERSION="19.03"

if version_gt $MIN_DOCKER_VERSION $DOCKER_VERSION; then
echo -e "${RED}Your Docker version ($DOCKER_VERSION) does not support GPU. You need at least version $MIN_DOCKER_VERSION.${PLAIN}"
exit 1
fi
fi

if ! command -v docker-compose &> /dev/null; then
echo -e "${RED}docker-compose could not be found.${PLAIN}"
exit 1
fi

echo -e "${YELLOW}Pulling the image might take a while, so why not grab a cup of java first?\n${PLAIN}"

docker compose pull
docker compose up -d

if [ "$choice" -eq 2 ]; then
if ! docker run --gpus all artrajz/vits-simple-api:latest-gpu nvidia-smi &> /dev/null; then
echo -e "${RED}Your Docker does not seem to support GPU or NVIDIA Docker is not installed properly.${PLAIN}"
exit 1
fi
fi

echo -e "\nThe upgrade or installation has been completed."
echo -e "The configuration file directory is $(realpath $INSTALL_DIR)"
echo -e "${YELLOW}If the vits model is not imported, it cannot be used. Import the model in the configuration file directory.${PLAIN}"
Expand Down

0 comments on commit 7a9f4b7

Please sign in to comment.