Upload Dockerfile with huggingface_hub
Browse files- Dockerfile +88 -0
Dockerfile
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime
|
| 2 |
+
|
| 3 |
+
# Set environment variables
|
| 4 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 5 |
+
ENV PYTHONUNBUFFERED=1
|
| 6 |
+
ENV HF_HOME=/app/.cache/huggingface
|
| 7 |
+
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface/transformers
|
| 8 |
+
ENV PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128
|
| 9 |
+
|
| 10 |
+
# Create necessary directories with proper permissions
|
| 11 |
+
RUN mkdir -p /app/.cache/huggingface/transformers && \
|
| 12 |
+
chmod -R 777 /app
|
| 13 |
+
|
| 14 |
+
# Install system dependencies
|
| 15 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 16 |
+
build-essential \
|
| 17 |
+
git \
|
| 18 |
+
curl \
|
| 19 |
+
ca-certificates \
|
| 20 |
+
cmake \
|
| 21 |
+
python3-pip \
|
| 22 |
+
python3-dev \
|
| 23 |
+
ninja-build \
|
| 24 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 25 |
+
|
| 26 |
+
# Create a working directory
|
| 27 |
+
WORKDIR /app
|
| 28 |
+
|
| 29 |
+
# Install core requirements
|
| 30 |
+
COPY requirements.txt .
|
| 31 |
+
RUN pip3 install --no-cache-dir --upgrade pip && \
|
| 32 |
+
pip3 install --no-cache-dir -r requirements.txt
|
| 33 |
+
|
| 34 |
+
# Install basic dependencies specifically for InternViT
|
| 35 |
+
RUN pip3 install --no-cache-dir \
|
| 36 |
+
transformers==4.37.2 \
|
| 37 |
+
timm==0.9.11 \
|
| 38 |
+
accelerate==0.30.0 \
|
| 39 |
+
safetensors==0.4.1 \
|
| 40 |
+
einops
|
| 41 |
+
|
| 42 |
+
# Install flash-attn with specific CUDA compatibility
|
| 43 |
+
# Flash Attention requires CUDA Toolkit, so we install a version that's pre-built
|
| 44 |
+
RUN pip3 install --no-cache-dir \
|
| 45 |
+
ninja \
|
| 46 |
+
packaging \
|
| 47 |
+
"flash-attn<2.0.0" --no-build-isolation
|
| 48 |
+
|
| 49 |
+
# Copy the application
|
| 50 |
+
COPY simple_internvit_test.py .
|
| 51 |
+
|
| 52 |
+
# Add GPU diagnostic script
|
| 53 |
+
RUN echo '#!/bin/bash \n\
|
| 54 |
+
echo "Starting GPU diagnostics..." \n\
|
| 55 |
+
echo "===== System Information =====" \n\
|
| 56 |
+
python3 -c "import sys; print(f\"Python version: {sys.version}\")" \n\
|
| 57 |
+
python3 -c "import torch; print(f\"PyTorch version: {torch.__version__}\")" \n\
|
| 58 |
+
echo "\n===== CUDA Information =====" \n\
|
| 59 |
+
python3 -c "import torch; print(f\"CUDA available: {torch.cuda.is_available()}\")" \n\
|
| 60 |
+
if [ $(python3 -c "import torch; print(torch.cuda.is_available())") = "True" ]; then \n\
|
| 61 |
+
python3 -c "import torch; print(f\"CUDA version: {torch.version.cuda}\")" \n\
|
| 62 |
+
python3 -c "import torch; print(f\"GPU count: {torch.cuda.device_count()}\")" \n\
|
| 63 |
+
python3 -c "import torch; for i in range(torch.cuda.device_count()): print(f\"GPU {i}: {torch.cuda.get_device_name(i)}\")" \n\
|
| 64 |
+
python3 -c "import torch; print(f\"Allocated memory: {torch.cuda.memory_allocated() / 1024 / 1024:.2f} MB\")" \n\
|
| 65 |
+
python3 -c "import torch; print(f\"Reserved memory: {torch.cuda.memory_reserved() / 1024 / 1024:.2f} MB\")" \n\
|
| 66 |
+
fi \n\
|
| 67 |
+
echo "\n===== Package Information =====" \n\
|
| 68 |
+
pip3 list | grep -E "transformers|einops|torch|timm|flash|accelerate|safetensors" \n\
|
| 69 |
+
echo "\n===== Testing Simple CUDA Operation =====" \n\
|
| 70 |
+
python3 -c "import torch; a = torch.randn(1000, 1000).cuda(); b = torch.randn(1000, 1000).cuda(); t0 = torch.cuda.Event(enable_timing=True); t1 = torch.cuda.Event(enable_timing=True); t0.record(); c = torch.matmul(a, b); t1.record(); torch.cuda.synchronize(); print(f\"Matrix multiplication completed in {t0.elapsed_time(t1):.2f} ms\")" \n\
|
| 71 |
+
echo "\n===== NVIDIA System Information =====" \n\
|
| 72 |
+
if command -v nvidia-smi &> /dev/null; then \n\
|
| 73 |
+
nvidia-smi \n\
|
| 74 |
+
else \n\
|
| 75 |
+
echo "nvidia-smi not found" \n\
|
| 76 |
+
fi \n\
|
| 77 |
+
echo "\n===== Starting Application =====" \n\
|
| 78 |
+
exec "$@"' > /entrypoint.sh && \
|
| 79 |
+
chmod +x /entrypoint.sh
|
| 80 |
+
|
| 81 |
+
# Expose port 7860 for Gradio
|
| 82 |
+
EXPOSE 7860
|
| 83 |
+
|
| 84 |
+
# Use our enhanced diagnostic entrypoint script
|
| 85 |
+
ENTRYPOINT ["/entrypoint.sh"]
|
| 86 |
+
|
| 87 |
+
# Start the application
|
| 88 |
+
CMD ["python3", "simple_internvit_test.py"]
|