ShalomKing commited on
Commit
4ab7b53
·
verified ·
1 Parent(s): b901259

Upload Dockerfile with huggingface_hub

Browse files
Files changed (1) hide show
  1. Dockerfile +25 -20
Dockerfile CHANGED
@@ -1,13 +1,14 @@
1
  FROM nvidia/cuda:12.1.0-devel-ubuntu22.04
2
 
3
  # Set environment variables
4
- ENV DEBIAN_FRONTEND=noninteractive
5
- ENV PYTHONUNBUFFERED=1
 
6
 
7
  # Install system dependencies
8
  RUN apt-get update && apt-get install -y \
9
- python3.10 \
10
- python3.10-dev \
11
  python3-pip \
12
  git \
13
  git-lfs \
@@ -15,12 +16,13 @@ RUN apt-get update && apt-get install -y \
15
  build-essential \
16
  libsndfile1 \
17
  ninja-build \
 
18
  && rm -rf /var/lib/apt/lists/* \
19
  && git lfs install
20
 
21
  # Set Python 3.10 as default
22
- RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1
23
- RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
24
 
25
  # Upgrade pip
26
  RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
@@ -29,37 +31,40 @@ RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
29
  RUN pip install --no-cache-dir \
30
  torch==2.4.1 \
31
  torchvision==0.19.1 \
32
- torchaudio==2.4.1
 
33
 
34
- # Install flash-attn separately with proper flags
35
- RUN pip install --no-cache-dir flash-attn==2.7.4.post1 --no-build-isolation
 
36
 
37
  # Set working directory
38
  WORKDIR /app
39
 
40
- # Copy requirements (without torch and flash-attn since we installed them)
41
- COPY requirements.txt /tmp/requirements-base.txt
42
 
43
- # Install remaining requirements
44
- RUN grep -v "^torch==" /tmp/requirements-base.txt | \
45
- grep -v "^torchvision==" | \
46
- grep -v "^torchaudio==" | \
47
- grep -v "^flash-attn==" | \
48
- pip install --no-cache-dir -r /dev/stdin
49
 
50
  # Copy application files
51
  COPY . .
52
 
53
- # Create user and set permissions
54
  RUN useradd -m -u 1000 user && \
55
- chown -R user:user /app
 
 
56
 
 
57
  USER user
58
 
59
  # Set environment for HuggingFace
60
  ENV HOME=/home/user \
61
  PATH=/home/user/.local/bin:$PATH \
62
- PYTHONPATH=/app
 
63
 
64
  # Expose port for Gradio
65
  EXPOSE 7860
 
1
  FROM nvidia/cuda:12.1.0-devel-ubuntu22.04
2
 
3
  # Set environment variables
4
+ ENV DEBIAN_FRONTEND=noninteractive \
5
+ PYTHONUNBUFFERED=1 \
6
+ PYTHON_VERSION=3.10
7
 
8
  # Install system dependencies
9
  RUN apt-get update && apt-get install -y \
10
+ python${PYTHON_VERSION} \
11
+ python${PYTHON_VERSION}-dev \
12
  python3-pip \
13
  git \
14
  git-lfs \
 
16
  build-essential \
17
  libsndfile1 \
18
  ninja-build \
19
+ wget \
20
  && rm -rf /var/lib/apt/lists/* \
21
  && git lfs install
22
 
23
  # Set Python 3.10 as default
24
+ RUN update-alternatives --install /usr/bin/python python /usr/bin/python${PYTHON_VERSION} 1 && \
25
+ update-alternatives --install /usr/bin/python3 python3 /usr/bin/python${PYTHON_VERSION} 1
26
 
27
  # Upgrade pip
28
  RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
 
31
  RUN pip install --no-cache-dir \
32
  torch==2.4.1 \
33
  torchvision==0.19.1 \
34
+ torchaudio==2.4.1 \
35
+ --index-url https://download.pytorch.org/whl/cu121
36
 
37
+ # Try to install flash-attn, but don't fail if it doesn't work
38
+ RUN pip install --no-cache-dir flash-attn==2.7.4.post1 --no-build-isolation || \
39
+ echo "Warning: flash-attn installation failed, continuing without it (will use slower attention)"
40
 
41
  # Set working directory
42
  WORKDIR /app
43
 
44
+ # Copy requirements.txt first for better caching
45
+ COPY requirements.txt .
46
 
47
+ # Install remaining requirements (skip torch, torchvision, torchaudio, flash-attn as they're already installed)
48
+ RUN pip install --no-cache-dir -r requirements.txt || \
49
+ (echo "Some packages failed to install" && pip install --no-cache-dir -r requirements.txt --ignore-installed)
 
 
 
50
 
51
  # Copy application files
52
  COPY . .
53
 
54
+ # Create user directory and set permissions
55
  RUN useradd -m -u 1000 user && \
56
+ chown -R user:user /app && \
57
+ mkdir -p /home/user/.cache /home/user/.local && \
58
+ chown -R user:user /home/user
59
 
60
+ # Switch to non-root user
61
  USER user
62
 
63
  # Set environment for HuggingFace
64
  ENV HOME=/home/user \
65
  PATH=/home/user/.local/bin:$PATH \
66
+ PYTHONPATH=/app \
67
+ HF_HOME=/home/user/.cache/huggingface
68
 
69
  # Expose port for Gradio
70
  EXPOSE 7860