Skip to content

Commit

Permalink
Separate GPU-accelerated steps to GPU the workload image.
Browse files Browse the repository at this point in the history
  • Loading branch information
HanFa committed Feb 15, 2025
1 parent 79acf1d commit dd698d3
Show file tree
Hide file tree
Showing 32 changed files with 539 additions and 719 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build
- name: Build EasyVideoTrans service
uses: docker/build-push-action@v2
with:
context: .
push: false
tags: hanfa/pytvzhen-web:${{github.event.pull_request.number}}
tags: hanfa/easyvideotrans:${{github.event.pull_request.number}}

- name: Build EasyVideoTrans workloads
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile-gpu-workload
push: false
tags: hanfa/easyvideotrans-workloads:${{github.event.pull_request.number}}
4 changes: 2 additions & 2 deletions .github/workflows/docker-release.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Pytvzhen-web Docker Image Release
name: EasyVideoTrans Service Docker Image Release

on:
workflow_run:
Expand Down Expand Up @@ -29,4 +29,4 @@ jobs:
with:
context: .
push: true
tags: hanfa/pytvzhen-web:latest
tags: hanfa/easyvideotrans:latest
32 changes: 32 additions & 0 deletions .github/workflows/docker-workload-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: EasyVideoTrans Workloads Docker Image Release

on:
workflow_run:
workflows: [ "Pytvzhen-web application test" ]
branches: [ "master" ]
types:
- completed

jobs:
build:
runs-on: self-hosted

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: hanfa/easyvideotrans-workloads:latest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ output/
!celery_results/*

.DS_Store

.pytest_cache
19 changes: 11 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Use an official NVIDIA runtime with CUDA and Miniconda as a parent image
FROM pytorch/pytorch:2.1.0-cuda11.8-cudnn8-runtime AS base
FROM python:3.9-slim AS base

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Disable interactive debian
ENV TZ=America/New_York \
Expand All @@ -15,7 +18,7 @@ COPY requirements.txt .

# Install dependencies
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
RUN pip install --default-timeout=200 -r requirements.txt


FROM base AS final
Expand All @@ -27,11 +30,11 @@ COPY . /app
COPY configs/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Set environment variables to configure Celery
ENV CELERY_BROKER_DOMAIN=localhost
ENV CELERY_BROKER_URL=pyamqp://guest@localhost:5672//
ENV CELERY_RESULT_BACKEND=file:///app/celery_results
ENV CELERY_WORKER_PREFETCH_MULTIPLIER=1
ENV CELERY_TASK_ACKS_LATE=true
ENV CELERY_BROKER_DOMAIN localhost
ENV CELERY_BROKER_URL pyamqp://guest@localhost:5672//
ENV CELERY_RESULT_BACKEND file:///app/celery_results
ENV CELERY_WORKER_PREFETCH_MULTIPLIER 1
ENV CELERY_TASK_ACKS_LATE true

# Make port 8080 available to the world outside this container
EXPOSE 8080
Expand All @@ -42,7 +45,7 @@ ENV FLASK_APP app.py
ENV FLASK_DEBUG 0

ARG PYTVZHEN_STAGE=beta
ENV PYTVZHEN_STAGE=${PYTVZHEN_STAGE}
ENV PYTVZHEN_STAGE ${PYTVZHEN_STAGE}

# Run supervisord to start both Flask and Celery
CMD ["/usr/bin/supervisord"]
30 changes: 30 additions & 0 deletions Dockerfile-gpu-workload
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM pytorch/pytorch:2.6.0-cuda12.4-cudnn9-runtime AS base

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Disable interactive debian
ENV TZ=America/New_York \
DEBIAN_FRONTEND=noninteractive

WORKDIR /app

RUN apt-get update && apt-get install -y \
ffmpeg \
git \
&& rm -rf /var/lib/apt/lists/*


COPY workloads/requirements.txt /app/

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

COPY workloads /app/workloads/
COPY src /app/src/
COPY inference.py /app

ENV LD_LIBRARY_PATH /opt/conda/lib/python3.11/site-packages/nvidia/cudnn/lib

EXPOSE 8188

CMD ["python", "inference.py"]
26 changes: 13 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import zipfile
import shutil
import uuid
from src.service.audio_processing.audio_remove import audio_remove
from src.service.audio_processing.transcribe_audio import transcribe_audio_en
from src.service.audio_processing.voice_connect import connect_voice
from src.service.translation import get_translator, srt_sentense_merge
from src.service.video_synthesis.voice_connect import connect_voice
from src.service.translation import get_translator
from src.service.tts import get_tts_client
from src.workload_client import EasyVideoTransWorkloadClient
from src.task_manager.celery_tasks.tasks import video_preview_task
from src.task_manager.celery_tasks.celery_utils import get_queue_length
from werkzeug.utils import secure_filename
Expand All @@ -19,16 +18,23 @@
from prometheus_flask_exporter import PrometheusMetrics

app = Flask(__name__, template_folder="./appendix/templates", static_folder="./appendix/static")
app.config.from_file("./configs/pytvzhen.json", load=json.load)
app.config.from_file("./configs/easyvideotrans.json", load=json.load)
metrics = PrometheusMetrics(app)
metrics.info('pytvzhen_web', 'Pytvzhen backend API', version='1.0.0')

PYTVZHEN_STAGE = 'PYTVZHEN_STAGE'
pytvzhen_api_request_counter = metrics.counter(
'pytvzhen_api_request_counter', 'Request count by request paths',
labels={'base_url': lambda: url_rule_to_base(request.url_rule), 'stage': lambda: pytvzhen_stage(),
'method': lambda: request.method, 'status': lambda r: r.status_code}
)

# Setup workloads client to submit any GPU workloads to EasyVideoTrans compute backend
gpu_workload = EasyVideoTransWorkloadClient(
audio_separation_endpoint=app.config['VOICE_BACKGROUND_SEPARATION_ENDPOINT'],
audio_transcribe_endpoint=app.config['AUDIO_TRANSCRIBE_ENDPOINT'],
)


def pytvzhen_stage():
return os.environ[PYTVZHEN_STAGE] if PYTVZHEN_STAGE in os.environ else 'default'
Expand Down Expand Up @@ -283,9 +289,7 @@ def remove_audio_bg(video_id):
f'not found at {output_path}, please extract it first')}), 404

try:
baseline_path = app.config['REMOVE_BACKGROUND_MUSIC_BASELINE_MODEL_PATH']
audio_remove(audio_path, audio_no_bg_path, audio_bg_fn_path, baseline_path,
app.config['REMOVE_BACKGROUND_MUSIC_TORCH_DEVICE'])
audio_bg_fn_path, audio_no_bg_fn = gpu_workload.separate_audio(audio_fn)
return jsonify({"message": log_info_return_str(
f"Remove remove background music for {audio_fn} as {audio_no_bg_fn} and {audio_bg_fn_path} successfully."),
"video_id": video_id}), 200
Expand Down Expand Up @@ -333,7 +337,6 @@ def audio_bg_serve(video_id):
def transcribe(video_id):
output_path = app.config['OUTPUT_PATH']

transcribe_model = "medium"
en_srt_fn, en_srt_merged_fn, audio_no_bg_fn = f'{video_id}_en.srt', f'{video_id}_en_merged.srt', f'{video_id}_no_bg.wav'

en_srt_path, en_srt_merged_path, audio_no_bg_path = (os.path.join(output_path, en_srt_fn),
Expand All @@ -351,10 +354,7 @@ def transcribe(video_id):
f'not found at {audio_no_bg_path}, please extract it first')}), 404

try:
transcribe_audio_en(app.logger, path=audio_no_bg_path, modelName=transcribe_model, language="en",
srtFilePathAndName=en_srt_path)
srt_sentense_merge(app.logger, en_srt_path, en_srt_merged_path)

gpu_workload.transcribe_audio(audio_no_bg_fn, [en_srt_fn, en_srt_merged_fn])
return jsonify({"message": log_info_return_str(
f"Transcribed SRT from {audio_no_bg_fn} as {en_srt_fn} and {en_srt_merged_fn} successfully."),
"video_id": video_id}), 200
Expand Down
6 changes: 6 additions & 0 deletions configs/easyvideotrans.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"OUTPUT_PATH": "./output",
"VIDEO_MAX_DURATION": 3610,
"VOICE_BACKGROUND_SEPARATION_ENDPOINT": "http://localhost:8199/audio-sep",
"AUDIO_TRANSCRIBE_ENDPOINT": "http://localhost:8199/audio-transcribe"
}
6 changes: 0 additions & 6 deletions configs/pytvzhen.json

This file was deleted.

Loading

0 comments on commit dd698d3

Please sign in to comment.