Spaces:
Running
Running
Update dockerfile 2
Browse files- Dockerfile +51 -18
Dockerfile
CHANGED
@@ -1,11 +1,10 @@
|
|
1 |
-
FROM nvidia/cuda:12.2
|
2 |
|
3 |
# Set environment variables
|
4 |
ENV DEBIAN_FRONTEND=noninteractive
|
5 |
ENV PYTHONUNBUFFERED=1
|
6 |
ENV PYTHONDONTWRITEBYTECODE=1
|
7 |
ENV TF_FORCE_GPU_ALLOW_GROWTH=true
|
8 |
-
ENV XLA_FLAGS="--xla_gpu_enable_fast_min_max"
|
9 |
|
10 |
# Install system dependencies
|
11 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
@@ -26,38 +25,72 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
26 |
# Set working directory
|
27 |
WORKDIR /app
|
28 |
|
29 |
-
# Copy requirements
|
30 |
COPY requirements.txt /app/
|
|
|
31 |
RUN sed -i 's/tensorflow==2.18.0/tensorflow==2.15.0/' /app/requirements.txt
|
32 |
|
33 |
# Install Python dependencies
|
34 |
RUN pip3 install --no-cache-dir --upgrade pip setuptools wheel
|
35 |
RUN pip3 install --no-cache-dir -r requirements.txt
|
36 |
|
37 |
-
# Install compatible OpenCV
|
38 |
-
RUN pip3 install --no-cache-dir opencv-python-headless
|
39 |
|
40 |
# Copy application code
|
41 |
COPY . /app/
|
42 |
|
43 |
-
#
|
44 |
-
RUN
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
-
#
|
48 |
-
RUN
|
|
|
|
|
|
|
|
|
49 |
sed -i '/result = self._model/i\ # Try with GPU' /app/FILM.py && \
|
50 |
-
sed -i '/result = self._model/a\ except Exception as e:\n print("GPU inference failed, falling back to CPU")\n # Force CPU execution\n with tf.device("/cpu:0"):\n result = self._model(inputs, training=False)' /app/FILM.py
|
|
|
51 |
|
52 |
-
# Set environment variables for
|
53 |
-
ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}
|
54 |
ENV PATH=/usr/local/cuda/bin:${PATH}
|
55 |
-
|
56 |
-
# Force TensorFlow to use compatible cuDNN version
|
57 |
-
ENV TF_CUDNN_VERSION=8
|
58 |
|
59 |
# Expose port for Streamlit
|
60 |
EXPOSE 8501
|
61 |
|
62 |
-
#
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM docker.io/nvidia/cuda:12.3.2-cudnn9-devel-ubuntu22.04
|
2 |
|
3 |
# Set environment variables
|
4 |
ENV DEBIAN_FRONTEND=noninteractive
|
5 |
ENV PYTHONUNBUFFERED=1
|
6 |
ENV PYTHONDONTWRITEBYTECODE=1
|
7 |
ENV TF_FORCE_GPU_ALLOW_GROWTH=true
|
|
|
8 |
|
9 |
# Install system dependencies
|
10 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
25 |
# Set working directory
|
26 |
WORKDIR /app
|
27 |
|
28 |
+
# Copy requirements but modify TensorFlow version
|
29 |
COPY requirements.txt /app/
|
30 |
+
# Use TensorFlow 2.15.0 which has better compatibility with newer CUDA versions
|
31 |
RUN sed -i 's/tensorflow==2.18.0/tensorflow==2.15.0/' /app/requirements.txt
|
32 |
|
33 |
# Install Python dependencies
|
34 |
RUN pip3 install --no-cache-dir --upgrade pip setuptools wheel
|
35 |
RUN pip3 install --no-cache-dir -r requirements.txt
|
36 |
|
37 |
+
# Install compatible OpenCV
|
38 |
+
RUN pip3 install --no-cache-dir opencv-python-headless opencv-contrib-python-headless
|
39 |
|
40 |
# Copy application code
|
41 |
COPY . /app/
|
42 |
|
43 |
+
# Create a more robust CPU fallback implementation
|
44 |
+
RUN echo 'import tensorflow as tf\n\
|
45 |
+
import os\n\
|
46 |
+
import sys\n\
|
47 |
+
\n\
|
48 |
+
# Set TensorFlow logging level\n\
|
49 |
+
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"\n\
|
50 |
+
\n\
|
51 |
+
# Function to modify FILM.py for CPU fallback\n\
|
52 |
+
def ensure_cpu_fallback():\n\
|
53 |
+
# Check if we have a GPU available and supported\n\
|
54 |
+
try:\n\
|
55 |
+
gpus = tf.config.list_physical_devices("GPU")\n\
|
56 |
+
if len(gpus) > 0:\n\
|
57 |
+
for gpu in gpus:\n\
|
58 |
+
tf.config.experimental.set_memory_growth(gpu, True)\n\
|
59 |
+
print(f"Available GPUs: {len(gpus)}")\n\
|
60 |
+
else:\n\
|
61 |
+
print("No GPUs found, will run on CPU only")\n\
|
62 |
+
except Exception as e:\n\
|
63 |
+
print(f"Error setting up GPU: {e}")\n\
|
64 |
+
\n\
|
65 |
+
# Call the function\n\
|
66 |
+
ensure_cpu_fallback()\n\
|
67 |
+
' > /app/tf_setup.py
|
68 |
|
69 |
+
# Modify FILM.py to use CPU if GPU fails
|
70 |
+
RUN if [ -f "/app/FILM.py" ]; then \
|
71 |
+
# Import our setup at the top of the file\
|
72 |
+
sed -i '1s/^/import sys\nimport os\nimport tensorflow as tf\nfrom tf_setup import *\n/' /app/FILM.py && \
|
73 |
+
# Add try-except around model call\
|
74 |
+
sed -i '/def __call__/a\ try:' /app/FILM.py && \
|
75 |
sed -i '/result = self._model/i\ # Try with GPU' /app/FILM.py && \
|
76 |
+
sed -i '/result = self._model/a\ except Exception as e:\n print(f"GPU inference failed: {e}, falling back to CPU")\n # Force CPU execution\n with tf.device("/cpu:0"):\n result = self._model(inputs, training=False)' /app/FILM.py; \
|
77 |
+
fi
|
78 |
|
79 |
+
# Set environment variables for GPU compatibility
|
80 |
+
ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}
|
81 |
ENV PATH=/usr/local/cuda/bin:${PATH}
|
82 |
+
ENV TF_FORCE_GPU_ALLOW_GROWTH=true
|
|
|
|
|
83 |
|
84 |
# Expose port for Streamlit
|
85 |
EXPOSE 8501
|
86 |
|
87 |
+
# Create a startup script that ensures proper execution
|
88 |
+
RUN echo '#!/bin/bash\n\
|
89 |
+
# Ensure library paths are set correctly\n\
|
90 |
+
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH\n\
|
91 |
+
# Run the app\n\
|
92 |
+
exec streamlit run app.py --server.port=8501 --server.address=0.0.0.0\n\
|
93 |
+
' > /app/start.sh && chmod +x /app/start.sh
|
94 |
+
|
95 |
+
# Use the startup script
|
96 |
+
CMD ["/app/start.sh"]
|