tezuesh commited on
Commit
28a9da3
·
verified ·
1 Parent(s): 4091af9

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +21 -103
Dockerfile CHANGED
@@ -1,119 +1,37 @@
1
- # Builder stage
2
  FROM nvidia/cuda:12.1.0-cudnn8-runtime-ubuntu22.04
3
 
4
- # Add these lines after the FROM statement
5
-
6
- # System-level configuration
7
- ENV DEBIAN_FRONTEND=noninteractive \
8
- PYTHONUNBUFFERED=1 \
9
  CUDA_HOME=/usr/local/cuda \
10
  PATH=/usr/local/cuda/bin:$PATH \
11
- LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH \
12
- TORCH_CUDA_ARCH_LIST="8.6" \
13
- PIP_NO_CACHE_DIR=1 \
14
- TORCH_NVCC_FLAGS="-Xfatbin -compress-all" \
15
- MAX_JOBS=4
16
 
17
- # Install build dependencies
18
  RUN apt-get update && apt-get install -y --no-install-recommends \
 
19
  python3-pip \
20
- && apt-get clean \
21
- && rm -rf /var/lib/apt/lists/* \
22
- && python3 -m pip install --no-cache-dir --upgrade pip
23
-
24
-
25
- # Set up Python
26
- RUN ln -sf /usr/bin/python3 /usr/bin/python && \
27
- curl -sS https://bootstrap.pypa.io/get-pip.py | python3 && \
28
- python3 -m pip install --no-cache-dir pip==23.3.1 setuptools==69.0.3 wheel==0.42.0 && \
29
- rm -rf /root/.cache/pip/*
30
-
31
- # Replace the pip install command (around line 80) with:
32
- RUN python3 -m pip install --no-cache-dir -r requirements.txt && \
33
- rm -rf /root/.cache/pip/* && \
34
- find /usr/local/lib/python3.* -name '*.pyc' -delete && \
35
- find /usr/local/lib/python3.* -name '__pycache__' -exec rm -r {} +
36
-
37
- # Runtime stage
38
- FROM nvidia/cuda:12.1.0-cudnn8-runtime-ubuntu22.04
39
 
40
- # Copy Python environment from builder
41
- COPY --from=builder /usr/local /usr/local
42
- COPY --from=builder /usr/bin/python* /usr/bin/
43
- COPY --from=builder /usr/lib/python* /usr/lib/
44
- COPY --from=builder /usr/bin/ffmpeg /usr/bin/
45
- COPY --from=builder /usr/lib/x86_64-linux-gnu/libsndfile* /usr/lib/x86_64-linux-gnu/
46
-
47
- # Runtime environment configuration
48
- ENV PYTHONUNBUFFERED=1 \
49
- CUDA_HOME=/usr/local/cuda \
50
- PATH=/usr/local/cuda/bin:$PATH \
51
- LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH \
52
- TORCH_CUDA_ARCH_LIST="8.6" \
53
- NVIDIA_VISIBLE_DEVICES=0 \
54
- NVIDIA_DRIVER_CAPABILITIES=compute,utility,video \
55
- CUDA_MODULE_LOADING=LAZY \
56
- PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:1024 \
57
- OMP_NUM_THREADS=8 \
58
- MKL_NUM_THREADS=8 \
59
- CUDA_LAUNCH_BLOCKING=0 \
60
- NCCL_P2P_DISABLE=1
61
-
62
- # Set up application directory
63
  WORKDIR /app
64
- RUN mkdir -p /app/cache /app/src && \
65
- chmod 777 /app/cache && \
66
- rm -rf /tmp/* /var/tmp/*
67
-
68
- # Install dependencies
69
- COPY requirements.txt /app/src/
70
- WORKDIR /app/src
71
- RUN pip3 install --no-cache-dir -r requirements.txt && \
72
- rm -rf /root/.cache/pip/* && \
73
- find /usr/local/lib/python3.* -name '*.pyc' -delete && \
74
- find /usr/local/lib/python3.* -name '__pycache__' -exec rm -r {} +
75
 
76
- # Copy application code
77
- COPY . /app/src/
78
 
79
- # Remove unnecessary files
80
- RUN rm -rf \
81
- /app/src/.git* \
82
- /app/src/*.pyc \
83
- /app/src/__pycache__ \
84
- /app/src/*.log \
85
- /app/src/*.tmp \
86
- /root/.cache/* \
87
- /tmp/* \
88
- /var/tmp/* \
89
- /var/cache/apt/* \
90
- /var/lib/apt/lists/* \
91
- /usr/share/doc/* \
92
- /usr/share/man/* \
93
- /usr/local/share/doc/* \
94
- /usr/local/share/man/*
95
 
96
- # Runtime environment
97
- ENV MODEL_PATH=/app/cache \
98
- PYTHONPATH=/app/src:$PYTHONPATH
99
 
100
- # GPU verification
101
- RUN python3 -c '\
102
- import torch; \
103
- import os; \
104
- assert torch.cuda.is_available(), "CUDA unavailable"; \
105
- print(f"PyTorch version: {torch.__version__}"); \
106
- print(f"CUDA version: {torch.version.cuda}"); \
107
- print(f"CUDA device count: {torch.cuda.device_count()}"); \
108
- device = torch.cuda.current_device(); \
109
- print(f"Current device: {torch.cuda.get_device_name(device)}"); \
110
- print(f"Device memory: {torch.cuda.get_device_properties(device).total_memory / 1024**3:.2f} GB"); \
111
- print(f"Architecture: {torch.cuda.get_device_capability(device)}");'
112
 
 
113
  EXPOSE 8000
114
 
115
- # Add healthcheck
116
- HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
117
- CMD curl -f http://localhost:8000/health || exit 1
118
-
119
- CMD ["python", "server.py"]
 
1
+ # Base image with CUDA support
2
  FROM nvidia/cuda:12.1.0-cudnn8-runtime-ubuntu22.04
3
 
4
+ # Set environment variables
5
+ ENV PYTHONUNBUFFERED=1 \
6
+ DEBIAN_FRONTEND=noninteractive \
 
 
7
  CUDA_HOME=/usr/local/cuda \
8
  PATH=/usr/local/cuda/bin:$PATH \
9
+ LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
 
 
 
 
10
 
11
+ # Install Python and pip
12
  RUN apt-get update && apt-get install -y --no-install-recommends \
13
+ python3 \
14
  python3-pip \
15
+ curl \
16
+ && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
+ # Set up working directory
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  WORKDIR /app
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ # Copy requirements first to leverage Docker cache
22
+ COPY requirements.txt .
23
 
24
+ # Install Python dependencies
25
+ RUN pip3 install --no-cache-dir -r requirements.txt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
+ # Copy the rest of your application
28
+ COPY . .
 
29
 
30
+ # Verify GPU setup
31
+ RUN python3 -c "import torch; assert torch.cuda.is_available(), 'CUDA not available'"
 
 
 
 
 
 
 
 
 
 
32
 
33
+ # Expose port
34
  EXPOSE 8000
35
 
36
+ # Start the application
37
+ CMD ["python3", "server.py"]