|
FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime |
|
|
|
|
|
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 |
|
|
|
|
|
RUN mkdir -p /app/.cache/huggingface/transformers && \ |
|
chmod -R 777 /app |
|
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \ |
|
build-essential \ |
|
git \ |
|
curl \ |
|
ca-certificates \ |
|
python3-pip \ |
|
python3-dev \ |
|
&& rm -rf /var/lib/apt/lists/* |
|
|
|
|
|
WORKDIR /app |
|
|
|
|
|
COPY requirements.txt . |
|
RUN pip3 install --no-cache-dir --upgrade pip && \ |
|
pip3 install --no-cache-dir -r requirements.txt |
|
|
|
|
|
RUN pip3 install --no-cache-dir \ |
|
transformers==4.37.2 \ |
|
timm==0.9.11 \ |
|
accelerate==0.30.0 \ |
|
safetensors==0.4.1 \ |
|
einops |
|
|
|
|
|
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(" |
|
|
|
|
|
RUN echo ' |
|
echo "Starting 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\ |
|
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\"Total GPU memory: {torch.cuda.get_device_properties(0).total_memory / 1024 / 1024 / 1024:.2f} GB\")" \n\ |
|
fi \n\ |
|
echo "\n===== Package Information =====" \n\ |
|
pip3 list | grep -E "transformers|einops|torch|timm|accelerate|safetensors" \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 7860 |
|
|
|
|
|
ENTRYPOINT ["/entrypoint.sh"] |
|
|
|
|
|
CMD ["python3", "no_flash_attn_test.py"] |