Dockerfile 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. ENV HF_HOME=/tmp/hf_cache
  7. ENV TRANSFORMERS_CACHE=/tmp/hf_cache
  8. ENV TORCH_HOME=/tmp/torch_cache
  9. # System dependencies
  10. RUN apt-get update && apt-get install -y --no-install-recommends \
  11. python3.11 \
  12. python3.11-venv \
  13. python3-pip \
  14. git \
  15. git-lfs \
  16. wget \
  17. curl \
  18. && rm -rf /var/lib/apt/lists/* \
  19. && git lfs install
  20. # Set python3.11 as default
  21. RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 \
  22. && update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1
  23. # Upgrade pip
  24. RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
  25. # Install PyTorch with CUDA 12.4
  26. RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
  27. # Install flash-attention for faster training
  28. RUN pip install --no-cache-dir flash-attn --no-build-isolation 2>/dev/null || echo "Flash attention build failed, continuing without it"
  29. # Create app directory
  30. WORKDIR /app
  31. # Copy requirements and install
  32. COPY requirements.txt .
  33. RUN pip install --no-cache-dir -r requirements.txt
  34. # Copy app files
  35. COPY . .
  36. # Create cache directories
  37. RUN mkdir -p /tmp/hf_cache /tmp/torch_cache /tmp/qwen3-uncensored-lora /tmp/merged_model
  38. # Create non-root user for HF Spaces
  39. RUN useradd -m -u 1000 user
  40. USER user
  41. ENV HOME=/home/user
  42. ENV PATH="/home/user/.local/bin:$PATH"
  43. EXPOSE 7860
  44. CMD ["python", "app.py"]