Dockerfile 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. FROM nvidia/cuda:12.4.1-devel-ubuntu22.04
  2. ENV DEBIAN_FRONTEND=noninteractive
  3. ENV PYTHONUNBUFFERED=1
  4. ENV GRADIO_SERVER_NAME=0.0.0.0
  5. ENV GRADIO_SERVER_PORT=7860
  6. # System dependencies
  7. RUN apt-get update && apt-get install -y --no-install-recommends \
  8. python3.11 \
  9. python3.11-venv \
  10. python3.11-dev \
  11. python3-pip \
  12. git \
  13. git-lfs \
  14. wget \
  15. curl \
  16. build-essential \
  17. && rm -rf /var/lib/apt/lists/* \
  18. && git lfs install
  19. # Set python3.11 as default
  20. RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 \
  21. && update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1
  22. # Upgrade pip
  23. RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
  24. # Install PyTorch with CUDA 12.4
  25. RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
  26. # Install transformers from git main (qwen3_next model type not in any stable release yet)
  27. RUN pip install --no-cache-dir "git+https://github.com/huggingface/transformers.git@main"
  28. # Install flash-attention for faster training
  29. RUN pip install --no-cache-dir flash-attn --no-build-isolation 2>/dev/null || echo "Flash attention build failed, continuing without it"
  30. # Install causal-conv1d and flash-linear-attention for DeltaNet layers (optional but recommended)
  31. RUN pip install --no-cache-dir causal-conv1d 2>/dev/null || echo "causal-conv1d build failed, continuing without it"
  32. RUN pip install --no-cache-dir flash-linear-attention 2>/dev/null || echo "flash-linear-attention build failed, continuing without it"
  33. # Create non-root user FIRST
  34. RUN useradd -m -u 1000 user
  35. # Create app directory
  36. WORKDIR /app
  37. # Copy requirements and install (transformers already installed from git above, pip will skip it)
  38. COPY requirements.txt .
  39. RUN pip install --no-cache-dir -r requirements.txt
  40. # Copy app files
  41. COPY . .
  42. # Create ALL directories under user home (NOT /tmp)
  43. RUN mkdir -p /home/user/hf_cache /home/user/torch_cache /home/user/output /home/user/merged \
  44. && chown -R user:user /home/user /app
  45. # Set cache env vars to user home
  46. ENV HOME=/home/user
  47. ENV HF_HOME=/home/user/hf_cache
  48. ENV TRANSFORMERS_CACHE=/home/user/hf_cache
  49. ENV TORCH_HOME=/home/user/torch_cache
  50. ENV PATH="/home/user/.local/bin:$PATH"
  51. USER user
  52. EXPOSE 7860
  53. CMD ["python", "app.py"]