File size: 3,528 Bytes
1386b2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-devel

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV HF_HOME=/app/.cache/huggingface
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface/transformers
ENV PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128

# Create necessary directories with proper permissions
RUN mkdir -p /app/.cache/huggingface/transformers && \
    chmod -R 777 /app

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    git \
    curl \
    ca-certificates \
    cmake \
    python3-pip \
    python3-dev \
    ninja-build \
    && rm -rf /var/lib/apt/lists/*

# Create a working directory
WORKDIR /app

# Install core requirements
COPY requirements.txt .
RUN pip3 install --no-cache-dir --upgrade pip && \
    pip3 install --no-cache-dir -r requirements.txt

# Install basic dependencies specifically for InternViT
RUN pip3 install --no-cache-dir \
    transformers==4.37.2 \
    timm==0.9.11 \
    accelerate==0.30.0 \
    safetensors==0.4.1 \
    einops

# Install flash-attn with build tools provided by devel image
RUN pip3 install --no-cache-dir \
    ninja \
    packaging \
    "flash-attn==1.0.9"

# Copy the application
COPY simple_internvit_test.py .

# Add GPU diagnostic script
RUN echo '#!/bin/bash \n\
echo "Starting GPU diagnostics..." \n\
echo "===== System Information =====" \n\
python3 -c "import sys; print(f\"Python version: {sys.version}\")" \n\
python3 -c "import torch; print(f\"PyTorch version: {torch.__version__}\")" \n\
echo "\n===== CUDA Information =====" \n\
python3 -c "import torch; print(f\"CUDA available: {torch.cuda.is_available()}\")" \n\
if [ $(python3 -c "import torch; print(torch.cuda.is_available())") = "True" ]; then \n\
    echo "CUDA/NVCC version:" \n\
    nvcc --version \n\
    python3 -c "import torch; print(f\"CUDA version: {torch.version.cuda}\")" \n\
    python3 -c "import torch; print(f\"GPU count: {torch.cuda.device_count()}\")" \n\
    python3 -c "import torch; for i in range(torch.cuda.device_count()): print(f\"GPU {i}: {torch.cuda.get_device_name(i)}\")" \n\
    python3 -c "import torch; print(f\"Allocated memory: {torch.cuda.memory_allocated() / 1024 / 1024:.2f} MB\")" \n\
    python3 -c "import torch; print(f\"Reserved memory: {torch.cuda.memory_reserved() / 1024 / 1024:.2f} MB\")" \n\
fi \n\
echo "\n===== Package Information =====" \n\
pip3 list | grep -E "transformers|einops|torch|timm|flash|accelerate|safetensors" \n\
echo "\n===== Testing Simple CUDA Operation =====" \n\
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\
echo "\n===== Testing Flash Attention Import =====" \n\
python3 -c "import flash_attn; print(f\"Flash Attention version: {flash_attn.__version__}\")" \n\
echo "\n===== NVIDIA System Information =====" \n\
if command -v nvidia-smi &> /dev/null; then \n\
    nvidia-smi \n\
else \n\
    echo "nvidia-smi not found" \n\
fi \n\
echo "\n===== Starting Application =====" \n\
exec "$@"' > /entrypoint.sh && \
chmod +x /entrypoint.sh

# Expose port 7860 for Gradio
EXPOSE 7860

# Use our enhanced diagnostic entrypoint script
ENTRYPOINT ["/entrypoint.sh"]

# Start the application
CMD ["python3", "simple_internvit_test.py"]