From 62513f9d959cdb3e6f8a22e4663d47d4d45a87d7 Mon Sep 17 00:00:00 2001 From: SanghyeonAn94 Date: Thu, 16 Oct 2025 19:42:29 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=B0=ED=8F=AC=20=EC=A4=80=EB=B9=84?= =?UTF-8?q?=EB=B9=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 - Dockerfile | 111 ++++++++++++++------------ Dockerfile.prod | 124 ++++++++++++++++++++++++++++++ GPT_weights/.gitkeep | 0 GPT_weights_v2/.gitkeep | 0 GPT_weights_v2Pro/.gitkeep | 0 GPT_weights_v2ProPlus/.gitkeep | 0 GPT_weights_v3/.gitkeep | 0 GPT_weights_v4/.gitkeep | 0 SoVITS_weights/.gitkeep | 0 SoVITS_weights_v2/.gitkeep | 0 SoVITS_weights_v2Pro/.gitkeep | 0 SoVITS_weights_v2ProPlus/.gitkeep | 0 SoVITS_weights_v3/.gitkeep | 0 SoVITS_weights_v4/.gitkeep | 0 buildspec.yml | 25 ++++++ 16 files changed, 210 insertions(+), 54 deletions(-) create mode 100644 Dockerfile.prod create mode 100644 GPT_weights/.gitkeep create mode 100644 GPT_weights_v2/.gitkeep create mode 100644 GPT_weights_v2Pro/.gitkeep create mode 100644 GPT_weights_v2ProPlus/.gitkeep create mode 100644 GPT_weights_v3/.gitkeep create mode 100644 GPT_weights_v4/.gitkeep create mode 100644 SoVITS_weights/.gitkeep create mode 100644 SoVITS_weights_v2/.gitkeep create mode 100644 SoVITS_weights_v2Pro/.gitkeep create mode 100644 SoVITS_weights_v2ProPlus/.gitkeep create mode 100644 SoVITS_weights_v3/.gitkeep create mode 100644 SoVITS_weights_v4/.gitkeep create mode 100644 buildspec.yml diff --git a/.gitignore b/.gitignore index d280e459..d6414f33 100644 --- a/.gitignore +++ b/.gitignore @@ -5,10 +5,6 @@ __pycache__ env runtime .idea -output -logs -SoVITS_weights*/ -GPT_weights*/ TEMP weight.json ffmpeg* diff --git a/Dockerfile b/Dockerfile index 71bf6fa1..3187efa6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,62 +1,73 @@ -ARG CUDA_VERSION=12.6 -ARG TORCH_BASE=full +FROM nvidia/cuda:12.8.1-cudnn-runtime-ubuntu22.04 -FROM xxxxrt666/torch-base:cu${CUDA_VERSION}-${TORCH_BASE} +# GPT-SoVITS Docker Image +# This image contains the GPT-SoVITS TTS model with GPU support -LABEL maintainer="XXXXRT" -LABEL version="V4" -LABEL description="Docker image for GPT-SoVITS" +# Prevent interactive prompts during build +ENV DEBIAN_FRONTEND=noninteractive -ARG CUDA_VERSION=12.6 +# Install system dependencies +RUN apt-get update && apt-get install -y \ + software-properties-common \ + && add-apt-repository ppa:deadsnakes/ppa \ + && apt-get update && apt-get install -y \ + python3.11 \ + python3.11-dev \ + python3.11-distutils \ + git \ + wget \ + curl \ + ffmpeg \ + libsndfile1 \ + build-essential \ + && rm -rf /var/lib/apt/lists/* -ENV CUDA_VERSION=${CUDA_VERSION} +# Install pip for Python 3.11 +RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11 -SHELL ["/bin/bash", "-c"] - -WORKDIR /workspace/GPT-SoVITS - -COPY Docker /workspace/GPT-SoVITS/Docker/ - -ARG LITE=false -ENV LITE=${LITE} - -ARG WORKFLOW=false -ENV WORKFLOW=${WORKFLOW} - -ARG TARGETPLATFORM -ENV TARGETPLATFORM=${TARGETPLATFORM} - -RUN bash Docker/miniconda_install.sh - -COPY extra-req.txt /workspace/GPT-SoVITS/ - -COPY requirements.txt /workspace/GPT-SoVITS/ - -COPY install.sh /workspace/GPT-SoVITS/ - -RUN bash Docker/install_wrapper.sh - -EXPOSE 9871 9872 9873 9874 9880 - -ENV PYTHONPATH="/workspace/GPT-SoVITS" - -RUN conda init bash && echo "conda activate base" >> ~/.bashrc +# Set Python 3.11 as default +RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1 && \ + update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.11 1 +# Set working directory WORKDIR /workspace -RUN rm -rf /workspace/GPT-SoVITS +# Environment variables for GPU +ENV NVIDIA_VISIBLE_DEVICES=all +ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility +# Create GPT-SoVITS directory (will be mounted via volumes) +RUN mkdir -p /workspace/GPT-SoVITS + +# Set working directory to GPT-SoVITS WORKDIR /workspace/GPT-SoVITS -COPY . /workspace/GPT-SoVITS +# Install PyTorch with CUDA 12.8 support first +RUN pip install --no-cache-dir \ + torch==2.7.1 \ + torchaudio==2.7.1 \ + --index-url https://download.pytorch.org/whl/cu128 -CMD ["/bin/bash", "-c", "\ - rm -rf /workspace/GPT-SoVITS/GPT_SoVITS/pretrained_models && \ - rm -rf /workspace/GPT-SoVITS/GPT_SoVITS/text/G2PWModel && \ - rm -rf /workspace/GPT-SoVITS/tools/asr/models && \ - rm -rf /workspace/GPT-SoVITS/tools/uvr5/uvr5_weights && \ - ln -s /workspace/models/pretrained_models /workspace/GPT-SoVITS/GPT_SoVITS/pretrained_models && \ - ln -s /workspace/models/G2PWModel /workspace/GPT-SoVITS/GPT_SoVITS/text/G2PWModel && \ - ln -s /workspace/models/asr_models /workspace/GPT-SoVITS/tools/asr/models && \ - ln -s /workspace/models/uvr5_weights /workspace/GPT-SoVITS/tools/uvr5/uvr5_weights && \ - exec bash"] \ No newline at end of file +# Copy GPT-SoVITS requirements.txt from current directory +COPY requirements.txt /tmp/requirements.txt + +# Install GPT-SoVITS dependencies from requirements.txt +RUN pip install --no-cache-dir -r /tmp/requirements.txt + +# Install additional dependencies for STT (not in requirements.txt) +RUN pip install --no-cache-dir \ + "faster-whisper>=1.1.0" \ + soundfile \ + BS-RoFormer + +# Expose API port +EXPOSE 9881 + +# Default configuration +ENV API_HOST=0.0.0.0 +ENV API_PORT=9881 +ENV CONFIG_PATH=GPT_SoVITS/configs/tts_infer.yaml + +# Health check - Just check if the API server is responding (any response is OK, even 4xx) +HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ + CMD curl -s -o /dev/null -w "%{http_code}" http://localhost:9881/tts | grep -E "^[2-4][0-9][0-9]$" > /dev/null || exit 1 \ No newline at end of file diff --git a/Dockerfile.prod b/Dockerfile.prod new file mode 100644 index 00000000..3fd4c0ac --- /dev/null +++ b/Dockerfile.prod @@ -0,0 +1,124 @@ +# Production Dockerfile for GPT-SoVITS +# Self-contained image with GPU support and all dependencies + +FROM nvidia/cuda:12.8.1-cudnn-runtime-ubuntu22.04 + +# Prevent interactive prompts during build +ENV DEBIAN_FRONTEND=noninteractive + +# Install system dependencies including AWS CLI +RUN apt-get update && apt-get install -y \ + software-properties-common \ + && add-apt-repository ppa:deadsnakes/ppa \ + && apt-get update && apt-get install -y \ + python3.11 \ + python3.11-dev \ + python3.11-distutils \ + git \ + wget \ + curl \ + ffmpeg \ + libsndfile1 \ + build-essential \ + unzip \ + && rm -rf /var/lib/apt/lists/* + +# Install AWS CLI v2 +RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \ + && unzip awscliv2.zip \ + && ./aws/install \ + && rm -rf awscliv2.zip aws + +# Install pip for Python 3.11 +RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11 + +# Set Python 3.11 as default +RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1 && \ + update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.11 1 + +# Set working directory +WORKDIR /workspace + +# Environment variables for GPU +ENV NVIDIA_VISIBLE_DEVICES=all +ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility + +# Install PyTorch with CUDA 12.8 support first +RUN pip install --no-cache-dir \ + torch==2.7.1 \ + torchaudio==2.7.1 \ + --index-url https://download.pytorch.org/whl/cu128 + +# Copy only requirements.txt for dependency pre-installation +COPY requirements.txt /tmp/gpt-sovits-requirements.txt + +# Install GPT-SoVITS dependencies +RUN pip install --no-cache-dir -r /tmp/gpt-sovits-requirements.txt + +# Install additional dependencies for STT +RUN pip install --no-cache-dir \ + "faster-whisper>=1.1.0" \ + soundfile \ + BS-RoFormer + +# Create cache storage directory (shared with ML Service) +RUN mkdir -p /app/shared/cache_storage + +# Expose API port +EXPOSE 9881 + +# Environment variables for S3 model download +ENV API_HOST=0.0.0.0 +ENV API_PORT=9881 +ENV CONFIG_PATH=GPT_SoVITS/configs/tts_infer.yaml +ENV MODEL_DIR=/workspace/GPT-SoVITS +ENV S3_MODEL_URI=s3://shiftup-enterprise-ai-service/tts/model_registry/GPT-SoVITS/ + +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \ + CMD curl -s -o /dev/null -w "%{http_code}" http://localhost:9881/tts | grep -E "^[2-4][0-9][0-9]$" > /dev/null || exit 1 + +# Create entrypoint script for S3 model download +RUN echo '#!/bin/bash\n\ +set -e\n\ +\n\ +echo "=== GPT-SoVITS Startup (EC2 Production) ==="\n\ +echo "Model directory: $MODEL_DIR"\n\ +echo "S3 source: $S3_MODEL_URI"\n\ +echo ""\n\ +\n\ +# Check if model directory already exists and has content\n\ +if [ -d "$MODEL_DIR" ] && [ "$(ls -A $MODEL_DIR 2>/dev/null)" ]; then\n\ + echo "✓ Model files already exist in $MODEL_DIR"\n\ + echo "Skipping S3 download..."\n\ +else\n\ + echo "Downloading model files from S3..."\n\ + echo "This may take several minutes on first startup..."\n\ + \n\ + # Create model directory\n\ + mkdir -p $MODEL_DIR\n\ + \n\ + # Download from S3 (using AWS CLI)\n\ + if ! aws s3 sync "$S3_MODEL_URI" "$MODEL_DIR" --delete --quiet; then\n\ + echo "ERROR: Failed to download model files from S3"\n\ + echo "Please check:"\n\ + echo " 1. AWS credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION)"\n\ + echo " 2. S3 URI: $S3_MODEL_URI"\n\ + echo " 3. Network connectivity to S3"\n\ + exit 1\n\ + fi\n\ + \n\ + echo "✓ Model files downloaded successfully"\n\ +fi\n\ +\n\ +echo ""\n\ +echo "Changing to model directory..."\n\ +cd $MODEL_DIR\n\ +\n\ +echo "Current directory: $(pwd)"\n\ +echo ""\n\ +echo "Starting GPT-SoVITS API on $API_HOST:$API_PORT..."\n\ +exec python api_v2.py -a "$API_HOST" -p "$API_PORT" -c "$CONFIG_PATH"\n\ +' > /entrypoint.sh && chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/GPT_weights/.gitkeep b/GPT_weights/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/GPT_weights_v2/.gitkeep b/GPT_weights_v2/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/GPT_weights_v2Pro/.gitkeep b/GPT_weights_v2Pro/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/GPT_weights_v2ProPlus/.gitkeep b/GPT_weights_v2ProPlus/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/GPT_weights_v3/.gitkeep b/GPT_weights_v3/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/GPT_weights_v4/.gitkeep b/GPT_weights_v4/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/SoVITS_weights/.gitkeep b/SoVITS_weights/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/SoVITS_weights_v2/.gitkeep b/SoVITS_weights_v2/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/SoVITS_weights_v2Pro/.gitkeep b/SoVITS_weights_v2Pro/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/SoVITS_weights_v2ProPlus/.gitkeep b/SoVITS_weights_v2ProPlus/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/SoVITS_weights_v3/.gitkeep b/SoVITS_weights_v3/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/SoVITS_weights_v4/.gitkeep b/SoVITS_weights_v4/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/buildspec.yml b/buildspec.yml new file mode 100644 index 00000000..540fab08 --- /dev/null +++ b/buildspec.yml @@ -0,0 +1,25 @@ +version: 0.2 + +env: + variables: + ECR_REGISTRY: "public.ecr.aws/r2p3x7v0/ailabs" + IMAGE_NAME: "sai2ply" + SERVICE_NAME: "gpt-sovits" + +phases: + pre_build: + commands: + - aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws + - export IMAGE_TAG=${CODEBUILD_RESOLVED_SOURCE_VERSION:0:7} + - export FULL_IMAGE_URI="${ECR_REGISTRY}/${IMAGE_NAME}:${SERVICE_NAME}-${IMAGE_TAG}" + - export LATEST_IMAGE_URI="${ECR_REGISTRY}/${IMAGE_NAME}:${SERVICE_NAME}-latest" + + build: + commands: + - docker build -f Dockerfile.prod -t $FULL_IMAGE_URI -t $LATEST_IMAGE_URI . + + post_build: + commands: + - docker push $FULL_IMAGE_URI + - docker push $LATEST_IMAGE_URI + - echo "Image pushed - $LATEST_IMAGE_URI"