meeting-avatar / Dockerfile
redkits's picture
Pin to single GPU (CUDA_VISIBLE_DEVICES=0): multi-GPU hosts OOM the boot-time model load; stack is single-GPU by design
5eadf1b verified
Raw History Blame Contribute Delete
7.16 kB
# Meeting Avatar — production deployment image
# Based on the upstream OpenAvatarChat Dockerfile (HumanAIGC-Engineering), adapted for
# hosted deployment (HF Space or any CUDA 12.8 host): non-root user, port 7860,
# plain HTTP behind a TLS-terminating proxy, and all model weights baked in at
# build time so container restarts never re-download.
#
# Build context must contain: config/ (this repo's config directory).
FROM nvidia/cuda:12.8.1-cudnn-devel-ubuntu22.04
# Pinned upstream commit — tested with this exact tree:
ARG OAC_COMMIT=8b7b3b4
ARG WORK_DIR=/app
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
UV_COMPILE_BYTECODE=0 \
PYTORCH_JIT=0 \
NVIDIA_DRIVER_CAPABILITIES=compute,utility,video \
HF_HOME=/app/.cache/hf \
MODELSCOPE_CACHE=/app \
TORCH_HOME=/app/.cache/torch \
# Cap parallelism: HF Space builders (and small self-host boxes) have limited RAM;
# uncapped source builds (C++/CUDA extensions, parallel wheel builds) OOM-kill the
# builder with exit 137. install.py only caps its own no-build-isolation phase,
# so bound everything here. Low values = slower compile, bounded memory.
MAX_JOBS=2 \
CMAKE_BUILD_PARALLEL_LEVEL=2 \
NVCC_THREADS=2 \
UV_CONCURRENT_BUILDS=1 \
UV_CONCURRENT_DOWNLOADS=4 \
# Pin to a single GPU: this stack is single-GPU by design (one session per
# GPU, models loaded once). On multi-GPU hosts (e.g. a 2x-a10g Space, 92 GB
# RAM) device enumeration makes boot-time model loading replicate per
# visible GPU and the container is OOM-killed at boot (exit 137) — observed
# where the identical single-GPU l40s host boots fine. Pinning to device 0
# makes any host behave like the verified single-GPU case.
CUDA_VISIBLE_DEVICES=0
# ---------------------------------------------------------------------------
# System dependencies (mirrors upstream Dockerfile, minus China-region mirrors)
# ---------------------------------------------------------------------------
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-venv python3.11-distutils python3-pip \
git git-lfs build-essential \
libgl1 libglib2.0-0 libsm6 libxext6 libgomp1 \
libsndfile1 ffmpeg sox libsox-dev \
libavcodec-dev libavformat-dev libswscale-dev \
curl ca-certificates && \
git lfs install && \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2 && \
update-alternatives --set python3 /usr/bin/python3.11 && \
python3.11 -m ensurepip --upgrade && \
python3.11 -m pip install --no-cache-dir --upgrade pip setuptools wheel
WORKDIR $WORK_DIR
# ---------------------------------------------------------------------------
# Upstream source at the pinned commit, with all handler submodules
# ---------------------------------------------------------------------------
RUN git clone https://github.com/HumanAIGC-Engineering/OpenAvatarChat.git . && \
git checkout $OAC_COMMIT && \
git submodule update --init --recursive --depth 1
# Our runtime configs (MuseTalk default + LiteAvatar fallback)
COPY config/ config/
# Upstream patch (required, verified on GPU smoke test): the CosyVoice TTS
# warmup call passes a bare True into the vendored CosyVoice's zero_shot_spk_id
# parameter (KeyError: True at boot). The streaming path already uses the
# keyword form; align the warmup call.
RUN sed -i 's/self\.ref_audio_buffer, True)/self.ref_audio_buffer, stream=True)/' \
src/handlers/tts/cosyvoice/cosyvoice_processor.py && \
! grep -q "ref_audio_buffer, True)" src/handlers/tts/cosyvoice/cosyvoice_processor.py
# ---------------------------------------------------------------------------
# Python environment — only the handlers our config needs
# ---------------------------------------------------------------------------
RUN pip install --no-cache-dir uv && \
uv venv --python /usr/bin/python3.11 --seed && \
uv run install.py --config config/meeting_avatar.yaml
# Dependency-conflict fix (verified on GPU smoke test): typeguard>=4.4 imports
# NoExtraItems from typing_extensions>=4.14, but resolution installs an older
# typing_extensions, which crashes the CosyVoice TTS processor at import.
RUN uv pip install --no-cache-dir -U "typing_extensions>=4.14"
# Second resolver conflict (verified on GPU smoke test): a NumPy-2-built pyarrow
# is installed against the env's NumPy 1.26 pin, crashing the CosyVoice dataset
# processor import. Pin a NumPy-1-compatible pyarrow build.
RUN uv pip install --no-cache-dir "pyarrow<16"
# onnxruntime GPU variant (Docker-specific, same pin as upstream)
RUN uv pip uninstall onnxruntime onnxruntime-gpu || true
RUN uv pip install --no-cache-dir onnxruntime-gpu==1.20.2
# ---------------------------------------------------------------------------
# Bake all model weights into the image
# ---------------------------------------------------------------------------
# MuseTalk stack (musetalk, SD-VAE, whisper, DWPose, SyncNet, face-parse, s3fd)
RUN uv run --no-sync scripts/download_models.py --config config/meeting_avatar.yaml
# Local CosyVoice2-0.5B (voice cloning TTS) — handler resolves this local path
RUN uv run --no-sync modelscope download --model "iic/CosyVoice2-0.5B" --local_dir "models/iic/CosyVoice2-0.5B"
# SenseVoiceSmall ASR — pre-populate the modelscope snapshot cache at MODELSCOPE_CACHE=/app
RUN uv run --no-sync python -c "import modelscope; modelscope.snapshot_download('iic/SenseVoiceSmall')"
# MuseTalk's s3fd face detector is loaded from the torch-hub cache directory;
# link the downloaded weights there (same layout the upstream run script mounts).
RUN mkdir -p /app/.cache/torch/hub && \
if [ -d /app/models/musetalk/s3fd-619a316812 ]; then \
ln -sfn /app/models/musetalk/s3fd-619a316812 /app/.cache/torch/hub/checkpoints; \
fi
# Stand-in voice reference: CosyVoice's load_wav asserts the source rate must
# exceed the 24 kHz target; the bundled asset is 16 kHz. Resample a copy.
RUN mkdir -p /app/models/voice && \
sox /app/src/handlers/tts/cosyvoice/CosyVoice/asset/zero_shot_prompt.wav -r 48000 /app/models/voice/standin_48k.wav
# ---------------------------------------------------------------------------
# Non-root user (HF Spaces runs containers as UID 1000)
# ---------------------------------------------------------------------------
RUN useradd -m -u 1000 user && chown -R user:user /app
USER user
ENV HOME=/home/user
WORKDIR /app
EXPOSE 7860
# The LLM API key must be provided via the environment (HF Space secret or .env):
# DASHSCOPE_API_KEY — despite the name, this is simply the OpenAI-compatible
# API key read by the LLM handler by default.
CMD ["uv", "run", "--no-sync", "src/demo.py", "--config", "config/meeting_avatar.yaml", "--host", "0.0.0.0", "--port", "7860"]