ashutosh-koottu commited on
Commit
caf6800
·
1 Parent(s): 4f004a4

Force CUDA use

Browse files
Files changed (2) hide show
  1. Dockerfile +19 -41
  2. handler.py +10 -2
Dockerfile CHANGED
@@ -1,63 +1,41 @@
1
- FROM python:3.10-slim
2
 
3
- # Add CUDA repository and install CUDA toolkit
4
- RUN apt-get update && apt-get install -y --no-install-recommends \
5
- wget \
6
- gnupg2 \
7
- && wget -qO - https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/3bf863cc.pub | apt-key add - \
8
- && echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64 /" > /etc/apt/sources.list.d/cuda.list \
9
- && apt-get update \
10
- && apt-get install -y --no-install-recommends \
11
- cuda-toolkit-12-4 \
12
- libcudnn8 \
13
- libcublas-12-4 \
14
- && rm -rf /var/lib/apt/lists/*
15
-
16
- # Install build tools and system dependencies
17
  RUN apt-get update && apt-get install -y --no-install-recommends \
 
 
 
18
  build-essential \
19
- gcc \
20
- g++ \
21
  git \
 
22
  libglib2.0-0 \
23
  libsm6 \
24
  libxext6 \
25
  libxrender-dev \
26
- elfutils \
27
  && rm -rf /var/lib/apt/lists/*
28
 
29
- # Verify Python version
30
- RUN python --version && pip --version
 
31
 
32
- WORKDIR /code
33
 
34
- # Copy requirements first for better layer caching
35
  COPY requirements.txt .
 
 
36
 
37
- # Install Python packages with pip upgrade
38
- RUN python3.10 -m pip install --no-cache-dir --upgrade pip setuptools wheel && \
39
- python3.10 -m pip install --no-cache-dir -r requirements.txt
40
-
41
- # Fix executable stack issue in onnxruntime binary
42
- RUN find /usr/local/lib/python3.10/site-packages/onnxruntime -name "*.so" -type f 2>/dev/null | while read f; do \
43
- execstack -c "$f" 2>/dev/null || true; \
44
- done || true
45
-
46
- # Fix CUDA library symlinks for onnxruntime compatibility
47
- RUN find /usr/local/cuda/lib64 -name "libcublas*" -o -name "libcudnn*" 2>/dev/null && \
48
- ln -sf /usr/local/cuda/lib64/libcublasLt.so.12.* /usr/local/cuda/lib64/libcublasLt.so.12 2>/dev/null || true && \
49
- ln -sf /usr/local/cuda/lib64/libcublas.so.12.* /usr/local/cuda/lib64/libcublas.so.12 2>/dev/null || true && \
50
- ln -sf /usr/local/cuda/lib64/libcudart.so.12.* /usr/local/cuda/lib64/libcudart.so.12 2>/dev/null || true
51
-
52
  COPY . .
53
 
54
- # Set comprehensive environment variables for CUDA
 
 
 
55
  ENV CUDA_HOME=/usr/local/cuda
 
56
  ENV PATH=${CUDA_HOME}/bin:${PATH}
57
- ENV LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${CUDA_HOME}/extras/CUPTI/lib64:/usr/local/cuda/lib64:/usr/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}
58
  ENV INSIGHTFACE_HOME=/tmp/.insightface
59
- ENV MPLCONFIGDIR=/tmp/matplotlib
60
- ENV ORT_CUDA_UNAVAILABLE=0
61
 
62
  EXPOSE 7860
63
 
 
1
+ FROM nvidia/cuda:12.4.1-runtime-ubuntu22.04
2
 
3
+ # Install Python 3.10 and essential dependencies
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  RUN apt-get update && apt-get install -y --no-install-recommends \
5
+ python3.10 \
6
+ python3.10-dev \
7
+ python3-pip \
8
  build-essential \
 
 
9
  git \
10
+ libgl1-mesa-glx \
11
  libglib2.0-0 \
12
  libsm6 \
13
  libxext6 \
14
  libxrender-dev \
 
15
  && rm -rf /var/lib/apt/lists/*
16
 
17
+ # Set Python 3.10 as default
18
+ RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1 && \
19
+ update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
20
 
21
+ WORKDIR /app
22
 
23
+ # Copy and install requirements
24
  COPY requirements.txt .
25
+ RUN pip install --no-cache-dir --upgrade pip && \
26
+ pip install --no-cache-dir -r requirements.txt
27
 
28
+ # Copy application code
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  COPY . .
30
 
31
+ # Create insightface cache directory
32
+ RUN mkdir -p /tmp/.insightface
33
+
34
+ # Set environment variables
35
  ENV CUDA_HOME=/usr/local/cuda
36
+ ENV LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}
37
  ENV PATH=${CUDA_HOME}/bin:${PATH}
 
38
  ENV INSIGHTFACE_HOME=/tmp/.insightface
 
 
39
 
40
  EXPOSE 7860
41
 
handler.py CHANGED
@@ -19,8 +19,16 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
19
 
20
  class EndpointHandler:
21
  def __init__(self, model_dir=None):
22
- self.app = FaceAnalysis(root="/tmp/.insightface")
23
- self.app.prepare(ctx_id=0) # Set to 0 for GPU, or -1 for CPU
 
 
 
 
 
 
 
 
24
 
25
  # Get configuration
26
  config = get_config()
 
19
 
20
  class EndpointHandler:
21
  def __init__(self, model_dir=None):
22
+ # Initialize FaceAnalysis with GPU support
23
+ self.app = FaceAnalysis(root="/tmp/.insightface", providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
24
+ self.app.prepare(ctx_id=0) # 0 = GPU, -1 = CPU
25
+
26
+ print("=" * 80)
27
+ print("InsightFace Providers:")
28
+ for model in self.app.models:
29
+ if hasattr(model, 'sess'):
30
+ print(f" {model.__class__.__name__}: {model.sess.get_providers()}")
31
+ print("=" * 80)
32
 
33
  # Get configuration
34
  config = get_config()