ethnmcl commited on
Commit
4e4e6ed
·
verified ·
1 Parent(s): 6a1379c

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +21 -8
Dockerfile CHANGED
@@ -1,26 +1,39 @@
1
- # Hugging Face Spaces (Docker) — GPU-compatible base (works on CPU too)
2
- FROM nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu22.04
3
 
4
  ENV DEBIAN_FRONTEND=noninteractive \
5
  PIP_NO_CACHE_DIR=1 \
6
  HF_HUB_ENABLE_HF_TRANSFER=1 \
7
  UVICORN_WORKERS=1 \
8
- PORT=7860
 
 
 
 
 
 
 
 
9
 
10
- # System deps
11
  RUN apt-get update && apt-get install -y --no-install-recommends \
12
  python3-pip python3-dev git build-essential && \
13
  ln -s /usr/bin/python3 /usr/bin/python && \
14
  pip install --upgrade pip && \
15
  rm -rf /var/lib/apt/lists/*
16
 
17
- # Copy files
 
 
 
 
18
  WORKDIR /app
19
  COPY requirements.txt /app/requirements.txt
20
- RUN pip install -r /app/requirements.txt
21
 
22
- COPY app.py /app/app.py
 
 
23
 
24
- # Expose & run
25
  EXPOSE 7860
26
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
1
+ # GPU-ready base with PyTorch + CUDA 12.1
2
+ FROM pytorch/pytorch:2.3.1-cuda12.1-cudnn8-runtime
3
 
4
  ENV DEBIAN_FRONTEND=noninteractive \
5
  PIP_NO_CACHE_DIR=1 \
6
  HF_HUB_ENABLE_HF_TRANSFER=1 \
7
  UVICORN_WORKERS=1 \
8
+ PORT=7860 \
9
+ HOME=/app \
10
+ XDG_CACHE_HOME=/app/.cache \
11
+ HF_HOME=/app/.cache/huggingface \
12
+ HF_HUB_CACHE=/app/.cache/huggingface/hub \
13
+ TRANSFORMERS_CACHE=/app/.cache/huggingface/transformers \
14
+ HF_DATASETS_CACHE=/app/.cache/huggingface/datasets \
15
+ TORCH_HOME=/app/.cache/torch \
16
+ PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128
17
 
 
18
  RUN apt-get update && apt-get install -y --no-install-recommends \
19
  python3-pip python3-dev git build-essential && \
20
  ln -s /usr/bin/python3 /usr/bin/python && \
21
  pip install --upgrade pip && \
22
  rm -rf /var/lib/apt/lists/*
23
 
24
+ # Make caches writable
25
+ RUN mkdir -p /app/.cache/huggingface/hub /app/.cache/huggingface/transformers \
26
+ /app/.cache/huggingface/datasets /app/.cache/torch && \
27
+ chmod -R 777 /app/.cache
28
+
29
  WORKDIR /app
30
  COPY requirements.txt /app/requirements.txt
 
31
 
32
+ # IMPORTANT: torch is already installed in the base image — don't overwrite it.
33
+ # Remove "torch" from requirements.txt to avoid pulling a CPU wheel by mistake.
34
+ RUN sed -i '/^torch==/d' /app/requirements.txt && pip install -r /app/requirements.txt
35
 
36
+ COPY app.py /app/app.py
37
  EXPOSE 7860
38
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
39
+