Upload Dockerfile with huggingface_hub
Browse files- Dockerfile +76 -0
Dockerfile
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
python3-pip \
|
21 |
+
python3-dev \
|
22 |
+
&& rm -rf /var/lib/apt/lists/*
|
23 |
+
|
24 |
+
# Create a working directory
|
25 |
+
WORKDIR /app
|
26 |
+
|
27 |
+
# Install core requirements
|
28 |
+
COPY requirements.txt .
|
29 |
+
RUN pip3 install --no-cache-dir --upgrade pip && \
|
30 |
+
pip3 install --no-cache-dir -r requirements.txt
|
31 |
+
|
32 |
+
# Install basic dependencies specifically for InternViT
|
33 |
+
RUN pip3 install --no-cache-dir \
|
34 |
+
transformers==4.37.2 \
|
35 |
+
timm==0.9.11 \
|
36 |
+
accelerate==0.30.0 \
|
37 |
+
safetensors==0.4.1 \
|
38 |
+
einops
|
39 |
+
|
40 |
+
# Create a modified test script that can work without flash-attn
|
41 |
+
RUN echo 'import torch\nimport os\nimport sys\nimport traceback\nimport gradio as gr\nfrom PIL import Image\nfrom transformers import AutoModel, CLIPImageProcessor\n\nprint("=" * 50)\nprint("INTERNVIT-6B MODEL LOADING TEST (NO FLASH-ATTN)")\nprint("=" * 50)\n\n# System information\nprint(f"Python version: {sys.version}")\nprint(f"PyTorch version: {torch.__version__}")\nprint(f"CUDA available: {torch.cuda.is_available()}")\n\nif torch.cuda.is_available():\n print(f"CUDA version: {torch.version.cuda}")\n print(f"GPU count: {torch.cuda.device_count()}")\n for i in range(torch.cuda.device_count()):\n print(f"GPU {i}: {torch.cuda.get_device_name(i)}")\n \n # Memory info\n print(f"Total GPU memory: {torch.cuda.get_device_properties(0).total_memory / 1e9:.2f} GB")\n print(f"Allocated GPU memory: {torch.cuda.memory_allocated() / 1e9:.2f} GB")\n print(f"Reserved GPU memory: {torch.cuda.memory_reserved() / 1e9:.2f} GB")\nelse:\n print("CUDA is not available. This is a critical issue for model loading.")\n\n# Create a function to load and test the model\ndef load_and_test_model():\n try:\n # Monkey patch to disable flash attention\n import sys\n import types\n \n # Create a fake flash_attn module\n flash_attn_module = types.ModuleType("flash_attn")\n flash_attn_module.__version__ = "0.0.0-disabled"\n sys.modules["flash_attn"] = flash_attn_module\n \n print("\\nNOTE: Created dummy flash_attn module to avoid dependency error")\n print("This is just for testing basic model loading - some functionality may be disabled")\n \n print("\\nLoading model with bfloat16 precision and low_cpu_mem_usage=True...")\n model = AutoModel.from_pretrained(\n "OpenGVLab/InternViT-6B-224px",\n torch_dtype=torch.bfloat16,\n low_cpu_mem_usage=True,\n trust_remote_code=True)\n \n if torch.cuda.is_available():\n print("Moving model to CUDA...")\n model = model.cuda()\n \n model.eval()\n print("✓ Model loaded successfully!")\n \n # Now try to process a test image\n print("\\nLoading image processor...")\n image_processor = CLIPImageProcessor.from_pretrained("OpenGVLab/InternViT-6B-224px")\n print("✓ Image processor loaded successfully!")\n \n # Create a simple test image\n print("\\nCreating test image...")\n test_image = Image.new("RGB", (224, 224), color="red")\n \n # Process the test image\n print("Processing test image...")\n pixel_values = image_processor(images=test_image, return_tensors="pt").pixel_values\n if torch.cuda.is_available():\n pixel_values = pixel_values.to(torch.bfloat16).cuda()\n \n # Get model parameters\n params = sum(p.numel() for p in model.parameters())\n print(f"Model parameters: {params:,}")\n \n # Forward pass\n print("Running forward pass...")\n with torch.no_grad():\n outputs = model(pixel_values)\n \n print("✓ Forward pass successful!")\n print(f"Output shape: {outputs.last_hidden_state.shape}")\n \n return f"SUCCESS: Model loaded and test passed!\\nParameters: {params:,}\\nOutput shape: {outputs.last_hidden_state.shape}"\n \n except Exception as e:\n print(f"\\n❌ ERROR: {str(e)}")\n traceback.print_exc()\n return f"FAILED: Error loading model or processing image\\nError: {str(e)}"\n\n# Create a simple Gradio interface\ndef create_interface():\n with gr.Blocks(title="InternViT-6B Test") as demo:\n gr.Markdown("# InternViT-6B Model Loading Test (without Flash Attention)")\n gr.Markdown("### This version uses a dummy flash-attn implementation to avoid compilation issues")\n \n with gr.Row():\n test_btn = gr.Button("Test Model Loading")\n output = gr.Textbox(label="Test Results", lines=10)\n \n test_btn.click(fn=load_and_test_model, inputs=[], outputs=output)\n \n return demo\n\n# Main function\nif __name__ == "__main__":\n # Print environment variables\n print("\\nEnvironment variables:")\n relevant_vars = ["CUDA_VISIBLE_DEVICES", "NVIDIA_VISIBLE_DEVICES", \n "TRANSFORMERS_CACHE", "HF_HOME", "PYTORCH_CUDA_ALLOC_CONF"]\n for var in relevant_vars:\n print(f"{var}: {os.environ.get(var, "Not set")}")\n \n # Set environment variable for better GPU memory management\n os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:128"\n \n # Create and launch the interface\n demo = create_interface()\n demo.launch(share=False, server_name="0.0.0.0")' > /app/no_flash_attn_test.py
|
42 |
+
|
43 |
+
# Add a simple script to check GPU status
|
44 |
+
RUN echo '#!/bin/bash \n\
|
45 |
+
echo "Starting diagnostics..." \n\
|
46 |
+
echo "===== System Information =====" \n\
|
47 |
+
python3 -c "import sys; print(f\"Python version: {sys.version}\")" \n\
|
48 |
+
python3 -c "import torch; print(f\"PyTorch version: {torch.__version__}\")" \n\
|
49 |
+
echo "\n===== CUDA Information =====" \n\
|
50 |
+
python3 -c "import torch; print(f\"CUDA available: {torch.cuda.is_available()}\")" \n\
|
51 |
+
if [ $(python3 -c "import torch; print(torch.cuda.is_available())") = "True" ]; then \n\
|
52 |
+
python3 -c "import torch; print(f\"CUDA version: {torch.version.cuda}\")" \n\
|
53 |
+
python3 -c "import torch; print(f\"GPU count: {torch.cuda.device_count()}\")" \n\
|
54 |
+
python3 -c "import torch; for i in range(torch.cuda.device_count()): print(f\"GPU {i}: {torch.cuda.get_device_name(i)}\")" \n\
|
55 |
+
python3 -c "import torch; print(f\"Total GPU memory: {torch.cuda.get_device_properties(0).total_memory / 1024 / 1024 / 1024:.2f} GB\")" \n\
|
56 |
+
fi \n\
|
57 |
+
echo "\n===== Package Information =====" \n\
|
58 |
+
pip3 list | grep -E "transformers|einops|torch|timm|accelerate|safetensors" \n\
|
59 |
+
echo "\n===== NVIDIA System Information =====" \n\
|
60 |
+
if command -v nvidia-smi &> /dev/null; then \n\
|
61 |
+
nvidia-smi \n\
|
62 |
+
else \n\
|
63 |
+
echo "nvidia-smi not found" \n\
|
64 |
+
fi \n\
|
65 |
+
echo "\n===== Starting Application =====" \n\
|
66 |
+
exec "$@"' > /entrypoint.sh && \
|
67 |
+
chmod +x /entrypoint.sh
|
68 |
+
|
69 |
+
# Expose port 7860 for Gradio
|
70 |
+
EXPOSE 7860
|
71 |
+
|
72 |
+
# Use our entrypoint script
|
73 |
+
ENTRYPOINT ["/entrypoint.sh"]
|
74 |
+
|
75 |
+
# Start the modified application that doesn't require flash-attn
|
76 |
+
CMD ["python3", "no_flash_attn_test.py"]
|