| # ββ HF GPU Space Dockerfile (CUDA / llama.cpp on GPU) ββββββββββββββββββββββββ | |
| # Optimized: lightweight runtime image + PREBUILT CUDA wheel for llama-cpp-python | |
| # (no source compile, so no nvcc/toolkit needed and no OOM during build). | |
| # | |
| # For local CPU dev, keep using Dockerfile.local instead. | |
| # Lightweight runtime image. We don't compile anything, so we don't need the | |
| # heavier `devel` image (which only existed to provide nvcc). The prebuilt | |
| # llama-cpp-python wheel below already contains compiled CUDA code; this image | |
| # just provides the CUDA 12.4 runtime libraries it links against. | |
| FROM nvidia/cuda:12.4.1-runtime-ubuntu22.04 | |
| # System deps. We use a prebuilt CUDA wheel for llama-cpp-python (no compile), | |
| # but a couple of small pure-C dependencies (e.g. cdifflib, pulled in by | |
| # nemo_text_processing) ship no wheel and must compile from source, so we keep | |
| # build-essential + python3.11-dev (gcc + Python headers) for those. This does | |
| # NOT recompile llama.cpp β that's still the prebuilt wheel below. | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| python3.11 python3.11-dev python3-pip \ | |
| ffmpeg \ | |
| build-essential \ | |
| && rm -rf /var/lib/apt/lists/* \ | |
| && ln -sf /usr/bin/python3.11 /usr/bin/python | |
| # ββ HF permission convention: run as a non-root user with ID 1000 ββββββββββββ | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| WORKDIR $HOME/app | |
| # Keep all model/cache downloads inside the user's home (writable on a Space). | |
| ENV HF_HOME=$HOME/.cache/huggingface \ | |
| XDG_CACHE_HOME=$HOME/.cache | |
| # Install Python deps. Use a PREBUILT CUDA 12.4 wheel for llama-cpp-python: | |
| # - --extra-index-url points pip at abetlen's prebuilt CUDA wheel index | |
| # - --only-binary=:all: for llama-cpp-python forces a prebuilt wheel; if no | |
| # matching wheel exists pip ERRORS LOUDLY instead of silently falling back | |
| # to a (slow, OOM-prone) source compile. `python -m pip` binds to py3.11. | |
| COPY --chown=user requirements-gpu.txt . | |
| RUN python -m pip install --no-cache-dir --upgrade pip && \ | |
| python -m pip install --no-cache-dir --only-binary=:all: \ | |
| llama-cpp-python==0.3.4 \ | |
| --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu124 && \ | |
| python -m pip install --no-cache-dir -r requirements-gpu.txt | |
| # Copy the project (owned by the runtime user). | |
| COPY --chown=user . . | |
| # Pre-download Kokoro + Wav2Vec2 into the build (lazy models pulled at startup). | |
| RUN python scripts/download_models.py | |
| # ββ Runtime config βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Offload all LLM layers to the GPU. Gradio binds 0.0.0.0:7860 (HF default). | |
| ENV LLM_GPU_LAYERS=999 \ | |
| GRADIO_SERVER_NAME=0.0.0.0 \ | |
| GRADIO_SERVER_PORT=7860 | |
| EXPOSE 7860 | |
| CMD ["python", "app.py"] | |